tiddlyhost / tiddlyhost-com

Rails application for creating and hosting TiddlyWiki sites, plus resources for deploying it to https://tiddlyhost.com/
Other
184 stars 17 forks source link

Consider solutions to avoid losing data when using tiddlyhost on multiple devices #219

Open simonbaird opened 2 years ago

simonbaird commented 2 years ago

Or even multiple tabs.

E.g. https://www.reddit.com/r/TiddlyWiki5/comments/tia329/tiddlyhost_from_multiple_devices/

Ideas:

fmatosqg commented 2 years ago

I think those make sense, but I'd also like to align then with my main use cases

I'd say there's enough value on a simple implementation of detecting changes + alert + manual refresh that it could be it's own pr / issue. Potentially rolling the lock and merges as separate issues. I'd love the merge idea btw, I've been using monkey GTD and I guess most of my cases will probably involve writing in laptop and reading/marking done on phone.

saqimtiaz commented 2 years ago

I have the following work on WebDAV:

If I can find the time I might try to extract this into a more generic plugin, currently it relies on WebDAV for things like the modification date.

simonbaird commented 2 years ago

What code is doing the "check every minute"? Something built into TW already, or some custom code?

simonbaird commented 2 years ago

Here's some WIP that might improve the current situation:

It does depend on switching from the upload saver to the put saver.

@saqimtiaz What do you think about that TW PR?

saqimtiaz commented 2 years ago

What code is doing the "check every minute"? Something built into TW already, or some custom code?

Custom code. TW has a concept of syncers for which you can write adaptors - this is what the node.js version of TW uses. I had some code laying around from something else that did what I needed though so I never explored writing an adaptor for the syncer.

simonbaird commented 2 years ago

220 is deployed now to prod. Here's how you can try the new behavior:

simonbaird commented 2 years ago

It's still not a great experience, but perhaps better than overwriting some important changes by accident.

For a next step, I'd like to investigate checking for new updates every minute or so, and either notifying the user and suggesting they hit reload, or syncing the updates automatically if it's possible.

simonbaird commented 2 years ago

Once TW 5.2.3 is released, we might consider enabling the put saver for all 5.2.3 or newer sites by default.

fmatosqg commented 2 years ago

Checked, a few quirks but they're welcome so it makes me double sure nothing is lost. I think they're coming because I always tick the "autosave", and ticking it triggers a save even though I guess nothing is saved, but still assuming it will generate a new ETAG. I can't reliably reproduce this, but I feel it's related to opening the tab for 1st time, but won't happen after reload.

Worked nice on both (2 tabs on laptop) and (2 tabs on laptop + 1 on phone).

image

AnthonyMuscio commented 2 years ago

I have only come to this Issue today.

But I have a working proof on concept, but It will take time to finesse for publishing;

The above could be enhanced by including the username in the browser/device/username cookies (optional password Obscured but stored cookie and/or in wiki) but of course by definition most users will be using a different browser/device.

I would like to set a timeout on inactivity that automatically checked the wiki back in and released it. However with a single user, its easy to release from one device when finished. Or say when moving from mobile to desktop or return you most likely have both available.

One advantage of tiddlyhost wikis is they exist at a url and unlike file wikis the cookies can be made unique to that url.

Move to local storage

pmario commented 2 years ago

I think there is no need for the server to be involved. There is the https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API which allows us to create a message that is broadcasted, whenever a new tab, window or even an iframe is opened from the same orgin.

If a tab is opened with an eg: ID=wiki-1 it broadcasts this info. .. Every other tab which is already open and contains a wiki did already create a "broadcast listener". If it gets an info that a new tab is opened with it's own ID it, sends a message back, that this wiki ID is already open. -- The newly created window / tab can now display a message, that this wiki is already open.

I'm using a very similar mechanism with my file-backups plugin. Since it's a browser addON the mechanism is slightly different, but the principle is the same. It works very well for me.

This mechanism works with the same browser only. So if 2 different device are involved, that's not possible.

simonbaird commented 2 years ago

The solution I'm imagining involves changes to TiddlyWiki to do the following:

I think the amount of code needed would be small, since TiddlyWiki already has functions to do the OPTIONS request and store the etag. So it's probably a small-ish patch to compare old and new values and trigger the alert.

It should work across different devices, e.g. phone vs laptop, and it feels a lot simpler than inventing some kind of write permission lock workflow.

simonbaird commented 2 years ago

Re "is there a way to upstream it to an existing tiddly", if you enable put saver (in the Tiddlyhost settings for your site) it should work, but you won't get the longer explanation text when the save is refused unless your TiddlyWiki is a 5.2.3-prerelease.

Actually in 5.2.2 it says:

Error while saving

File changed on server

Versus this on the 5.2.3 and higher:

Error while saving

File changed on server

The site has been updated since you first loaded it. Saving now would cause those                                                                                                 
updates to be overwritten.

Try reloading and then reapplying your changes.
simonbaird commented 1 year ago

FYI the put saver mentioned above is now used by default for new sites.

I think this issue is a little stale now. Todo: Extract out the viable sugestions from above and file them as separate issues.

pmario commented 1 year ago

I think this issue is a little stale now. Todo: Extract out the viable sugestions from above and file them as separate issues.

I think that's a good idea.

fmatosqg commented 1 year ago

I'm curious, how do I upgrade my existing site or clone it in a way that it supports this feature?

On Wed, 7 Dec 2022, 21:51 Mario Pietsch, @.***> wrote:

I think this issue is a little stale now. Todo: Extract out the viable sugestions from above and file them as separate issues.

I think that's a good idea.

— Reply to this email directly, view it on GitHub https://github.com/simonbaird/tiddlyhost/issues/219#issuecomment-1340773648, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABI4Y4OKWVUTUSR6ZRS4MCDWMBT3LANCNFSM5SNLMDMQ . You are receiving this because you commented.Message ID: @.***>

simonbaird commented 1 year ago

I'm curious, how do I upgrade my existing site or clone it in a way that it supports this feature?

See https://github.com/simonbaird/tiddlyhost/wiki/About-the-two-different-save-methods .