Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load last project on start? #2

Closed
Praful opened this issue Nov 18, 2024 · 9 comments
Closed

Load last project on start? #2

Praful opened this issue Nov 18, 2024 · 9 comments

Comments

@Praful
Copy link

Praful commented Nov 18, 2024

Thank you for providing this excellent plugin. I like that the current state can be saved on quit. How can I have this last project automatically restored when yazi starts?

I know I can type P,P but wanted it to be done automatically since I always do that.

@MasouShizuka
Copy link
Owner

Could you try the new config load_after_start?

@Praful
Copy link
Author

Praful commented Nov 19, 2024

@MasouShizuka ありがとう (I'm learning Japanese but it's very basic!)

I've updated the plugin (with ya pack -u) and can see the new code but this is not working. When I start yazi, the last project is not restored. PP still restores correctly.

I'm using the latest Linux Mint. Is there some debugging I can do?

My init.lua code for projects.yazi:

require("projects"):setup({
    save = {
        method = "yazi", -- yazi | lua
        lua_save_path = "", -- windows: "%APPDATA%/yazi/state/projects.json", unix: "~/.config/yazi/state/projects.json"
    },
    last = {
        update_after_save = true,
        update_after_load = true,
        load_after_start = true,
    },
    merge = {
        quit_after_merge = false,
    },
    notify = {
        enable = true,
        title = "Projects",
        timeout = 2,
        level = "info",
    },
})

@MasouShizuka
Copy link
Owner

I tested it and may have found the problem.

There is a certain delay when the yazi API reads the .dds content (i.e. the saved projects) at startup.
You can try to execute load_last immediately after startup, but the recovery fails because it has not been read successfully.
After a certain period of time, executing load_last will succeed because the reading has been completed.

Since the current implementation tries to read and restore immediately after loading the plugin, it does not succeed.
And I currently have no way of knowing when yazi will finish reading .dds, so I can't complete the automatic loading in a delayed manner.

You can try again with the lua save method.

@Praful
Copy link
Author

Praful commented Nov 20, 2024

I changed to the following:

require("projects"):setup({
    save = {
        method = "lua", -- yazi | lua

But this doesn't save or restore the project!

This is hacky, but what about adding a short delay, say, 1 sec? I say this because the yazi UI is ready within a second and I immediately press PPand the project is restored.

@MasouShizuka
Copy link
Owner

After you switch to lua method, could you find projects.json, by default it should be in ~/.local/state/yazi/projects.json (after update).

@MasouShizuka
Copy link
Owner

By the way, please do not leave lua_save_path empty, either specify the path of projects.json, or comment it out to use the default path.

@MasouShizuka
Copy link
Owner

This is hacky, but what about adding a short delay, say, 1 sec? I say this because the yazi UI is ready within a second and I immediately press PPand the project is restored.

This implementation is unreliable.
Yazi reads dds asynchronously (i.e. ps.sub_remote), which means that even if you set a 1s delay time for reading, autoload may still not be possible in the case of poor performance.

@Praful
Copy link
Author

Praful commented Nov 20, 2024

I've removed the empty lua_save_path line and switched to the lua method and all is working now: the project loads on yazi startup!

projects.json has the correct information on quit.

When I switched back to the yazi save method, nothing was loaded on startup. 'PP' loaded a different project from the one I saved when using the lua method. I assume the yazi method is saving the project elsewhere?

Thanks for providing this feature!

@MasouShizuka
Copy link
Owner

Yes, Yazi saves it in a .dds file, by default it should be ~/.local/state/yazi/.dds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants