Help needed: how does TW5 boot up its plugins?

I need some help understanding how exactly TiddlyWiki initiates plugin tiddlers other than the $:/core plugin. Where exactly does this happen: in the startup mechanism, or the boot mechanism prior to startup? How can I programmatically startup some plugin tiddlers that I have stored in the browser’s indexeddb?

I’ve been reading TW’s source code all weekend trying to figure it out, but I feel terribly lost. From what I can tell, you have to run code within the method $tw.boot.startup(), but any word of advice from the core developers will be nice. I’ve also tried doing something akin to what browserstorage plugin does with the wikified raw markup, but I haven’t had much success so far.

I don’t know, how your code looks like, so I only can guess.

Have a closer look at the dev wiki: https://tiddlywiki.com/dev/#StartupMechanism

It depends. Every TW plugin / module / library has a module-type field. If you search the whole source globally for module-type you’ll find the code, that directly deals with that field in boot.js

And you’ll see, which types actually exit. … plugins can only be “executed” after they have been loaded from the store.

Depending on the module-type they are started differently as shown in the first link.

There has been a hangout video in 2013, where Jeremy talks about the startup procedure. https://web.archive.org/web/20161205105740/http://hangouts.tiddlyspace.com/#HangOut_010

There is the video-link, which may help you. …

I personally would have a closer look, how the tw browser-storage plugin does it.
TiddlyWiki5/startup.js at 681f22b66d1e37c1f4bbaf900ed41b3036e8ae81 · Jermolene/TiddlyWiki5 · GitHub because it seems to be a similar mechanism.

hope that helps.

1 Like

@pmario thanks for all those useful links. Here’s sample code to show you what I am trying to accomplish. The code from the demo I shared recently naively adds plugin tiddlers, but it seems they don’t get a chance to be started up by TiddlyWiki.

https://abesamma.github.io/oneplaybook-syncadaptor-demo/#%24%3A%2Fplugins%2Foneplaybooklab%2Foneplaybook-tw5-plugin%2FOneplaybookSyncSetup.js

I tried this to no avail and I am not sure why. Maybe I am missing something. I anticipate more digging through source code.

As @pmario points out, the best way to achieve this is to run some JS in a raw markup tiddler that runs before the boot kernel, and simply push the tiddlers you want to create onto the array $tw.preloadTiddlers, creating those variables if needed. The browser-storage plugin demonstrates the technique.

1 Like

I think that’s what I was missing @jeremyruston! Thank you so much. I was burning the midnight oil trying to figure this out. I may have been too exhausted to understand this. I will try this out and let you know. I understood that running some raw markup tiddler prior to the kernel was my best shot, so I couldn’t understand why it wasn’t working.

Uups sorry. I should have pointed my link 1 level higher. … Make sure, that you reload the browser tab when you change something in the raw markup tiddler. They need a browser refresh

@jeremyruston, I’ve had a stab at this but no cigar so far :disappointed:. Apparently by the time I’ve pushed tidders into this array, bootjs has already proceeded with booting up the wiki. Typing $tw.preloadTiddlers in the browser console shows a still filled array that hasn’t been processed by bootjs. Maybe I’m missing something else? I’ve only had success with $tw.boot.preloadDirty, but because it marks these plugin tiddlers as dirty and ask for a reload, that’s a no no for me. Any suggestions?

I’m on mobile at moment, but if you have time have a look at the source of Xememex — A place for thinking to see a working example.

1 Like

Grateful for all the kind help sir. I’ll check it out and let you know.

Hi Abesamma,
according to here access to indexeddb is asynchronous, so I do not think loading tiddlers from indexeddb before the boot will work - I think it is possible to unpack plugins later in the boot process provided there is no javascript

cheers

BJ

I think the key is to suppress the tiddlywiki boot process by setting $tw.boot.suppressBoot to true, and then once you have loaded your data, boot tiddlywiki by calling $tw.boot.boot()

2 Likes

Yes, I came to post what @saqimtiaz has above. You have to set $tw.boot.suppressBoot = true in the javascript raw markup tiddler (as this is in the DOM-header it is proccessed first, and “pauses” booting TW when the page javascript including the boot kernel is loaded lower down in the DOM-body), and then put the $tw.boot.boot() call into the callback function triggered when the indexeddb has loaded its data.

2 Likes

Yes, that is part of the problem unfortunately. So, as I’ve gleaned from Xememex’s code and as others have pointed out, the key would be to suppress the bootup process.

TBH, I am embarrassed to say that I had never noticed that $tw.boot.suppressBoot was a thing. I am glad it exists. :relieved:

@saqimtiaz you’re my savior. :fire:

2 Likes

Writing to say that my problem has been solved. I think we should document this somewhere because it was quite a task figuring it out otherwise. Thank you all for your help.

1 Like

I’d welcome that. https://tiddlywiki.com/dev is a good place for a “How to use TiddlyWiki with a boot loader” tiddler.

1 Like