notekit icon indicating copy to clipboard operation
notekit copied to clipboard

Update when underlying files change

Open eddsalkield opened this issue 3 years ago • 4 comments

If notekit were to monitor its note files for modifications, then the note rendered in the UI could be updated in real time and kept in sync when the underlying file changes. This would allow for better note synchronisation across multiple devices and text editors.

On Linux, this could be implemented fairly easily using the inotify kernel API, which provides a file that blocks on a read until a modification is made, making this implementable without polling.

eddsalkield avatar Sep 03 '21 11:09 eddsalkield

I can look into it. What do you think it should do if there are conflicting changes inside the buffer and on disk? Should it prefer the program's view or the updated version of the file?

blackhole89 avatar Sep 10 '21 05:09 blackhole89

When this situation occurs for the first time, we could draw a banner to give the user three choices:

  • Use the current buffer
  • Use the new file contents
  • [Advanced] Perform a three-way merge

There could be a "remember my choice" checkbox, and equivalent settings in the config file and menu.

For low latency situations, the three-way merge would certainly give the best results, even allowing multiple concurrent users to make use of the application on different devices, depending on how often the buffer gets flushed. However, it would also take the most effort to implement, requiring notekit to keep track of the previous file state for the merging process.

Something that might be useful here is that I've been developing a header-only inotify library in modern C++, since I wasn't able to find any other libraries that provided a nice RAII interface. I'm hoping to get it in a workable state over the weekend, so I'll write up some documentation if it would be potentially of use to you.

eddsalkield avatar Sep 11 '21 01:09 eddsalkield

How's that C++ library coming along?

A three-way merge in general requires access to the latest common ancestor of the two documents, which in a syncing setting would require knowing the past state of the local document that the remote one diverged at. If you have a use case for that, I would actually recommend just putting your notes in a git repository. Now, there might be an interesting idea there along the lines of tightly integrating a notekeeping program with git...

blackhole89 avatar Dec 18 '22 17:12 blackhole89

I did get the library which I called ynotify into a workable state, but I haven't done any documentation; I built it initially for a different project which I've rewritten in a different language. I hope the code's clear enough as is to start with though.

You can find the repo here and the main header here.

Git integration seems cool, but it wouldn't solve the problem where you have the file opened in two editors. I think at least the user could be given a banner telling them that the file got updated.

eddsalkield avatar Jan 04 '23 16:01 eddsalkield