deckmaster icon indicating copy to clipboard operation
deckmaster copied to clipboard

Add support for automatic reloading the config when it has been changed (based on #50)

Open marcusramberg opened this issue 3 years ago • 2 comments

Automatic reloading is very useful, and I've been using it locally, but #50 seems to be abandoned, so I forked it and tried to address the remaining review comments.

marcusramberg avatar Feb 07 '22 08:02 marcusramberg

A general note: file watching is difficult and I fear there's a bit more work required to make this work universally. Depending on the editor you use to edit a .deck file, the file watcher can actually break deckmaster. The reason for that is that some editors don't just overwrite a file, they actually remove the old file and then rename a temporary file to match the name of the edited file. In this case we'll receive an fsnotify event, but loading the deck again will fail as the file has vanished.

Solving this is tricky: you'll have to watch the entire directory the .deck file resides in to monitor things like deletions, file creations and move operations.

muesli avatar Feb 08 '22 02:02 muesli

A general note: file watching is difficult and I fear there's a bit more work required to make this work universally. Depending on the editor you use to edit a .deck file, the file watcher can actually break deckmaster. The reason for that is that some editors don't just overwrite a file, they actually remove the old file and then rename a temporary file to match the name of the edited file. In this case we'll receive an fsnotify event, but loading the deck again will fail as the file has vanished.

Solving this is tricky: you'll have to watch the entire directory the .deck file resides in to monitor things like deletions, file creations and move operations.

I'm not sure which editors this would be a problem for, only been testing on nvim and it seems to work very consistently. Did a test autoincrementing a number 250 times (mostly to check that we're not leaking on reload), and seemed to reload consistently every time. An idea to address this issue could be adding a small delay (50-100ms?) (incremented every new event) before saving?

marcusramberg avatar Feb 08 '22 20:02 marcusramberg

I guess there's no interest in progressing this PR so I will just close it.

marcusramberg avatar Dec 23 '22 11:12 marcusramberg

Yeah, to be honest I'm not sure it's worth properly solving this. It would require a bunch of nasty code with tons of (platform and filesystem specific) edge-cases. Thanks for looking into it, tho!

muesli avatar Dec 23 '22 11:12 muesli