Action on return to TiddlyWiki

In a issue I recently raised [IDEA] Last saved timestamp and what it may enable #6684 an incidental idea came to me, if there a method by which we could detect a users return to a tab or window in which a tiddlywiki is loaded? Ie the tiddlywiki gets focus.

I do not have the developer knowledge to know how to determine if this is possible for any application/website, let alone TiddlyWiki.

The idea would be to trigger a custom action when a tiddlywiki receives focus.

  • This would then allow the time now to be compared with last loaded and last saved (proposed) timestamps and trigger different responses. See #6684
  • This would complement existing start-up actions and timestamps.

It is possible to trigger an action after a timeout in a tab, but I am not sure if they will take place of the tab does not have the focus.

For background “scripts” of tabs most browsers now disable them completely, because of performance of visible tabs and battery saving mechanisms on mobile devices.

If a web app should do something in the background it needs to install web workers but they are also throttled if the tab is in the background. …

If a tab gets focus, we do have better luck. See: windows.onFocusChanged - Mozilla | MDN

@pmario thanks for that. It should be sufficient if we can trigger when focus returns to tiddlywiki even if has to subsequently refresh a time before triggering further actions.

How can we get such an action made. Shall I raise an issue?

One of the first functions that I did implement into my file-backups AddOn was the detection of other tabs with the same wiki.

I think we should check if it is possible to implement that function into TW itself. … If possible,the downside is, that we will need to implement it in a way, so a browser AddOn can detect, if that function is available. The addOn has to be “silent” if the function is part of the wiki.

I’m not sure, if there is an issue for that function at GitHub already. … But there is a high chance.

Yes, but be as short and specific as possible.

1 Like

I must revisit this as it is using some interesting mechanisiums but since I have Timimi in all my browsers I have not used it.

In relation to other tabs in the same wiki I have found that if a wiki is opened with a target in the href then of course every time we use that link it opens in the same tab/window. This reduces the possibility of contention between tabs containing the same single file wiki. I am yet to find an easy way for users and to facilitate this transparently.

In relation to the OT I suppose what we need is a trigger on a wiki when it recieves focus to trigger some custom actions. It would be the responcibility of the designer to ensure it was reusable and had minimal if any ui effects. This refocusing could occur very often such as after other activity on the host.

So an example use of such a trigger would be to test if the current wiki was last saved or loaded more than a day ago and reload if no changes pending or prompt if changes are pending.

Further it could help check and refresh any check out status.