mirror of
https://github.com/Ascyii/projects.yazi.git
synced 2026-01-01 03:24:24 -05:00
fix: add saved event for save_last_and_quit function
This commit is contained in:
@@ -90,7 +90,9 @@ The following are the default configurations:
|
|||||||
require("projects"):setup({
|
require("projects"):setup({
|
||||||
save = {
|
save = {
|
||||||
method = "yazi", -- yazi | lua
|
method = "yazi", -- yazi | lua
|
||||||
lua_save_path = "", -- comment out to get the default value
|
yazi_load_event = "projects-load", -- event name when loading projects in `yazi` method
|
||||||
|
lua_save_path = "", -- saved file path in `lua` method, comment out or assign explicitly
|
||||||
|
-- default value:
|
||||||
-- windows: "%APPDATA%/yazi/state/projects.json"
|
-- windows: "%APPDATA%/yazi/state/projects.json"
|
||||||
-- unix: "~/.local/state/yazi/projects.json"
|
-- unix: "~/.local/state/yazi/projects.json"
|
||||||
},
|
},
|
||||||
|
|||||||
15
main.lua
15
main.lua
@@ -517,12 +517,16 @@ local SUPPORTED_KEYS = {
|
|||||||
local _load_config = ya.sync(function(state, opts)
|
local _load_config = ya.sync(function(state, opts)
|
||||||
state.save = {
|
state.save = {
|
||||||
method = "yazi",
|
method = "yazi",
|
||||||
|
yazi_load_event = "projects-load",
|
||||||
lua_save_path = "",
|
lua_save_path = "",
|
||||||
}
|
}
|
||||||
if type(opts.save) == "table" then
|
if type(opts.save) == "table" then
|
||||||
if type(opts.save.method) == "string" then
|
if type(opts.save.method) == "string" then
|
||||||
state.save.method = opts.save.method
|
state.save.method = opts.save.method
|
||||||
end
|
end
|
||||||
|
if type(opts.save.yazi_load_event) == "string" then
|
||||||
|
state.save.yazi_load_event = opts.save.yazi_load_event
|
||||||
|
end
|
||||||
if type(opts.save.lua_save_path) == "string" then
|
if type(opts.save.lua_save_path) == "string" then
|
||||||
state.save.lua_save_path = opts.save.lua_save_path
|
state.save.lua_save_path = opts.save.lua_save_path
|
||||||
else
|
else
|
||||||
@@ -718,7 +722,7 @@ local _save_projects = ya.sync(function(state, projects)
|
|||||||
state.projects = projects
|
state.projects = projects
|
||||||
|
|
||||||
if state.save.method == "yazi" then
|
if state.save.method == "yazi" then
|
||||||
ps.pub_to(0, "@projects", projects)
|
ps.pub_to(0, state.save.yazi_load_event, projects)
|
||||||
elseif state.save.method == "lua" then
|
elseif state.save.method == "lua" then
|
||||||
local f = io.open(state.save.lua_save_path, "w")
|
local f = io.open(state.save.lua_save_path, "w")
|
||||||
if not f then
|
if not f then
|
||||||
@@ -804,7 +808,7 @@ end)
|
|||||||
|
|
||||||
local _load_projects = ya.sync(function(state)
|
local _load_projects = ya.sync(function(state)
|
||||||
if state.save.method == "yazi" then
|
if state.save.method == "yazi" then
|
||||||
ps.sub_remote("@projects", function(body)
|
ps.sub_remote(state.save.yazi_load_event, function(body)
|
||||||
state.projects = body
|
state.projects = body
|
||||||
end)
|
end)
|
||||||
elseif state.save.method == "lua" then
|
elseif state.save.method == "lua" then
|
||||||
@@ -861,10 +865,15 @@ end)
|
|||||||
|
|
||||||
local save_last_and_quit = ya.sync(function(state)
|
local save_last_and_quit = ya.sync(function(state)
|
||||||
local projects = _get_projects()
|
local projects = _get_projects()
|
||||||
projects.last = _get_current_project()
|
local current_project = _get_current_project()
|
||||||
|
projects.last = current_project
|
||||||
|
|
||||||
_save_projects(projects)
|
_save_projects(projects)
|
||||||
|
|
||||||
|
if state.event.save.enable then
|
||||||
|
ps.pub_to(0, state.event.save.name, current_project)
|
||||||
|
end
|
||||||
|
|
||||||
ya.emit("quit", {})
|
ya.emit("quit", {})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user