From a168b7627d912daba897bd2c9501cc18f2860ce9 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Wed, 3 Jan 2024 03:42:36 +0800 Subject: [PATCH] fix: restore to useable state --- assets/plugins/syncadaptor-ui.html | 2 +- assets/plugins/syncadaptor.html | 2 +- .../plugin.info | 3 +- .../expo-file-system-syncadaptor/plugin.info | 3 +- .../useStreamChunksToWebView/index.ts | 10 +- .../webviewSideReceiver.ts | 122 ++++++++++++++++++ 6 files changed, 131 insertions(+), 11 deletions(-) diff --git a/assets/plugins/syncadaptor-ui.html b/assets/plugins/syncadaptor-ui.html index 3b70034..4bd0a83 100644 --- a/assets/plugins/syncadaptor-ui.html +++ b/assets/plugins/syncadaptor-ui.html @@ -1 +1 @@ -{"author":"LinOnetwo","core-version":">=5.1.22","dependents":"$:/plugins/linonetwo/expo-file-system-syncadaptor","description":"UI for $:/plugins/linonetwo/expo-file-system-syncadaptor","list":"readme tree","name":"TidGi","plugin-priority":12,"plugin-priority-comment":"use 11, higher than $:/plugins/tiddlywiki/tiddlyweb's 10, so we load after it to overwrite it","plugin-type":"plugin","text":"{\"tiddlers\":{\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/readme\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/readme\",\"type\":\"text/vnd.tiddlywiki\",\"text\":\"!! UI\\n\\nTo fix [[https://github.com/Jermolene/TiddlyWiki5/issues/7553]]\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/tree\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/tree\",\"caption\":\"{{$:/language/SideBar/Explorer/Caption}}\",\"text\":\"<>\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/icon/cloud\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/icon/cloud\",\"tags\":\"$:/tags/Image\",\"text\":\"\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/readonly\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/readonly\",\"tags\":\"[[$:/tags/Stylesheet]]\",\"text\":\"\\\\define button-selector(title)\\nbutton.$title$, .tc-drop-down button.$title$, div.$title$\\n\\\\end\\n\\n\\\\define hide-edit-controls()\\n<$reveal state=\\\"$:/status/IsReadOnly\\\" type=\\\"match\\\" text=\\\"yes\\\" default=\\\"yes\\\">\\n<>`,`\\n<>`,`\\n<>`,`\\n<>`,`\\n<>`,`\\n<>`,`\\n<>`,`\\n<>`,`\\n<>`,`\\n<>`,`\\n<> `{\\n\\tdisplay: none;\\n}`\\n\\n\\\\end\\n\\n\\\\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline macrocallblock\\n\\n<>\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/save/offline\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/save/offline\",\"text\":\"\\\\import [subfilter{$:/core/config/GlobalImportFilter}]\\n\\\\define saveTiddlerFilter()\\n[is[tiddler]] -[[$:/boot/boot.css]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/linonetwo/expo-file-system-syncadaptor-ui]] -[prefix[$:/temp/]] +[sort[title]] $(publishFilter)$\\n\\\\end\\n{{$:/core/templates/tiddlywiki5.html}}\\n\"},\"$:/core/ui/Buttons/save-wiki\":{\"title\":\"$:/core/ui/Buttons/save-wiki\",\"tags\":\"$:/tags/PageControls\",\"caption\":\"{{$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/icon/cloud}} TidGi status\",\"description\":\"Status of synchronisation with TidGi\",\"text\":\"\\\\whitespace trim\\n\\\\define config-title()\\n$:/config/PageControlButtons/Visibility/$(listItem)$\\n\\\\end\\n<$button popup=<> tooltip=\\\"Status of synchronisation with server\\\" aria-label=\\\"Server status\\\" class=<> selectedClass=\\\"tc-selected\\\">\\n\\n<$list filter=\\\"[match[yes]]\\\">\\n{{$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/icon/cloud}}\\n\\n<$list filter=\\\"[match[yes]]\\\">\\n<$text text=\\\"Server status\\\"/>\\n\\n\\n\\n<$reveal state=<> type=\\\"popup\\\" position=\\\"belowleft\\\" animate=\\\"yes\\\">\\n
\\n<$list filter=\\\"[all[shadows+tiddlers]tag[$:/tags/TidgiSyncadaptorDropdown]!has[draft.of]]\\\" variable=\\\"listItem\\\">\\n<$transclude tiddler=<>/>\\n\\n
\\n\\n\"},\"$:/config/SaveWikiButton/Template\":{\"title\":\"$:/config/SaveWikiButton/Template\",\"text\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/save/offline\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/styles\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/styles\",\"tags\":\"[[$:/tags/Stylesheet]]\",\"text\":\"\\\\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline macrocallblock\\n\\nbody.tc-dirty span.tc-dirty-indicator svg {\\n\\ttransition: fill 250ms ease-in-out;\\n}\\n\\nbody .tc-image-cloud-idle {\\n\\tfill: <>;\\n\\ttransition: opacity 250ms ease-in-out;\\n\\topacity: 1;\\n\\tdisplay: unset;\\n}\\n\\nbody.tc-dirty .tc-image-cloud-idle {\\n\\topacity: 0;\\n\\tdisplay: none;\\n}\\n\\nbody .tc-image-cloud-progress {\\n\\ttransition: opacity 250ms ease-in-out;\\n\\ttransform-origin: 50% 50%;\\n\\ttransform: rotate(359deg);\\n\\tanimation: animation-rotate-slow 2s infinite linear;\\n\\tfill: <>;\\n\\tdisplay: none;\\n\\topacity: 0;\\n}\\n\\nbody.tc-dirty .tc-image-cloud-progress {\\n\\topacity: 1;\\n\\tdisplay: unset;\\n}\\n\\n@keyframes animation-rotate-slow {\\n\\tfrom {\\n\\t\\ttransform: rotate(0deg);\\n\\t}\\n\\tto {\\n\\t\\ttransform: scale(359deg);\\n\\t}\\n}\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/copy-logs\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/copy-logs\",\"tags\":\"$:/tags/TidgiSyncadaptorDropdown\",\"text\":\"<$button message=\\\"tm-copy-syncer-logs-to-clipboard\\\" class=\\\"tc-btn-invisible\\\">\\n{{$:/core/images/copy-clipboard}} Copy TidGi syncer logs to clipboard\\n\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/refresh\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/refresh\",\"tags\":\"$:/tags/TidgiSyncadaptorDropdown\",\"text\":\"<$reveal state=\\\"$:/status/IsLoggedIn\\\" type=\\\"match\\\" text=\\\"yes\\\">\\n<$button tooltip=\\\"Sync from TidGi main process\\\" aria-label=\\\"Refresh from server\\\" class=\\\"tc-btn-invisible\\\">\\n<$action-sendmessage $message=\\\"tm-server-refresh\\\"/>\\n{{$:/core/images/refresh-button}}<$text text=\\\"Sync from TidGi main process\\\"/>\\n\\n\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/save-snapshot\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/save-snapshot\",\"tags\":\"$:/tags/TidgiSyncadaptorDropdown\",\"text\":\"<$button class=\\\"tc-btn-invisible\\\">\\n<$wikify name=\\\"site-title\\\" text={{$:/config/SaveWikiButton/Filename}}>\\n<$action-sendmessage $message=\\\"tm-download-file\\\" $param={{$:/config/SaveWikiButton/Template}} filename=<>/>\\n\\n{{$:/core/images/download-button}} Save snapshot for offline use\\n\\n\"},\"$:/tags/TidgiSyncadaptorDropdown\":{\"title\":\"$:/tags/TidgiSyncadaptorDropdown\",\"list\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/refresh $:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/save-snapshot $:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/copy-logs\"}}}","title":"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui","type":"application/json","version":"0.1.0","Modern.TiddlyDev#SHA256-Hashed":"30d583a13349cad2465628fb6fe30d038a81e96c3fed01ce0a0453114beed8bb"} \ No newline at end of file +{"author":"LinOnetwo","core-version":">=5.1.22","dependents":"$:/plugins/linonetwo/expo-file-system-syncadaptor","description":"UI for $:/plugins/linonetwo/expo-file-system-syncadaptor","list":"readme tree","name":"TidGi","plugin-priority-comment":"Shouldn't add priority, otherwise content won't load.","plugin-type":"plugin","text":"{\"tiddlers\":{\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/readme\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/readme\",\"type\":\"text/vnd.tiddlywiki\",\"text\":\"!! UI\\n\\nTo fix [[https://github.com/Jermolene/TiddlyWiki5/issues/7553]]\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/tree\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/tree\",\"caption\":\"{{$:/language/SideBar/Explorer/Caption}}\",\"text\":\"<>\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/icon/cloud\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/icon/cloud\",\"tags\":\"$:/tags/Image\",\"text\":\"\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/save/offline\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/save/offline\",\"text\":\"\\\\import [subfilter{$:/core/config/GlobalImportFilter}]\\n\\\\define saveTiddlerFilter()\\n[is[tiddler]] -[[$:/boot/boot.css]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/linonetwo/expo-file-system-syncadaptor-ui]] -[prefix[$:/temp/]] +[sort[title]] $(publishFilter)$\\n\\\\end\\n{{$:/core/templates/tiddlywiki5.html}}\\n\"},\"$:/core/ui/Buttons/save-wiki\":{\"title\":\"$:/core/ui/Buttons/save-wiki\",\"tags\":\"$:/tags/PageControls\",\"caption\":\"{{$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/icon/cloud}} TidGi status\",\"description\":\"Status of synchronisation with TidGi\",\"text\":\"\\\\whitespace trim\\n\\\\define config-title()\\n$:/config/PageControlButtons/Visibility/$(listItem)$\\n\\\\end\\n<$button popup=<> tooltip=\\\"Status of synchronisation with server\\\" aria-label=\\\"Server status\\\" class=<> selectedClass=\\\"tc-selected\\\">\\n\\n<$list filter=\\\"[match[yes]]\\\">\\n{{$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/icon/cloud}}\\n\\n<$list filter=\\\"[match[yes]]\\\">\\n<$text text=\\\"Server status\\\"/>\\n\\n\\n\\n<$reveal state=<> type=\\\"popup\\\" position=\\\"belowleft\\\" animate=\\\"yes\\\">\\n
\\n<$list filter=\\\"[all[shadows+tiddlers]tag[$:/tags/TidgiSyncadaptorDropdown]!has[draft.of]]\\\" variable=\\\"listItem\\\">\\n<$transclude tiddler=<>/>\\n\\n
\\n\\n\"},\"$:/config/SaveWikiButton/Template\":{\"title\":\"$:/config/SaveWikiButton/Template\",\"text\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/save/offline\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/styles\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/styles\",\"tags\":\"[[$:/tags/Stylesheet]]\",\"text\":\"\\\\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline macrocallblock\\n\\nbody.tc-dirty span.tc-dirty-indicator svg {\\n\\ttransition: fill 250ms ease-in-out;\\n}\\n\\nbody .tc-image-cloud-idle {\\n\\tfill: <>;\\n\\ttransition: opacity 250ms ease-in-out;\\n\\topacity: 1;\\n\\tdisplay: unset;\\n}\\n\\nbody.tc-dirty .tc-image-cloud-idle {\\n\\topacity: 0;\\n\\tdisplay: none;\\n}\\n\\nbody .tc-image-cloud-progress {\\n\\ttransition: opacity 250ms ease-in-out;\\n\\ttransform-origin: 50% 50%;\\n\\ttransform: rotate(359deg);\\n\\tanimation: animation-rotate-slow 2s infinite linear;\\n\\tfill: <>;\\n\\tdisplay: none;\\n\\topacity: 0;\\n}\\n\\nbody.tc-dirty .tc-image-cloud-progress {\\n\\topacity: 1;\\n\\tdisplay: unset;\\n}\\n\\n@keyframes animation-rotate-slow {\\n\\tfrom {\\n\\t\\ttransform: rotate(0deg);\\n\\t}\\n\\tto {\\n\\t\\ttransform: scale(359deg);\\n\\t}\\n}\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/copy-logs\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/copy-logs\",\"tags\":\"$:/tags/TidgiSyncadaptorDropdown\",\"text\":\"<$button message=\\\"tm-copy-syncer-logs-to-clipboard\\\" class=\\\"tc-btn-invisible\\\">\\n{{$:/core/images/copy-clipboard}} Copy TidGi syncer logs to clipboard\\n\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/refresh\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/refresh\",\"tags\":\"$:/tags/TidgiSyncadaptorDropdown\",\"text\":\"<$reveal state=\\\"$:/status/IsLoggedIn\\\" type=\\\"match\\\" text=\\\"yes\\\">\\n<$button tooltip=\\\"Sync from TidGi main process\\\" aria-label=\\\"Refresh from server\\\" class=\\\"tc-btn-invisible\\\">\\n<$action-sendmessage $message=\\\"tm-server-refresh\\\"/>\\n{{$:/core/images/refresh-button}}<$text text=\\\"Sync from TidGi main process\\\"/>\\n\\n\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/save-snapshot\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/save-snapshot\",\"tags\":\"$:/tags/TidgiSyncadaptorDropdown\",\"text\":\"<$button class=\\\"tc-btn-invisible\\\">\\n<$wikify name=\\\"site-title\\\" text={{$:/config/SaveWikiButton/Filename}}>\\n<$action-sendmessage $message=\\\"tm-download-file\\\" $param={{$:/config/SaveWikiButton/Template}} filename=<>/>\\n\\n{{$:/core/images/download-button}} Save snapshot for offline use\\n\\n\"},\"$:/tags/TidgiSyncadaptorDropdown\":{\"title\":\"$:/tags/TidgiSyncadaptorDropdown\",\"list\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/refresh $:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/save-snapshot $:/plugins/linonetwo/expo-file-system-syncadaptor-ui/syncer-actions/copy-logs\"}}}","title":"$:/plugins/linonetwo/expo-file-system-syncadaptor-ui","type":"application/json","version":"0.1.0","Modern.TiddlyDev#SHA256-Hashed":"88bca903073179cd366f1d6a3f190cc94553f0257cbcf2c0f7097b417faea987"} \ No newline at end of file diff --git a/assets/plugins/syncadaptor.html b/assets/plugins/syncadaptor.html index c7f3c9e..e31b4e0 100644 --- a/assets/plugins/syncadaptor.html +++ b/assets/plugins/syncadaptor.html @@ -1 +1 @@ -{"author":"LinOnetwo","core-version":">=5.1.22","dependents":"","description":"Save/load data to tidgi's main process","list":"readme tree","name":"TidGi","plugin-priority":8,"plugin-priority-comment":"use 9, lower than $:/plugins/tiddlywiki/tiddlyweb's 10, so the js load before it to register","plugin-type":"plugin","text":"{\"tiddlers\":{\"$:/plugins/linonetwo/tidgi-ipc-syncadaptor/TiddlersToNotSave\":{\"title\":\"$:/plugins/linonetwo/tidgi-ipc-syncadaptor/TiddlersToNotSave\",\"creator\":\"LinOnetwo\",\"text\":\"$:/StoryList $:/HistoryList\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/readme\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/readme\",\"type\":\"text/vnd.tiddlywiki\",\"text\":\"!! SyncAdaptor\\n\\nCopied and modified from Tiddlywiki core's `plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js`.\\n\\nIt uses `src/services/wiki/ipcServerRoutes.ts` exposed from `window.wiki.ipcServerRoutes` to communicate with the main process.\\n\\nSome `JSON.stringify` and `JSON.parse` logic are removed, because we don't need this process when doing IPC. And some tiddlyweb related logic are removed, because it seems just transform to/back from tiddlyweb format, and nothing really changes after data received.\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/tree\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/tree\",\"caption\":\"{{$:/language/SideBar/Explorer/Caption}}\",\"text\":\"<>\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/file-system-syncadaptor.js\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/file-system-syncadaptor.js\",\"type\":\"application/javascript\",\"module-type\":\"syncadaptor\",\"Modern.TiddlyDev#Origin\":\"file-system-syncadaptor.ts\",\"text\":\"\\\"use strict\\\";var _a,_b,_c,__create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__esm=(e,i)=>function(){return i=e?(0,e[__getOwnPropNames(e)[0]])(e=0):i},__commonJS=(e,i)=>function(){return i||(0,e[__getOwnPropNames(e)[0]])((i={exports:{}}).exports,i),i.exports},__copyProps=(i,t,r,o)=>{if(t&&\\\"object\\\"==typeof t||\\\"function\\\"==typeof t)for(let e of __getOwnPropNames(t))__hasOwnProp.call(i,e)||e===r||__defProp(i,e,{get:()=>t[e],enumerable:!(o=__getOwnPropDesc(t,e))||o.enumerable});return i},__toESM=(e,i,t)=>(t=null!=e?__create(__getProtoOf(e)):{},__copyProps(!i&&e&&e.__esModule?t:__defProp(t,\\\"default\\\",{value:e,enumerable:!0}),e)),init_esbuild_inject=__esm({\\\"node_modules/.pnpm/tiddlywiki-plugin-dev@0.0.39_postcss@8.4.29_ts-node@10.9.1/node_modules/tiddlywiki-plugin-dev/dist/js/esbuild-inject.js\\\"(){}}),require_isObject=__commonJS({\\\"../node_modules/lodash/isObject.js\\\"(e,i){init_esbuild_inject(),i.exports=function(e){var i=typeof e;return null!=e&&(\\\"object\\\"==i||\\\"function\\\"==i)}}}),require_freeGlobal=__commonJS({\\\"../node_modules/lodash/_freeGlobal.js\\\"(e,i){init_esbuild_inject();var t=\\\"object\\\"==typeof global&&global&&global.Object===Object&&global;i.exports=t}}),require_root=__commonJS({\\\"../node_modules/lodash/_root.js\\\"(e,i){init_esbuild_inject();var t=require_freeGlobal(),r=\\\"object\\\"==typeof self&&self&&self.Object===Object&&self,t=t||r||Function(\\\"return this\\\")();i.exports=t}}),require_now=__commonJS({\\\"../node_modules/lodash/now.js\\\"(e,i){init_esbuild_inject();var t=require_root();i.exports=function(){return t.Date.now()}}}),require_trimmedEndIndex=__commonJS({\\\"../node_modules/lodash/_trimmedEndIndex.js\\\"(e,i){init_esbuild_inject();var t=/\\\\s/;i.exports=function(e){for(var i=e.length;i--&&t.test(e.charAt(i)););return i}}}),require_baseTrim=__commonJS({\\\"../node_modules/lodash/_baseTrim.js\\\"(e,i){init_esbuild_inject();var t=require_trimmedEndIndex(),r=/^\\\\s+/;i.exports=function(e){return e&&e.slice(0,t(e)+1).replace(r,\\\"\\\")}}}),require_Symbol=__commonJS({\\\"../node_modules/lodash/_Symbol.js\\\"(e,i){init_esbuild_inject();var t=require_root().Symbol;i.exports=t}}),require_getRawTag=__commonJS({\\\"../node_modules/lodash/_getRawTag.js\\\"(e,i){init_esbuild_inject();var t=require_Symbol(),r=Object.prototype,d=r.hasOwnProperty,s=r.toString,l=t?t.toStringTag:void 0;i.exports=function(e){var i=d.call(e,l),t=e[l];try{var r=!(e[l]=void 0)}catch(n){}var o=s.call(e);return r&&(i?e[l]=t:delete e[l]),o}}}),require_objectToString=__commonJS({\\\"../node_modules/lodash/_objectToString.js\\\"(e,i){init_esbuild_inject();var t=Object.prototype.toString;i.exports=function(e){return t.call(e)}}}),require_baseGetTag=__commonJS({\\\"../node_modules/lodash/_baseGetTag.js\\\"(e,i){init_esbuild_inject();var t=require_Symbol(),r=require_getRawTag(),o=require_objectToString(),n=t?t.toStringTag:void 0;i.exports=function(e){return null==e?void 0===e?\\\"[object Undefined]\\\":\\\"[object Null]\\\":(n&&n in Object(e)?r:o)(e)}}}),require_isObjectLike=__commonJS({\\\"../node_modules/lodash/isObjectLike.js\\\"(e,i){init_esbuild_inject(),i.exports=function(e){return null!=e&&\\\"object\\\"==typeof e}}}),require_isSymbol=__commonJS({\\\"../node_modules/lodash/isSymbol.js\\\"(e,i){init_esbuild_inject();var t=require_baseGetTag(),r=require_isObjectLike();i.exports=function(e){return\\\"symbol\\\"==typeof e||r(e)&&\\\"[object Symbol]\\\"==t(e)}}}),require_toNumber=__commonJS({\\\"../node_modules/lodash/toNumber.js\\\"(e,i){init_esbuild_inject();var t=require_baseTrim(),r=require_isObject(),o=require_isSymbol(),n=/^[-+]0x[0-9a-f]+$/i,d=/^0b[01]+$/i,s=/^0o[0-7]+$/i,l=parseInt;i.exports=function(e){if(\\\"number\\\"==typeof e)return e;if(o(e))return NaN;if(r(e)&&(i=\\\"function\\\"==typeof e.valueOf?e.valueOf():e,e=r(i)?i+\\\"\\\":i),\\\"string\\\"!=typeof e)return 0===e?e:+e;e=t(e);var i=d.test(e);return i||s.test(e)?l(e.slice(2),i?2:8):n.test(e)?NaN:+e}}}),require_debounce=__commonJS({\\\"../node_modules/lodash/debounce.js\\\"(e,i){init_esbuild_inject();var b=require_isObject(),h=require_now(),S=require_toNumber(),w=Math.max,y=Math.min;i.exports=function(r,o,e){var n,d,t,s,l,a,u=0,c=!1,_=!1,i=!0;if(\\\"function\\\"!=typeof r)throw new TypeError(\\\"Expected a function\\\");function g(e){var i=n,t=d;return n=d=void 0,u=e,s=r.apply(t,i)}function m(e){var i=e-a;return void 0===a||o<=i||i<0||_&&t<=e-u}function f(){var e,i=h();if(m(i))return p(i);l=setTimeout(f,(i=o-((e=i)-a),_?y(i,t-(e-u)):i))}function p(e){return l=void 0,i&&n?g(e):(n=d=void 0,s)}function v(){var e,i=h(),t=m(i);if(n=arguments,d=this,a=i,t){if(void 0===l)return u=e=a,l=setTimeout(f,o),c?g(e):s;if(_)return clearTimeout(l),l=setTimeout(f,o),g(a)}return void 0===l&&(l=setTimeout(f,o)),s}return o=S(o)||0,b(e)&&(c=!!e.leading,_=\\\"maxWait\\\"in e,t=_?w(S(e.maxWait)||0,o):t,i=\\\"trailing\\\"in e?!!e.trailing:i),v.cancel=function(){void 0!==l&&clearTimeout(l),n=a=d=l=void(u=0)},v.flush=function(){return void 0===l?s:p(h())},v}}}),import_debounce=(init_esbuild_inject(),__toESM(require_debounce())),TidGiMobileFileSystemSyncAdaptor=class{constructor(e){var i;if(this.name=\\\"tidgi-mobile-fs\\\",this.supportsLazyLoading=!0,this.updatedTiddlers={modifications:[],deletions:[]},this.recentUpdatedTiddlersFromClient={modifications:[],deletions:[]},void 0===(null==(i=window.service)?void 0:i.wikiStorageService))throw new Error(\\\"TidGi-Mobile wikiStorageService is undefined, can't load wiki.\\\");if(this.wikiStorageService=window.service.wikiStorageService,void 0===(null==(i=null==(i=window.meta)?void 0:i.call(window))?void 0:i.workspaceID))throw new Error(\\\"TidGi-Mobile workspaceID is undefined, can't load wiki.\\\");this.workspaceID=null==(i=null==(i=window.meta)?void 0:i.call(window))?void 0:i.workspaceID,this.wiki=e.wiki,this.hasStatus=!1,this.isAnonymous=!1,this.logger=new $tw.utils.Logger(\\\"TidGiMobileFileSystemSyncAdaptor\\\"),this.isLoggedIn=!1,this.isReadOnly=!1,this.logoutIsAvailable=!0}setupSSE(){if(void 0===this.wikiStorageService.getWikiChangeObserver$)console.error(\\\"getWikiChangeObserver$ is undefined in wikiStorageService, can't subscribe to server changes.\\\");else{const e=(0,import_debounce[\\\"default\\\"])(()=>{void 0===$tw.syncer?console.error(\\\"Syncer is undefined in TidGiMobileFileSystemSyncAdaptor. Abort the `syncFromServer` in `setupSSE debouncedSync`.\\\"):($tw.syncer.syncFromServer(),this.clearUpdatedTiddlers())},500);this.logger.log(\\\"setupSSE\\\"),this.configSyncer(),this.wikiStorageService.getWikiChangeObserver$().subscribe(i=>{Object.keys(i).forEach(e=>{i[e]&&(i[e].deleted&&!this.recentUpdatedTiddlersFromClient.deletions.includes(e)?this.updatedTiddlers.deletions.push(e):i[e].modified&&!this.recentUpdatedTiddlersFromClient.modifications.includes(e)&&this.updatedTiddlers.modifications.push(e))}),e()})}}addRecentUpdatedTiddlersFromClient(i,t){this.recentUpdatedTiddlersFromClient[i].push(t),setTimeout(()=>{var e=this.recentUpdatedTiddlersFromClient[i].indexOf(t);-1!==e&&this.recentUpdatedTiddlersFromClient[i].splice(e,1)},2e3)}clearUpdatedTiddlers(){this.updatedTiddlers={modifications:[],deletions:[]}}configSyncer(){void 0===$tw.syncer?console.error(\\\"Syncer is undefined in TidGiMobileFileSystemSyncAdaptor. Abort the configSyncer.\\\"):$tw.syncer.pollTimerInterval=2147483647}getUpdatedTiddlers(e,i){this.logger.log(\\\"getUpdatedTiddlers\\\"),i(null,this.updatedTiddlers)}setLoggerSaveBuffer(e){this.logger.setSaveBuffer(e)}isReady(){return!0}getTiddlerInfo(e){return{bag:e.fields.bag}}getTiddlerRevision(e){var i=this.wiki.getTiddler(e);return null==(i=null==i?void 0:i.fields)?void 0:i.revision}async getStatus(e){var i;this.logger.log(\\\"Getting status\\\");try{var t=await this.wikiStorageService.getStatus();if(void 0===t)throw new Error(\\\"No status returned from callWikiIpcServerRoute getStatus\\\");this.hasStatus=!0,this.recipe=null==(i=t.space)?void 0:i.recipe,this.isLoggedIn=\\\"GUEST\\\"!==t.username,this.isReadOnly=!!t.read_only,this.isAnonymous=!!t.anonymous,null!=e&&e(null,this.isLoggedIn,t.username,this.isReadOnly,this.isAnonymous)}catch(r){null!=e&&e(r)}}async getSkinnyTiddlers(e){this.logger.log(\\\"getSkinnyTiddlers\\\");try{var i=await this.wikiStorageService.getSkinnyTiddlers();if(void 0===i)null!=e&&e(new Error(\\\"Load tiddler store failed\\\"));else{var t=JSON.parse(i);if(void 0===t)throw new Error(\\\"No tiddlers returned from callWikiIpcServerRoute getTiddlersJSON in getSkinnyTiddlers\\\");this.logger.log(\\\"skinnyTiddlers.length\\\",t.length),e(null,t)}}catch(r){null!=e&&e(r)}}async saveTiddler(e,i,t){var r;if(this.isReadOnly)i(null);else try{var o,n,d=e.fields.title;$tw.utils.parseStringArray(null!=(r=this.wiki.getTiddlerText(\\\"$:/plugins/linonetwo/expo-file-system-syncadaptor/TiddlersToNotSave\\\"))?r:\\\"\\\").includes(d)?(this.logger.log(`Ignore saveTiddler ${d}, config in TiddlersToNotSave`),i(null)):(this.logger.log(\\\"saveTiddler \\\"+d),this.addRecentUpdatedTiddlersFromClient(\\\"modifications\\\",d),void 0===(o=await this.wikiStorageService.saveTiddler(d,e.getFieldStrings()))?i(new Error(\\\"Response from server is missing required `etag` header\\\")):void 0===(n=this.parseEtag(o))?i(new Error(\\\"Response from server etag header failed to parsed from \\\"+o)):i(null,{bag:n.bag},n.revision))}catch(s){null!=i&&i(s)}}async loadTiddler(e,i){var t;this.logger.log(\\\"loadTiddler \\\"+e);try{var r=this.wiki.getTiddler(e);if(void 0===r)throw new Error(`Tiddler \\\"${e}\\\" not exist`);var o=await this.wikiStorageService.loadTiddlerText(e),n={...r.fields,text:o,type:null!=(t=r.fields.type)?t:\\\"text/vnd.tiddlywiki\\\",_is_skinny:void 0,revision:void 0,bag:void 0};null!=i&&i(null,n)}catch(d){null!=i&&i(d)}}async deleteTiddler(e,i,t){if(this.isReadOnly)i(null);else{var r=null==(r=null==(r=null==t?void 0:t.tiddlerInfo)?void 0:r.adaptorInfo)?void 0:r.bag;if(this.logger.log(\\\"deleteTiddler\\\",r),r){this.addRecentUpdatedTiddlersFromClient(\\\"deletions\\\",e);r=await this.wikiStorageService.deleteTiddler(e);try{if(!r)throw new Error(\\\"getTiddler returned undefined from callWikiIpcServerRoute getTiddler in loadTiddler\\\");i(null,null)}catch(o){null!=i&&i(o)}}else i(null,t.tiddlerInfo.adaptorInfo)}}parseEtag(e){var i=e.indexOf(\\\"/\\\"),t=e.lastIndexOf(\\\"/\\\"),r=e.lastIndexOf(\\\":\\\");if(-1!==i&&-1!==t&&-1!==r)return{bag:$tw.utils.decodeURIComponentSafe(e.substring(1,i)),title:$tw.utils.decodeURIComponentSafe(e.substring(i+1,t)),revision:e.substring(t+1,r)}}};if($tw.browser&&\\\"undefined\\\"!=typeof window){const Qb=\\\"undefined\\\"!=typeof document&&window.isInTidGi,Rb=Boolean(null==(_a=window.service)?void 0:_a.wikiStorageService),Sb=Boolean(null==(_c=null==(_b=window.meta)?void 0:_b.call(window))?void 0:_c.workspaceID);Qb&&Rb&&Sb&&(exports.adaptorClass=TidGiMobileFileSystemSyncAdaptor)}\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/fix-location-info.js\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/fix-location-info.js\",\"type\":\"application/javascript\",\"module-type\":\"info\",\"Modern.TiddlyDev#Origin\":\"fix-location-info.ts\",\"text\":\"\\\"use strict\\\";function getInfoTiddlerFields(e){var t,i,n=function(e){return e?\\\"yes\\\":\\\"no\\\"},d=[];return $tw.browser&&\\\"undefined\\\"!=typeof window&&(t=\\\"undefined\\\"!=typeof document,i=null==(i=null==(i=window.meta)?void 0:i.call(window))?void 0:i.workspaceID,d.push({title:\\\"$:/info/tidgi\\\",text:n(t)},{title:\\\"$:/info/tidgi-mobile\\\",text:n(t)}),t)&&i&&d.push({title:\\\"$:/info/tidgi/workspaceID\\\",text:i}),d}exports.getInfoTiddlerFields=getInfoTiddlerFields;\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/monitorLocationChange.js\":{\"module-type\":\"startup\",\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/monitorLocationChange.js\",\"type\":\"application/javascript\",\"Modern.TiddlyDev#Origin\":\"monitorLocationChange.ts\",\"text\":\"\\\"use strict\\\";var setup=()=>{window.addEventListener(\\\"hashchange\\\",()=>{var e,i=location.hash;null!=(e=null==(e=window.service)?void 0:e.wikiHookService)&&e.saveLocationInfo(i)})};exports.startup=setup;\"}}}","title":"$:/plugins/linonetwo/expo-file-system-syncadaptor","type":"application/json","version":"0.1.0","Modern.TiddlyDev#SHA256-Hashed":"00c6bdbe027ba9f7ff385c30dfd4c7672f2e8f74db927c1fb7a7361350ab68cb"} \ No newline at end of file +{"author":"LinOnetwo","core-version":">=5.1.22","dependents":"","description":"Save/load data to tidgi's main process","list":"readme tree","name":"TidGi","plugin-priority-comment":"Shouldn't add priority, otherwise content won't load.","plugin-type":"plugin","text":"{\"tiddlers\":{\"$:/plugins/linonetwo/tidgi-ipc-syncadaptor/TiddlersToNotSave\":{\"title\":\"$:/plugins/linonetwo/tidgi-ipc-syncadaptor/TiddlersToNotSave\",\"creator\":\"LinOnetwo\",\"text\":\"$:/StoryList $:/HistoryList\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/readme\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/readme\",\"type\":\"text/vnd.tiddlywiki\",\"text\":\"!! SyncAdaptor\\n\\nCopied and modified from Tiddlywiki core's `plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js`.\\n\\nIt uses `src/services/wiki/ipcServerRoutes.ts` exposed from `window.wiki.ipcServerRoutes` to communicate with the main process.\\n\\nSome `JSON.stringify` and `JSON.parse` logic are removed, because we don't need this process when doing IPC. And some tiddlyweb related logic are removed, because it seems just transform to/back from tiddlyweb format, and nothing really changes after data received.\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/tree\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/tree\",\"caption\":\"{{$:/language/SideBar/Explorer/Caption}}\",\"text\":\"<>\\n\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/file-system-syncadaptor.js\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/file-system-syncadaptor.js\",\"type\":\"application/javascript\",\"module-type\":\"syncadaptor\",\"Modern.TiddlyDev#Origin\":\"file-system-syncadaptor.ts\",\"text\":\"\\\"use strict\\\";var _a,_b,_c,__create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__esm=(e,i)=>function(){return i=e?(0,e[__getOwnPropNames(e)[0]])(e=0):i},__commonJS=(e,i)=>function(){return i||(0,e[__getOwnPropNames(e)[0]])((i={exports:{}}).exports,i),i.exports},__copyProps=(i,t,r,o)=>{if(t&&\\\"object\\\"==typeof t||\\\"function\\\"==typeof t)for(let e of __getOwnPropNames(t))__hasOwnProp.call(i,e)||e===r||__defProp(i,e,{get:()=>t[e],enumerable:!(o=__getOwnPropDesc(t,e))||o.enumerable});return i},__toESM=(e,i,t)=>(t=null!=e?__create(__getProtoOf(e)):{},__copyProps(!i&&e&&e.__esModule?t:__defProp(t,\\\"default\\\",{value:e,enumerable:!0}),e)),init_esbuild_inject=__esm({\\\"node_modules/.pnpm/tiddlywiki-plugin-dev@0.0.39_postcss@8.4.29_ts-node@10.9.1/node_modules/tiddlywiki-plugin-dev/dist/js/esbuild-inject.js\\\"(){}}),require_isObject=__commonJS({\\\"../node_modules/lodash/isObject.js\\\"(e,i){init_esbuild_inject(),i.exports=function(e){var i=typeof e;return null!=e&&(\\\"object\\\"==i||\\\"function\\\"==i)}}}),require_freeGlobal=__commonJS({\\\"../node_modules/lodash/_freeGlobal.js\\\"(e,i){init_esbuild_inject();var t=\\\"object\\\"==typeof global&&global&&global.Object===Object&&global;i.exports=t}}),require_root=__commonJS({\\\"../node_modules/lodash/_root.js\\\"(e,i){init_esbuild_inject();var t=require_freeGlobal(),r=\\\"object\\\"==typeof self&&self&&self.Object===Object&&self,t=t||r||Function(\\\"return this\\\")();i.exports=t}}),require_now=__commonJS({\\\"../node_modules/lodash/now.js\\\"(e,i){init_esbuild_inject();var t=require_root();i.exports=function(){return t.Date.now()}}}),require_trimmedEndIndex=__commonJS({\\\"../node_modules/lodash/_trimmedEndIndex.js\\\"(e,i){init_esbuild_inject();var t=/\\\\s/;i.exports=function(e){for(var i=e.length;i--&&t.test(e.charAt(i)););return i}}}),require_baseTrim=__commonJS({\\\"../node_modules/lodash/_baseTrim.js\\\"(e,i){init_esbuild_inject();var t=require_trimmedEndIndex(),r=/^\\\\s+/;i.exports=function(e){return e&&e.slice(0,t(e)+1).replace(r,\\\"\\\")}}}),require_Symbol=__commonJS({\\\"../node_modules/lodash/_Symbol.js\\\"(e,i){init_esbuild_inject();var t=require_root().Symbol;i.exports=t}}),require_getRawTag=__commonJS({\\\"../node_modules/lodash/_getRawTag.js\\\"(e,i){init_esbuild_inject();var t=require_Symbol(),r=Object.prototype,d=r.hasOwnProperty,s=r.toString,l=t?t.toStringTag:void 0;i.exports=function(e){var i=d.call(e,l),t=e[l];try{var r=!(e[l]=void 0)}catch(n){}var o=s.call(e);return r&&(i?e[l]=t:delete e[l]),o}}}),require_objectToString=__commonJS({\\\"../node_modules/lodash/_objectToString.js\\\"(e,i){init_esbuild_inject();var t=Object.prototype.toString;i.exports=function(e){return t.call(e)}}}),require_baseGetTag=__commonJS({\\\"../node_modules/lodash/_baseGetTag.js\\\"(e,i){init_esbuild_inject();var t=require_Symbol(),r=require_getRawTag(),o=require_objectToString(),n=t?t.toStringTag:void 0;i.exports=function(e){return null==e?void 0===e?\\\"[object Undefined]\\\":\\\"[object Null]\\\":(n&&n in Object(e)?r:o)(e)}}}),require_isObjectLike=__commonJS({\\\"../node_modules/lodash/isObjectLike.js\\\"(e,i){init_esbuild_inject(),i.exports=function(e){return null!=e&&\\\"object\\\"==typeof e}}}),require_isSymbol=__commonJS({\\\"../node_modules/lodash/isSymbol.js\\\"(e,i){init_esbuild_inject();var t=require_baseGetTag(),r=require_isObjectLike();i.exports=function(e){return\\\"symbol\\\"==typeof e||r(e)&&\\\"[object Symbol]\\\"==t(e)}}}),require_toNumber=__commonJS({\\\"../node_modules/lodash/toNumber.js\\\"(e,i){init_esbuild_inject();var t=require_baseTrim(),r=require_isObject(),o=require_isSymbol(),n=/^[-+]0x[0-9a-f]+$/i,d=/^0b[01]+$/i,s=/^0o[0-7]+$/i,l=parseInt;i.exports=function(e){if(\\\"number\\\"==typeof e)return e;if(o(e))return NaN;if(r(e)&&(i=\\\"function\\\"==typeof e.valueOf?e.valueOf():e,e=r(i)?i+\\\"\\\":i),\\\"string\\\"!=typeof e)return 0===e?e:+e;e=t(e);var i=d.test(e);return i||s.test(e)?l(e.slice(2),i?2:8):n.test(e)?NaN:+e}}}),require_debounce=__commonJS({\\\"../node_modules/lodash/debounce.js\\\"(e,i){init_esbuild_inject();var b=require_isObject(),h=require_now(),S=require_toNumber(),w=Math.max,y=Math.min;i.exports=function(r,o,e){var n,d,t,s,l,a,u=0,c=!1,_=!1,i=!0;if(\\\"function\\\"!=typeof r)throw new TypeError(\\\"Expected a function\\\");function g(e){var i=n,t=d;return n=d=void 0,u=e,s=r.apply(t,i)}function m(e){var i=e-a;return void 0===a||o<=i||i<0||_&&t<=e-u}function f(){var e,i=h();if(m(i))return p(i);l=setTimeout(f,(i=o-((e=i)-a),_?y(i,t-(e-u)):i))}function p(e){return l=void 0,i&&n?g(e):(n=d=void 0,s)}function v(){var e,i=h(),t=m(i);if(n=arguments,d=this,a=i,t){if(void 0===l)return u=e=a,l=setTimeout(f,o),c?g(e):s;if(_)return clearTimeout(l),l=setTimeout(f,o),g(a)}return void 0===l&&(l=setTimeout(f,o)),s}return o=S(o)||0,b(e)&&(c=!!e.leading,_=\\\"maxWait\\\"in e,t=_?w(S(e.maxWait)||0,o):t,i=\\\"trailing\\\"in e?!!e.trailing:i),v.cancel=function(){void 0!==l&&clearTimeout(l),n=a=d=l=void(u=0)},v.flush=function(){return void 0===l?s:p(h())},v}}}),import_debounce=(init_esbuild_inject(),__toESM(require_debounce())),TidGiMobileFileSystemSyncAdaptor=class{constructor(e){var i;if(this.name=\\\"tidgi-mobile-fs\\\",this.supportsLazyLoading=!0,this.updatedTiddlers={modifications:[],deletions:[]},this.recentUpdatedTiddlersFromClient={modifications:[],deletions:[]},void 0===(null==(i=window.service)?void 0:i.wikiStorageService))throw new Error(\\\"TidGi-Mobile wikiStorageService is undefined, can't load wiki.\\\");if(this.wikiStorageService=window.service.wikiStorageService,void 0===(null==(i=null==(i=window.meta)?void 0:i.call(window))?void 0:i.workspaceID))throw new Error(\\\"TidGi-Mobile workspaceID is undefined, can't load wiki.\\\");this.workspaceID=null==(i=null==(i=window.meta)?void 0:i.call(window))?void 0:i.workspaceID,this.wiki=e.wiki,this.hasStatus=!1,this.isAnonymous=!1,this.logger=new $tw.utils.Logger(\\\"TidGiMobileFileSystemSyncAdaptor\\\"),this.isLoggedIn=!1,this.isReadOnly=!1,this.logoutIsAvailable=!0}setupSSE(){if(void 0===this.wikiStorageService.getWikiChangeObserver$)console.error(\\\"getWikiChangeObserver$ is undefined in wikiStorageService, can't subscribe to server changes.\\\");else{const e=(0,import_debounce[\\\"default\\\"])(()=>{void 0===$tw.syncer?console.error(\\\"Syncer is undefined in TidGiMobileFileSystemSyncAdaptor. Abort the `syncFromServer` in `setupSSE debouncedSync`.\\\"):($tw.syncer.syncFromServer(),this.clearUpdatedTiddlers())},500);this.logger.log(\\\"setupSSE\\\"),this.configSyncer(),this.wikiStorageService.getWikiChangeObserver$().subscribe(i=>{Object.keys(i).forEach(e=>{i[e]&&(i[e].deleted&&!this.recentUpdatedTiddlersFromClient.deletions.includes(e)?this.updatedTiddlers.deletions.push(e):i[e].modified&&!this.recentUpdatedTiddlersFromClient.modifications.includes(e)&&this.updatedTiddlers.modifications.push(e))}),e()})}}addRecentUpdatedTiddlersFromClient(i,t){this.recentUpdatedTiddlersFromClient[i].push(t),setTimeout(()=>{var e=this.recentUpdatedTiddlersFromClient[i].indexOf(t);-1!==e&&this.recentUpdatedTiddlersFromClient[i].splice(e,1)},2e3)}clearUpdatedTiddlers(){this.updatedTiddlers={modifications:[],deletions:[]}}configSyncer(){void 0===$tw.syncer?console.error(\\\"Syncer is undefined in TidGiMobileFileSystemSyncAdaptor. Abort the configSyncer.\\\"):$tw.syncer.pollTimerInterval=2147483647}getUpdatedTiddlers(e,i){this.logger.log(\\\"getUpdatedTiddlers\\\"),i(null,this.updatedTiddlers)}setLoggerSaveBuffer(e){this.logger.setSaveBuffer(e)}isReady(){return!0}getTiddlerInfo(e){return{bag:e.fields.bag}}getTiddlerRevision(e){var i=this.wiki.getTiddler(e);return null==(i=null==i?void 0:i.fields)?void 0:i.revision}async getStatus(e){var i;this.logger.log(\\\"Getting status\\\");try{var t=await this.wikiStorageService.getStatus();if(void 0===t)throw new Error(\\\"No status returned from callWikiIpcServerRoute getStatus\\\");this.hasStatus=!0,this.recipe=null==(i=t.space)?void 0:i.recipe,this.isLoggedIn=\\\"GUEST\\\"!==t.username,this.isReadOnly=!!t.read_only,this.isAnonymous=!!t.anonymous,null!=e&&e(null,this.isLoggedIn,t.username,this.isReadOnly,this.isAnonymous)}catch(r){null!=e&&e(r)}}async getSkinnyTiddlers(e){this.logger.log(\\\"getSkinnyTiddlers\\\");try{var i=await this.wikiStorageService.getSkinnyTiddlers();if(void 0===i)null!=e&&e(new Error(\\\"Load tiddler store failed\\\"));else{var t=JSON.parse(i);if(void 0===t)throw new Error(\\\"No tiddlers returned from callWikiIpcServerRoute getTiddlersJSON in getSkinnyTiddlers\\\");this.logger.log(\\\"skinnyTiddlers.length\\\",t.length),e(null,t)}}catch(r){null!=e&&e(r)}}async saveTiddler(e,i,t){var r;if(this.isReadOnly)i(null);else try{var o,n,d=e.fields.title;$tw.utils.parseStringArray(null!=(r=this.wiki.getTiddlerText(\\\"$:/plugins/linonetwo/expo-file-system-syncadaptor/TiddlersToNotSave\\\"))?r:\\\"\\\").includes(d)?(this.logger.log(`Ignore saveTiddler ${d}, config in TiddlersToNotSave`),i(null)):(this.logger.log(\\\"saveTiddler \\\"+d),this.addRecentUpdatedTiddlersFromClient(\\\"modifications\\\",d),void 0===(o=await this.wikiStorageService.saveTiddler(d,e.getFieldStrings()))?i(new Error(\\\"Response from server is missing required `etag` header\\\")):void 0===(n=this.parseEtag(o))?i(new Error(\\\"Response from server etag header failed to parsed from \\\"+o)):i(null,{bag:n.bag},n.revision))}catch(s){null!=i&&i(s)}}async loadTiddler(e,i){var t;this.logger.log(\\\"loadTiddler \\\"+e);try{var r=this.wiki.getTiddler(e);if(void 0===r)throw new Error(`Tiddler \\\"${e}\\\" not exist`);var o=await this.wikiStorageService.loadTiddlerText(e),n={...r.fields,text:o,type:null!=(t=r.fields.type)?t:\\\"text/vnd.tiddlywiki\\\",_is_skinny:void 0,revision:void 0,bag:void 0};null!=i&&i(null,n)}catch(d){null!=i&&i(d)}}async deleteTiddler(e,i,t){if(this.isReadOnly)i(null);else{var r=null==(r=null==(r=null==t?void 0:t.tiddlerInfo)?void 0:r.adaptorInfo)?void 0:r.bag;if(this.logger.log(\\\"deleteTiddler\\\",r),r){this.addRecentUpdatedTiddlersFromClient(\\\"deletions\\\",e);r=await this.wikiStorageService.deleteTiddler(e);try{if(!r)throw new Error(\\\"getTiddler returned undefined from callWikiIpcServerRoute getTiddler in loadTiddler\\\");i(null,null)}catch(o){null!=i&&i(o)}}else i(null,t.tiddlerInfo.adaptorInfo)}}parseEtag(e){var i=e.indexOf(\\\"/\\\"),t=e.lastIndexOf(\\\"/\\\"),r=e.lastIndexOf(\\\":\\\");if(-1!==i&&-1!==t&&-1!==r)return{bag:$tw.utils.decodeURIComponentSafe(e.substring(1,i)),title:$tw.utils.decodeURIComponentSafe(e.substring(i+1,t)),revision:e.substring(t+1,r)}}};if($tw.browser&&\\\"undefined\\\"!=typeof window){const Qb=\\\"undefined\\\"!=typeof document&&window.isInTidGi,Rb=Boolean(null==(_a=window.service)?void 0:_a.wikiStorageService),Sb=Boolean(null==(_c=null==(_b=window.meta)?void 0:_b.call(window))?void 0:_c.workspaceID);Qb&&Rb&&Sb&&(exports.adaptorClass=TidGiMobileFileSystemSyncAdaptor)}\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/fix-location-info.js\":{\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/fix-location-info.js\",\"type\":\"application/javascript\",\"module-type\":\"info\",\"Modern.TiddlyDev#Origin\":\"fix-location-info.ts\",\"text\":\"\\\"use strict\\\";function getInfoTiddlerFields(e){var t,i,n=function(e){return e?\\\"yes\\\":\\\"no\\\"},d=[];return $tw.browser&&\\\"undefined\\\"!=typeof window&&(t=\\\"undefined\\\"!=typeof document,i=null==(i=null==(i=window.meta)?void 0:i.call(window))?void 0:i.workspaceID,d.push({title:\\\"$:/info/tidgi\\\",text:n(t)},{title:\\\"$:/info/tidgi-mobile\\\",text:n(t)}),t)&&i&&d.push({title:\\\"$:/info/tidgi/workspaceID\\\",text:i}),d}exports.getInfoTiddlerFields=getInfoTiddlerFields;\"},\"$:/plugins/linonetwo/expo-file-system-syncadaptor/monitorLocationChange.js\":{\"module-type\":\"startup\",\"title\":\"$:/plugins/linonetwo/expo-file-system-syncadaptor/monitorLocationChange.js\",\"type\":\"application/javascript\",\"Modern.TiddlyDev#Origin\":\"monitorLocationChange.ts\",\"text\":\"\\\"use strict\\\";var setup=()=>{window.addEventListener(\\\"hashchange\\\",()=>{var e,i=location.hash;null!=(e=null==(e=window.service)?void 0:e.wikiHookService)&&e.saveLocationInfo(i)})};exports.startup=setup;\"}}}","title":"$:/plugins/linonetwo/expo-file-system-syncadaptor","type":"application/json","version":"0.1.0","Modern.TiddlyDev#SHA256-Hashed":"b7b1a45b70837a12b6229bd6a1598d38105d55eecd5287df0a765cc7451b0fb8"} \ No newline at end of file diff --git a/plugins/src/expo-file-system-syncadaptor-ui/plugin.info b/plugins/src/expo-file-system-syncadaptor-ui/plugin.info index 9089b4b..e25a8c6 100644 --- a/plugins/src/expo-file-system-syncadaptor-ui/plugin.info +++ b/plugins/src/expo-file-system-syncadaptor-ui/plugin.info @@ -8,6 +8,5 @@ "version": "0.1.0", "dependents": ["$:/plugins/linonetwo/expo-file-system-syncadaptor"], "list": "readme tree", - "plugin-priority-comment": "use 11, higher than $:/plugins/tiddlywiki/tiddlyweb's 10, so we load after it to overwrite it", - "plugin-priority": 12 + "plugin-priority-comment": "Shouldn't add priority, otherwise content won't load." } diff --git a/plugins/src/expo-file-system-syncadaptor/plugin.info b/plugins/src/expo-file-system-syncadaptor/plugin.info index 01282a7..31ad8b8 100644 --- a/plugins/src/expo-file-system-syncadaptor/plugin.info +++ b/plugins/src/expo-file-system-syncadaptor/plugin.info @@ -8,6 +8,5 @@ "version": "0.1.0", "dependents": [], "list": "readme tree", - "plugin-priority-comment": "use 9, lower than $:/plugins/tiddlywiki/tiddlyweb's 10, so the js load before it to register", - "plugin-priority": 8 + "plugin-priority-comment": "Shouldn't add priority, otherwise content won't load." } diff --git a/src/pages/WikiWebView/useStreamChunksToWebView/index.ts b/src/pages/WikiWebView/useStreamChunksToWebView/index.ts index c269335..b639a33 100644 --- a/src/pages/WikiWebView/useStreamChunksToWebView/index.ts +++ b/src/pages/WikiWebView/useStreamChunksToWebView/index.ts @@ -1,7 +1,7 @@ import { MutableRefObject, useCallback, useEffect, useState } from 'react'; import { WebView } from 'react-native-webview'; import { IHtmlContent } from '../useTiddlyWiki'; -import { getWebviewSideReceiver, OnStreamChunksToWebViewEventTypes } from './webviewSideReceiver'; +import { getWebviewSideReceiver, OnStreamChunksToWebViewEventTypes, webviewSideReceiver } from './webviewSideReceiver'; const CHUNK_SIZE = 1_000_000; @@ -72,10 +72,10 @@ export function useStreamChunksToWebView(webViewReference: MutableRefObject(undefined); - useEffect(() => { - void getWebviewSideReceiver().then(webviewSideReceiverSetter); - }, []); + // const [webviewSideReceiver, webviewSideReceiverSetter] = useState(undefined); + // useEffect(() => { + // void getWebviewSideReceiver().then(webviewSideReceiverSetter); + // }, []); return { injectHtmlAndTiddlersStore, webviewSideReceiver } as const; } diff --git a/src/pages/WikiWebView/useStreamChunksToWebView/webviewSideReceiver.ts b/src/pages/WikiWebView/useStreamChunksToWebView/webviewSideReceiver.ts index 6df6e5a..2760033 100644 --- a/src/pages/WikiWebView/useStreamChunksToWebView/webviewSideReceiver.ts +++ b/src/pages/WikiWebView/useStreamChunksToWebView/webviewSideReceiver.ts @@ -33,3 +33,125 @@ export const getWebviewSideReceiver = async () => { } return await fs.readAsStringAsync(streamChunksPreloadScriptFileUri); }; +export const webviewSideReceiver = `// Initialize an empty string to start with +(function useStreamChunksToWebViewWebviewSideReceiverIIFE() { + let tiddlersStoreAccumulatedContent = ''; + let skinnyTiddlersStoreAccumulatedContent = ''; + let wikiHTML = ''; + let scriptCompleteCount = 0; + function resetUseStreamChunksToWebViewWebviewSideReceiverIIFE() { + tiddlersStoreAccumulatedContent = ''; + skinnyTiddlersStoreAccumulatedContent = ''; + wikiHTML = ''; + scriptCompleteCount = 0; + } + + window.onStreamChunksToWebView = function (event) { + const data = event.data; + + switch (event.type) { + case 'TIDDLYWIKI_HTML': { + wikiHTML += data; + break; + } + case 'TIDDLER_STORE_SCRIPT_CHUNK': { + tiddlersStoreAccumulatedContent += data; + break; + } + case 'TIDDLER_SKINNY_STORE_SCRIPT_CHUNK': { + skinnyTiddlersStoreAccumulatedContent += data; + break; + } + case 'TIDDLER_SKINNY_STORE_SCRIPT_CHUNK_END': + case 'TIDDLER_STORE_SCRIPT_CHUNK_END': { + scriptCompleteCount += 1; + if (scriptCompleteCount === 2) { + // start jobs + startInjectHTML(); + } + break; + } + } + }; + + function startInjectHTML() { + console.log('startInjectHTML'); + /** + * All information needed are collected. + * Start using html and store. + */ + + /** + * Use MutationObserver to watch if wikiHTML is loaded. + * We execute the script tags after this. + */ + const observer = new MutationObserver((mutationsList, observer) => { + let hasChange = false; + for (let mutation of mutationsList) { + if (mutation.type === 'childList') { + hasChange = true; + } + } + if (hasChange) { + observer.disconnect(); // Important: disconnect the observer once done. + // use timeout to give splash screen a chance to execute and show + setTimeout(executeScriptsAfterInjectHTML, 100); + } + }); + + // Start observing the body with the configured parameters + observer.observe(document.body, { childList: true }); + + // this ignores all script tags, so we need 'executeScriptsAfterInjectHTML()' later. + document.body.innerHTML = wikiHTML; + } + + function appendStoreScript(storeJSON, name) { + const tiddlersStoreScript = document.createElement('script'); + tiddlersStoreScript.type = 'application/json'; + tiddlersStoreScript.classList.add('tiddlywiki-tiddler-store', name); + tiddlersStoreScript.textContent = storeJSON; + const styleAreaDiv = document.getElementById('styleArea'); + styleAreaDiv?.insertAdjacentElement('afterend', tiddlersStoreScript); + } + + /** + * Manually execute each of the script tags. + * Delay the script execution slightly, until MutationObserver found document.body is ready. + */ + function executeScriptsAfterInjectHTML() { + console.log('executeScriptsAfterInjectHTML'); + try { + // load tiddlers store, place it after
where it used to belong to. + appendStoreScript(skinnyTiddlersStoreAccumulatedContent, 'skinnyTiddlers'); + appendStoreScript(tiddlersStoreAccumulatedContent, 'pluginsAndJS'); + + // load other scripts + const scriptElements = document.querySelectorAll('script'); + for (let script of scriptElements) { + // skip tiddlersStoreScript we just added + if (script.classList.contains('tiddlywiki-tiddler-store')) continue; + // activate other scripts in the HTML + const newScript = document.createElement('script'); + // copy all attributes from the original script to the new one + for (const { name, value } of script.attributes) { + newScript.setAttribute(name, value); + } + if (script.src) { + // if the original script has a 'src' url, load it + newScript.src = script.src; + } else { + // if the script has inline content, set it + newScript.textContent = script.textContent; + } + // replace the old script element with the new one + script.parentNode?.replaceChild(newScript, script); + } + } catch (e) { + console.error('executeScriptsAfterInjectHTML error', e); + } + resetUseStreamChunksToWebViewWebviewSideReceiverIIFE(); + } +})(); + +`;