diff --git a/scripts/compilePlugins.mjs b/scripts/compilePlugins.mjs index 42c8c788..9848faca 100644 --- a/scripts/compilePlugins.mjs +++ b/scripts/compilePlugins.mjs @@ -30,6 +30,10 @@ await Promise.all([ ...sharedConfig, entryPoints: [path.join(__dirname, tidgiIpcSyncadaptorSourceFolder, 'electron-ipc-cat.ts')], }), + esbuild.build({ + ...sharedConfig, + entryPoints: [path.join(__dirname, tidgiIpcSyncadaptorSourceFolder, 'fix-location-info.ts')], + }), ]); const filterFunc = (src) => { return !src.endsWith('.ts'); diff --git a/src/services/wiki/plugin/ipcSyncAdaptor/fix-location-info.js.meta b/src/services/wiki/plugin/ipcSyncAdaptor/fix-location-info.js.meta new file mode 100644 index 00000000..a27f0951 --- /dev/null +++ b/src/services/wiki/plugin/ipcSyncAdaptor/fix-location-info.js.meta @@ -0,0 +1,3 @@ +title: $:/plugins/linonetwo/tidgi-ipc-syncadaptor/fix-location-info.js +type: application/javascript +module-type: info \ No newline at end of file diff --git a/src/services/wiki/plugin/ipcSyncAdaptor/fix-location-info.ts b/src/services/wiki/plugin/ipcSyncAdaptor/fix-location-info.ts new file mode 100644 index 00000000..a9abd5d2 --- /dev/null +++ b/src/services/wiki/plugin/ipcSyncAdaptor/fix-location-info.ts @@ -0,0 +1,40 @@ +/* eslint-disable @typescript-eslint/strict-boolean-expressions */ + +import type { WindowMeta, WindowNames } from '@services/windows/WindowProperties'; + +function getInfoTiddlerFields(updateInfoTiddlersCallback: (infos: Array<{ text: string; title: string }>) => void) { + const mapBoolean = function(value: boolean) { + return value ? 'yes' : 'no'; + }; + const infoTiddlerFields: Array<{ text: string; title: string }> = []; + // Basics + if (!$tw.browser || typeof window === 'undefined') return infoTiddlerFields; + const isInTidGi = typeof document !== 'undefined' && document?.location?.protocol?.startsWith('tidgi'); + const workspaceID = (window.meta as WindowMeta[WindowNames.view] | undefined)?.workspaceID; + infoTiddlerFields.push({ title: '$:/info/tidgi', text: mapBoolean(isInTidGi) }); + if (isInTidGi && workspaceID) { + infoTiddlerFields.push({ title: '$:/info/tidgi-workspace-id', text: workspaceID }); + void window.service.workspace.get(workspaceID).then(async (workspace) => { + if (workspace === undefined) return; + const asyncInfoTiddlerFields: Array<{ text: string; title: string }> = []; + const setLocationProperty = function(name: string, value: string) { + asyncInfoTiddlerFields.push({ title: '$:/info/url/' + name, text: value }); + }; + const localHostUrl = await window.service.native.getLocalHostUrlWithActualInfo(workspace.homeUrl, workspaceID); + const urlObject = new URL(localHostUrl); + setLocationProperty('full', (localHostUrl).split('#')[0]); + setLocationProperty('host', urlObject.host); + setLocationProperty('hostname', urlObject.hostname); + setLocationProperty('protocol', workspace.https ? 'https' : 'http'); + setLocationProperty('port', urlObject.port); + setLocationProperty('pathname', urlObject.pathname); + setLocationProperty('search', urlObject.search); + setLocationProperty('origin', urlObject.origin); + updateInfoTiddlersCallback(asyncInfoTiddlerFields); + }); + } + return infoTiddlerFields; +} + +// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access +exports.getInfoTiddlerFields = getInfoTiddlerFields; diff --git a/src/services/wiki/plugin/ipcSyncAdaptor/ipc-syncadaptor.ts b/src/services/wiki/plugin/ipcSyncAdaptor/ipc-syncadaptor.ts index f4c2ade7..2fef2e56 100644 --- a/src/services/wiki/plugin/ipcSyncAdaptor/ipc-syncadaptor.ts +++ b/src/services/wiki/plugin/ipcSyncAdaptor/ipc-syncadaptor.ts @@ -351,10 +351,10 @@ class TidGiIPCSyncAdaptor { } } -if (typeof $tw !== 'undefined' && $tw.browser && typeof window !== 'undefined') { +if ($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); + const hasWorkspaceIDinMeta = Boolean((window.meta as WindowMeta[WindowNames.view] | undefined)?.workspaceID); if (isInTidGi && servicesExposed && hasWorkspaceIDinMeta) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access exports.adaptorClass = TidGiIPCSyncAdaptor; diff --git a/src/services/workspaces/index.ts b/src/services/workspaces/index.ts index 087aaf20..f2c71a3f 100644 --- a/src/services/workspaces/index.ts +++ b/src/services/workspaces/index.ts @@ -413,7 +413,6 @@ export class Workspace implements IWorkspaceService { if (currentPicturePath) { try { await fsExtra.remove(currentPicturePath); - return; } catch (error) { console.error(error); }