vixalien / sticky

A simple sticky notes app for GNOME
https://flathub.org/apps/details/com.vixalien.sticky
MIT License
183 stars 28 forks source link

Safer backend #10

Closed sonnyp closed 1 year ago

sonnyp commented 1 year ago

Congrats on the app – it looks and feels great.

I have concerns about how the app persists data.

The app saves data on quit. This is problematic because if it crashes or if it is terminated unexpected (by user or system) - notes/changes won't be saved. My suggestion is to save changes as they happen.

The app saves all notes in a single JSON file. If something goes wrong during writing, the file will not be parsable and all notes will essentially be lost to users. My suggestion is to use one file per note.

vixalien commented 1 year ago

thanks for the suggestions. I'll implement saving in multiple files.

I'm not sure about saving on every keystroke as it may not be desirable for SSDs (limited writes), but the limitations are too high so I'll implement it anyways...

sonnyp commented 1 year ago

It doesn't have to be on every keystroke. It could be when focus is lost. Or debounced.

vixalien commented 1 year ago

how to i detect when focus is lost?

sonnyp commented 1 year ago

I would use this https://docs.gtk.org/gtk4/method.TextBuffer.set_modified.html

This is what Workbench uses in case you're looking for an example.

vixalien commented 1 year ago

oh okay!

so in short, when I save the note, I'll set the modified bit to false, then when it's changed it'll emit the modified-changed signal?

sonnyp commented 1 year ago

yes! this will save on every change but wait for the async save operation to be done before calling the next one

This is what Text Editor and Builder are doing too IIRC

sonnyp commented 1 year ago

there is also a way to make Gio use a backup file before replacing

If you assign me to a PR I can have a quick look / review if you like

vixalien commented 1 year ago

well I can definitely put up something like tomorrow. but if you want/can, you can create a PR

idoric commented 1 year ago

The app saves data on quit. This is problematic because if it crashes or if it is terminated unexpected (by user or system) - notes/changes won't be saved. My suggestion is to save changes as they happen.

Thank you for this analysis, now at least I know why I lost everything from my first day of use: I shut down my computer without manually quitting the application. Since I have a lot of applications open, the system probably terminated it.