Skip to content

Conversation

Tronix117
Copy link

@Tronix117 Tronix117 commented Apr 10, 2025

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_state option (false by default)
  • add state_ttl_secs option (None by 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

@Tronix117 Tronix117 force-pushed the master branch 2 times, most recently from 66f40ac to 27f148a Compare April 10, 2025 23:32
Add the ability 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
- add persist_state config option
- add state_ttl_secs config option to expiry a saved state after some time
- update documentation and examples
- add home-manager module support
@Tronix117
Copy link
Author

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...

@Tronix117 Tronix117 requested review from Kirottu and NotAShelf April 11, 2025 15:29
@Tronix117
Copy link
Author

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.

@Tronix117 Tronix117 marked this pull request as draft April 11, 2025 20:34
@Tronix117
Copy link
Author

Tronix117 commented Apr 11, 2025

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

@Tronix117 Tronix117 marked this pull request as ready for review April 11, 2025 21:22
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

Successfully merging this pull request may close these issues.

3 participants