|
6 | 6 | * Run `pnpm build:preload` to build this file.
|
7 | 7 | */
|
8 | 8 | (function useStreamChunksToWebViewWebviewSideReceiverIIFE() {
|
9 |
| - var tiddlersStoreAccumulatedContent = ''; |
10 |
| - var skinnyTiddlersStoreAccumulatedContent = ''; |
11 |
| - var wikiHTML = ''; |
12 |
| - var skinnyStoreCompleteCount = 0; |
13 |
| - var storeCompleteCount = 0; |
| 9 | + /** |
| 10 | + * Array of stringified json array. |
| 11 | + */ |
| 12 | + var tiddlersStoreContents = []; |
| 13 | + var canInjectTiddlers = false; |
14 | 14 | function resetUseStreamChunksToWebViewWebviewSideReceiverIIFE() {
|
15 |
| - tiddlersStoreAccumulatedContent = ''; |
16 |
| - skinnyTiddlersStoreAccumulatedContent = ''; |
17 |
| - wikiHTML = ''; |
18 |
| - skinnyStoreCompleteCount = 0; |
19 |
| - storeCompleteCount = 0; |
| 15 | + tiddlersStoreContents = []; |
| 16 | + canInjectTiddlers = false; |
20 | 17 | }
|
21 | 18 | // @ts-ignore
|
22 | 19 | window.onStreamChunksToWebView = function (event) {
|
23 | 20 | switch (event.type) {
|
24 | 21 | case 'TIDDLYWIKI_HTML': {
|
25 |
| - wikiHTML += event.data; |
| 22 | + resetUseStreamChunksToWebViewWebviewSideReceiverIIFE(); |
| 23 | + startInjectHTML(event.data); |
26 | 24 | break;
|
27 | 25 | }
|
28 | 26 | case 'TIDDLER_STORE_SCRIPT_CHUNK': {
|
29 |
| - tiddlersStoreAccumulatedContent += event.data; |
30 |
| - break; |
31 |
| - } |
32 |
| - case 'TIDDLER_SKINNY_STORE_SCRIPT_CHUNK': { |
33 |
| - skinnyTiddlersStoreAccumulatedContent += event.data; |
34 |
| - break; |
35 |
| - } |
36 |
| - case 'TIDDLER_SKINNY_STORE_SCRIPT_CHUNK_END': { |
37 |
| - skinnyStoreCompleteCount += 1; |
| 27 | + tiddlersStoreContents.push(event.data); |
38 | 28 | break;
|
39 | 29 | }
|
40 | 30 | case 'TIDDLER_STORE_SCRIPT_CHUNK_END': {
|
41 |
| - storeCompleteCount += 1; |
| 31 | + var startInjectTiddlerIfHTMLDone_1 = function () { |
| 32 | + if (canInjectTiddlers) { |
| 33 | + executeScriptsAfterInjectHTML(); |
| 34 | + } |
| 35 | + else { |
| 36 | + setTimeout(startInjectTiddlerIfHTMLDone_1, 100); |
| 37 | + } |
| 38 | + }; |
| 39 | + startInjectTiddlerIfHTMLDone_1(); |
42 | 40 | break;
|
43 | 41 | }
|
44 | 42 | }
|
45 |
| - if (skinnyStoreCompleteCount === 1 && storeCompleteCount === 1) { |
46 |
| - // start jobs |
47 |
| - startInjectHTML(); |
48 |
| - } |
49 | 43 | };
|
50 |
| - function startInjectHTML() { |
| 44 | + function startInjectHTML(newInnerHTML) { |
51 | 45 | console.log('startInjectHTML');
|
52 | 46 | /**
|
53 | 47 | * All information needed are collected.
|
|
67 | 61 | }
|
68 | 62 | if (hasChange) {
|
69 | 63 | observer.disconnect(); // Important: disconnect the observer once done.
|
70 |
| - // use timeout to give splash screen a chance to execute and show |
71 |
| - setTimeout(executeScriptsAfterInjectHTML, 100); |
| 64 | + canInjectTiddlers = true; |
72 | 65 | }
|
73 | 66 | });
|
74 | 67 | // Start observing the body with the configured parameters
|
75 | 68 | observer.observe(document.body, { childList: true });
|
76 | 69 | // this ignores all script tags, so we need 'executeScriptsAfterInjectHTML()' later.
|
77 |
| - document.body.innerHTML = wikiHTML; |
| 70 | + document.body.innerHTML = newInnerHTML; |
78 | 71 | }
|
79 |
| - function appendStoreScript(storeJSON, name) { |
| 72 | + function appendStoreScript(storeJSONString, name) { |
80 | 73 | var tiddlersStoreScript = document.createElement('script');
|
81 | 74 | tiddlersStoreScript.type = 'application/json';
|
82 | 75 | tiddlersStoreScript.classList.add('tiddlywiki-tiddler-store', name);
|
83 |
| - tiddlersStoreScript.textContent = storeJSON; |
| 76 | + tiddlersStoreScript.textContent = storeJSONString; |
84 | 77 | var styleAreaDiv = document.querySelector('#styleArea');
|
85 | 78 | styleAreaDiv === null || styleAreaDiv === void 0 ? void 0 : styleAreaDiv.insertAdjacentElement('afterend', tiddlersStoreScript);
|
86 | 79 | }
|
|
93 | 86 | console.log('executeScriptsAfterInjectHTML');
|
94 | 87 | try {
|
95 | 88 | // load tiddlers store, place it after <div id="styleArea"> where it used to belong to.
|
96 |
| - appendStoreScript(skinnyTiddlersStoreAccumulatedContent, 'skinnyTiddlers'); |
97 |
| - appendStoreScript(tiddlersStoreAccumulatedContent, 'pluginsAndJS'); |
| 89 | + tiddlersStoreContents.forEach(function (storeJSONString, index) { |
| 90 | + appendStoreScript(storeJSONString, "tidgi-tiddlers-store-".concat(index)); |
| 91 | + }); |
98 | 92 | // load other scripts
|
99 | 93 | var scriptElements = Array.from(document.querySelectorAll('script'));
|
100 | 94 | for (var _i = 0, scriptElements_1 = scriptElements; _i < scriptElements_1.length; _i++) {
|
|
0 commit comments