mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
feat: bundle tiddlyweb icons in ipc syncadaptor plugin
This commit is contained in:
parent
18f6fb3256
commit
e88a225f3b
22 changed files with 209 additions and 12 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
import esbuild from 'esbuild';
|
||||
|
||||
const outDir = path.join(__dirname, '../plugins-dev/linonetwo');
|
||||
const outDir = path.join(__dirname, '../plugins-dev/linonetwo/tidgi');
|
||||
await fs.mkdirp(outDir);
|
||||
const tsconfigPath = path.join(__dirname, '../tsconfig.json');
|
||||
const sourceFolder = '../src/services/wiki/plugin/ipcSyncAdaptor';
|
||||
|
|
@ -14,9 +14,12 @@ await esbuild.build({
|
|||
logLevel: 'info',
|
||||
entryPoints: [path.join(__dirname, sourceFolder, 'index.ts')],
|
||||
bundle: true,
|
||||
// use node so we have `exports`, otherwise `module.adaptorClass` in $:/core/modules/startup.js will be undefined
|
||||
platform: 'node',
|
||||
minify: true,
|
||||
outdir: outDir,
|
||||
tsconfig: tsconfigPath,
|
||||
target: 'ESNEXT',
|
||||
});
|
||||
const filterFunc = (src) => {
|
||||
return !src.endsWith('.ts');
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
||||
/* eslint-disable unicorn/no-null */
|
||||
import type { IWikiServerStatusObject } from '@services/wiki/ipcServerRoutes';
|
||||
import type { WindowMeta, WindowNames } from '@services/windows/WindowProperties';
|
||||
|
|
@ -390,10 +391,12 @@ class TidGiIPCSyncAdaptor {
|
|||
}
|
||||
}
|
||||
|
||||
const isInTidGi = ($tw.browser != null) && document.location.protocol.startsWith('tidgi');
|
||||
const servicesExposed = window.service?.wiki !== undefined;
|
||||
const hasWorkspaceIDinMeta = (window.meta as WindowMeta[WindowNames.view]).workspaceID !== undefined;
|
||||
if (isInTidGi && servicesExposed && hasWorkspaceIDinMeta) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
exports.adaptorClass = TidGiIPCSyncAdaptor;
|
||||
if (typeof $tw !== 'undefined' && $tw.browser && typeof window !== 'undefined') {
|
||||
const isInTidGi = typeof document !== 'undefined' && document?.location?.protocol?.startsWith('tidgi');
|
||||
const servicesExposed = Boolean(window.service?.wiki);
|
||||
const hasWorkspaceIDinMeta = Boolean((window.meta as WindowMeta[WindowNames.view]).workspaceID);
|
||||
if (isInTidGi && servicesExposed && hasWorkspaceIDinMeta) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
exports.adaptorClass = TidGiIPCSyncAdaptor;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
"core-version": ">=5.1.22",
|
||||
"plugin-type": "plugin",
|
||||
"version": "0.1.0",
|
||||
"dependents": [],
|
||||
"list": "readme"
|
||||
"dependents": ["$:/plugins/tiddlywiki/tiddlyweb"],
|
||||
"list": "readme tree",
|
||||
"plugin-priority-comment": "lower than $:/plugins/tiddlywiki/tiddlyweb's 10, so we load before it, so our syncadaptor load first in core/modules/server/server.js",
|
||||
"plugin-priority": 9
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,4 @@ Copied and modified from Tiddlywiki core's `plugins/tiddlywiki/tiddlyweb/tiddlyw
|
|||
|
||||
It uses `src/services/wiki/ipcServerRoutes.ts` exposed from `window.wiki.ipcServerRoutes` to communicate with the main process.
|
||||
|
||||
Some `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.
|
||||
Some `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.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
title: $:/core/templates/css-tiddler
|
||||
|
||||
<!--
|
||||
|
||||
This template is used for saving CSS tiddlers as a style tag with data attributes representing the tiddler fields. This version includes the tiddler changecount as the field `revision`.
|
||||
|
||||
-->`<style`<$fields exclude='text revision bag' template=' data-tiddler-$name$="$encoded_value$"'></$fields>` data-tiddler-revision="`<<changecount>>`" data-tiddler-bag="default" type="text/css">`<$view field="text" format="text" />`</style>`
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
title: $:/core/templates/html-div-skinny-tiddler
|
||||
|
||||
<!--
|
||||
|
||||
This template is a variant of the tiddlyweb plugin's overridden version of $:/core/templates/html-div-tiddler used for saving skinny tiddlers (with no text field)
|
||||
|
||||
-->`<div`<$fields exclude='text revision bag' template=' $name$="$encoded_value$"'></$fields>` revision="`<<changecount>>`" bag="default" _is_skinny="">
|
||||
<pre></pre>
|
||||
</div>`
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
title: $:/core/templates/html-div-tiddler
|
||||
|
||||
<!--
|
||||
|
||||
This template is used for saving tiddlers as an HTML DIV tag with attributes representing the tiddler fields. This version includes the tiddler changecount as the field `revision`.
|
||||
|
||||
-->`<div`<$fields exclude='text revision bag' template=' $name$="$encoded_value$"'></$fields>` revision="`<<changecount>>`" bag="default">
|
||||
<pre>`<$view field="text" format="htmltextencoded" />`</pre>
|
||||
</div>`
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
title: $:/core/templates/html-json-skinny-tiddler
|
||||
|
||||
<$list filter="[<numTiddlers>compare:number:gteq[1]] ~[<counter>!match[1]]">`,`<$text text=<<newline>>/></$list>
|
||||
<$jsontiddler tiddler=<<currentTiddler>> exclude="text" escapeUnsafeScriptChars="yes" $revision=<<changecount>> $bag="default" $_is_skinny=""/>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
title: $:/core/templates/html-json-tiddler
|
||||
|
||||
<$list filter="[<counter>!match[1]]">`,`<$text text=<<newline>>/></$list>
|
||||
<$jsontiddler tiddler=<<currentTiddler>> escapeUnsafeScriptChars="yes" $revision=<<changecount>> $bag="default">/>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
title: $:/core/templates/javascript-tiddler
|
||||
|
||||
<!--
|
||||
|
||||
This template is used for saving JavaScript tiddlers as a script tag with data attributes representing the tiddler fields. This version includes the tiddler changecount as the field `revision`.
|
||||
|
||||
-->`<script`<$fields exclude='text revision bag' template=' data-tiddler-$name$="$encoded_value$"'></$fields>` data-tiddler-revision="`<<changecount>>`" data-tiddler-bag="default" type="text/javascript">`<$view field="text" format="text" />`</script>`
|
||||
4
src/services/wiki/plugin/ipcSyncAdaptor/tree.tid
Normal file
4
src/services/wiki/plugin/ipcSyncAdaptor/tree.tid
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
title: $:/plugins/linonetwo/tidgi/tree
|
||||
caption: {{$:/language/SideBar/Explorer/Caption}}
|
||||
|
||||
<<tree "$:/plugins/linonetwo/tidgi/">>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
title: $:/config/SaveWikiButton/Template
|
||||
|
||||
$:/plugins/linonetwo/tidgi/save/offline
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
title: $:/plugins/linonetwo/tidgi/icon/cloud
|
||||
tags: $:/tags/Image
|
||||
|
||||
<svg class="tc-image-cloud tc-image-button" width="22pt" height="22pt" viewBox="0 0 128 128"><g><path d="M24 103C10.745 103 0 92.255 0 79c0-9.697 5.75-18.05 14.027-21.836A24.787 24.787 0 0114 56c0-13.255 10.745-24 24-24 1.373 0 2.718.115 4.028.337C48.628 24.2 58.707 19 70 19c19.882 0 36 16.118 36 36v.082c12.319 1.016 22 11.336 22 23.918 0 12.239-9.16 22.337-20.999 23.814L107 103H24z"/><path class="tc-image-cloud-idle" d="M57.929 84.698a6 6 0 01-8.485 0L35.302 70.556a6 6 0 118.485-8.485l9.9 9.9L81.97 43.686a6 6 0 018.485 8.486L57.929 84.698z"/><path class="tc-image-cloud-progress tc-animate-rotate-slow" d="M44.8 40a3.6 3.6 0 100 7.2h2.06A23.922 23.922 0 0040 64c0 13.122 10.531 23.785 23.603 23.997L64 88l.001-7.2c-9.171 0-16.626-7.348-16.798-16.477L47.2 64c0-5.165 2.331-9.786 5.999-12.868L53.2 55.6a3.6 3.6 0 107.2 0v-12a3.6 3.6 0 00-3.6-3.6h-12zM64 40v7.2c9.278 0 16.8 7.522 16.8 16.8 0 5.166-2.332 9.787-6 12.869V72.4a3.6 3.6 0 10-7.2 0v12a3.6 3.6 0 003.6 3.6h12a3.6 3.6 0 100-7.2l-2.062.001A23.922 23.922 0 0088 64c0-13.255-10.745-24-24-24z"/></g></svg>
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
title: $:/plugins/linonetwo/tidgi/readonly
|
||||
tags: [[$:/tags/Stylesheet]]
|
||||
|
||||
\define button-selector(title)
|
||||
button.$title$, .tc-drop-down button.$title$, div.$title$
|
||||
\end
|
||||
|
||||
\define hide-edit-controls()
|
||||
<$reveal state="$:/status/IsReadOnly" type="match" text="yes" default="yes">
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fplugins\%2Flinonetwo\%2Fslate-write\%2Fui\%2FViewToolbar\%2FButtons\%2Fedit-wysiwyg>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fclone>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fdelete>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fedit>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fnew-here>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fnew-journal-here>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fimport>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fmanager>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fnew-image>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fnew-journal>>`,`
|
||||
<<button-selector tc-btn-\%24\%3A\%2Fcore\%2Fui\%2FButtons\%2Fnew-tiddler>> `{
|
||||
display: none;
|
||||
}`
|
||||
</$reveal>
|
||||
\end
|
||||
|
||||
\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline macrocallblock
|
||||
|
||||
<<hide-edit-controls>>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
title: $:/plugins/linonetwo/tidgi/save/offline
|
||||
|
||||
\import [subfilter{$:/core/config/GlobalImportFilter}]
|
||||
\define saveTiddlerFilter()
|
||||
[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/tidgi]] -[prefix[$:/temp/]] +[sort[title]] $(publishFilter)$
|
||||
\end
|
||||
{{$:/core/templates/tiddlywiki5.html}}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
title: $:/core/ui/Buttons/save-wiki
|
||||
tags: $:/tags/PageControls
|
||||
caption: {{$:/plugins/linonetwo/tidgi/icon/cloud}} Server status
|
||||
description: Status of synchronisation with server
|
||||
|
||||
\whitespace trim
|
||||
\define config-title()
|
||||
$:/config/PageControlButtons/Visibility/$(listItem)$
|
||||
\end
|
||||
<$button popup=<<qualify "$:/state/popup/save-wiki">> tooltip="Status of synchronisation with server" aria-label="Server status" class=<<tv-config-toolbar-class>> selectedClass="tc-selected">
|
||||
<span class="tc-dirty-indicator">
|
||||
<$list filter="[<tv-config-toolbar-icons>match[yes]]">
|
||||
{{$:/plugins/linonetwo/tidgi/icon/cloud}}
|
||||
</$list>
|
||||
<$list filter="[<tv-config-toolbar-text>match[yes]]">
|
||||
<span class="tc-btn-text"><$text text="Server status"/></span>
|
||||
</$list>
|
||||
</span>
|
||||
</$button>
|
||||
<$reveal state=<<qualify "$:/state/popup/save-wiki">> type="popup" position="belowleft" animate="yes">
|
||||
<div class="tc-drop-down">
|
||||
<$list filter="[all[shadows+tiddlers]tag[$:/tags/SyncerDropdown]!has[draft.of]]" variable="listItem">
|
||||
<$transclude tiddler=<<listItem>>/>
|
||||
</$list>
|
||||
</div>
|
||||
</$reveal>
|
||||
44
src/services/wiki/plugin/ipcSyncAdaptor/ui/styles.tid
Normal file
44
src/services/wiki/plugin/ipcSyncAdaptor/ui/styles.tid
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
title: $:/plugins/linonetwo/tidgi/styles
|
||||
tags: [[$:/tags/Stylesheet]]
|
||||
|
||||
\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline macrocallblock
|
||||
|
||||
body.tc-dirty span.tc-dirty-indicator svg {
|
||||
transition: fill 250ms ease-in-out;
|
||||
}
|
||||
|
||||
body .tc-image-cloud-idle {
|
||||
fill: <<colour background>>;
|
||||
transition: opacity 250ms ease-in-out;
|
||||
opacity: 1;
|
||||
display: unset;
|
||||
}
|
||||
|
||||
body.tc-dirty .tc-image-cloud-idle {
|
||||
opacity: 0;
|
||||
display: none;
|
||||
}
|
||||
|
||||
body .tc-image-cloud-progress {
|
||||
transition: opacity 250ms ease-in-out;
|
||||
transform-origin: 50% 50%;
|
||||
transform: rotate(359deg);
|
||||
animation: animation-rotate-slow 2s infinite linear;
|
||||
fill: <<colour background>>;
|
||||
display: none;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
body.tc-dirty .tc-image-cloud-progress {
|
||||
opacity: 1;
|
||||
display: unset;
|
||||
}
|
||||
|
||||
@keyframes animation-rotate-slow {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: scale(359deg);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
title: $:/plugins/linonetwo/tidgi/syncer-actions/copy-logs
|
||||
tags: $:/tags/SyncerDropdown
|
||||
|
||||
<$button message="tm-copy-syncer-logs-to-clipboard" class="tc-btn-invisible">
|
||||
{{$:/core/images/copy-clipboard}} Copy syncer logs to clipboard
|
||||
</$button>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
title: $:/plugins/linonetwo/tidgi/syncer-actions/refresh
|
||||
tags: $:/tags/SyncerDropdown
|
||||
|
||||
<$reveal state="$:/status/IsLoggedIn" type="match" text="yes">
|
||||
<$button tooltip="Get latest changes from the server" aria-label="Refresh from server" class="tc-btn-invisible">
|
||||
<$action-sendmessage $message="tm-server-refresh"/>
|
||||
{{$:/core/images/refresh-button}}<span class="tc-btn-text"><$text text="Get latest changes from the server"/></span>
|
||||
</$button>
|
||||
</$reveal>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
title: $:/plugins/linonetwo/tidgi/syncer-actions/save-snapshot
|
||||
tags: $:/tags/SyncerDropdown
|
||||
|
||||
<$button class="tc-btn-invisible">
|
||||
<$wikify name="site-title" text={{$:/config/SaveWikiButton/Filename}}>
|
||||
<$action-sendmessage $message="tm-download-file" $param={{$:/config/SaveWikiButton/Template}} filename=<<site-title>>/>
|
||||
</$wikify>
|
||||
{{$:/core/images/download-button}} Save snapshot for offline use
|
||||
</$button>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
title: $:/tags/SyncerDropdown
|
||||
list: $:/plugins/linonetwo/tidgi/syncer-actions/refresh $:/plugins/linonetwo/tidgi/syncer-actions/save-snapshot $:/plugins/linonetwo/tidgi/syncer-actions/copy-logs
|
||||
|
|
@ -136,7 +136,7 @@ function startNodeJSWiki({
|
|||
const builtInPluginArguments = [
|
||||
// add tiddly filesystem back if is not readonly https://github.com/Jermolene/TiddlyWiki5/issues/4484#issuecomment-596779416
|
||||
readOnlyMode === true ? undefined : '+plugins/tiddlywiki/filesystem',
|
||||
'+plugins/tiddlywiki/tiddlyweb',
|
||||
// '+plugins/tiddlywiki/tiddlyweb', // we use $:/plugins/linonetwo/tidgi instead
|
||||
// '+plugins/linonetwo/watch-fs',
|
||||
].filter((a): a is string => Boolean(a));
|
||||
/**
|
||||
|
|
@ -217,8 +217,15 @@ function startNodeJSWiki({
|
|||
});
|
||||
});
|
||||
});
|
||||
wikiInstance.loadPlugins(['linonetwo/tidgi'], EXTRA_TIDGI_PLUGINS_PATH);
|
||||
wikiInstance.boot.startup({ bootPath: TIDDLYWIKI_PACKAGE_FOLDER });
|
||||
/**
|
||||
* Install $:/plugins/linonetwo/tidgi instead of +plugins/tiddlywiki/tiddlyweb to speedup (without JSON.parse) and fix http errors when network change.
|
||||
*/
|
||||
const tidgiPlugin = wikiInstance.loadPluginFolder(path.join(EXTRA_TIDGI_PLUGINS_PATH, 'linonetwo/tidgi'));
|
||||
if (tidgiPlugin !== null) {
|
||||
wikiInstance.wiki.addTiddler(tidgiPlugin);
|
||||
}
|
||||
// after setWikiInstance, ipc server routes will start serving content
|
||||
ipcServerRoutes.setWikiInstance(wikiInstance);
|
||||
} catch (error) {
|
||||
const message = `Tiddlywiki booted failed with error ${(error as Error).message} ${(error as Error).stack ?? ''}`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue