anyrun
anyrun copied to clipboard
feat: add input state persistence
This feature allows to save and restore input text between sessions
- save input text to state.ron when window closes
- restore text when application launches
- clear state when match is selected in the result list
- add
persist_stateoption (falseby default) - add
state_ttl_secsoption (Noneby default), duration after which the state is considered obsolete - home-manager module support
- update documentation and examples
Use case : when configured with keybind like pkill anyrun || anyrun, results are dismissed between sessions. It's disturbing when doing calculations with data in multiple place and not directly available on the screen.
I've thoroughly testes thoses modifications without finding any bug, regression or issue.
Changes are totaly backward compatible, since a persist_state config option need to be enabled.
Feel free to give me your feedback
Thanks for your feedbacks, I'll change that !
To avoid a little delay at launch for first display of matches, I also wanted to save matches in the file (so having the save after the refresh_matches has been done), however I can't find a way to easily serialize which plugin has generated the match...
So my last changes address all your feedbacks.
I used dirs crate to find relevant state and config folder. I changed it too for the config folder since it made more sense to handle them the same (+ it resolves #208 at the same time)
I moved the runtime_data initialisation block (was in main inside the new of the RuntimeData impl, and only keeped in main dependencies for the RuntimeData. It better respects the separation of concerns and was needed to avoid poluting main with state_dir and state_file.
I managed to save only when window will close, I think it is safe with anyrun since this is the main window. When it closes the program exits, and when we gracefuly kill the program, the window close event is also called.
Finaly I used a ron file like suggested and as always updated the docs.
~wait before review~, I found that now the saving mecanism skip some saving sometime, it seems the window close event is not so reliable, i put the pr in draft. Also I saw your changes wit #215 which are incompatible with my use of dirs crate, I'll wait for your opinion before doing anything else
EDIT: I solved that in last commit using signal-hook, I think it's the cleanest and neatest way to do that