diff --git a/docs/Development.md b/docs/Development.md index a764a3c9..af599a20 100644 --- a/docs/Development.md +++ b/docs/Development.md @@ -107,6 +107,8 @@ TBD ### `Uncaught ReferenceError: require is not defined` +Or `Uncaught TypeError: Cannot read properties of undefined (reading 'call') at __webpack_require__ (index.js:4317:33)` + `pnpm run clean:cache` can fix this. ### Electron download slow diff --git a/src/services/deepLink/index.ts b/src/services/deepLink/index.ts index 9fe28c98..2c0d61e2 100644 --- a/src/services/deepLink/index.ts +++ b/src/services/deepLink/index.ts @@ -18,18 +18,23 @@ export class DeepLinkService implements IDeepLinkService { */ private readonly deepLinkHandler: (requestUrl: string) => Promise = async (requestUrl) => { logger.info(`Receiving deep link`, { requestUrl, function: 'deepLinkHandler' }); - const url = new URL(requestUrl); - const workspaceId = url.hostname; - const workspace = await this.workspaceService.get(workspaceId); + // hostname is workspace id or name + const { hostname, hash } = new URL(requestUrl); + let workspace = await this.workspaceService.get(hostname); if (workspace === undefined) { - logger.error(`Workspace not found`, { workspaceId, function: 'deepLinkHandler' }); - return; + logger.error(`Workspace not found, try get by name`, { hostname, function: 'deepLinkHandler' }); + workspace = await this.workspaceService.getByWikiName(hostname); + if (workspace === undefined) { + return; + } } - let tiddlerName = url.hash.substring(1); // remove '#:' + let tiddlerName = hash.substring(1); // remove '#:' if (tiddlerName.includes(':')) { tiddlerName = tiddlerName.split(':')[1]; } - logger.info(`Open deep link`, { workspaceId, tiddlerName, function: 'deepLinkHandler' }); + // Support CJK + tiddlerName = decodeURIComponent(tiddlerName); + logger.info(`Open deep link`, { workspaceId: workspace.id, tiddlerName, function: 'deepLinkHandler' }); await this.workspaceService.openWorkspaceTiddler(workspace, tiddlerName); }; diff --git a/src/services/workspaces/index.ts b/src/services/workspaces/index.ts index e5032a30..a0c81c65 100644 --- a/src/services/workspaces/index.ts +++ b/src/services/workspaces/index.ts @@ -289,6 +289,12 @@ export class Workspace implements IWorkspaceService { return (await this.getWorkspacesAsList()).find((workspace) => workspace.wikiFolderLocation === wikiFolderLocation); } + public async getByWikiName(wikiName: string): Promise { + return (await this.getWorkspacesAsList()) + .sort((a, b) => a.order - b.order) + .find((workspace) => workspace.name === wikiName); + } + public getPreviousWorkspace = async (id: string): Promise => { const workspaceList = await this.getWorkspacesAsList(); let currentWorkspaceIndex = 0; diff --git a/src/services/workspaces/interface.ts b/src/services/workspaces/interface.ts index 976f0e0a..140ef91c 100644 --- a/src/services/workspaces/interface.ts +++ b/src/services/workspaces/interface.ts @@ -186,6 +186,10 @@ export interface IWorkspaceService { getActiveWorkspaceSync: () => IWorkspace | undefined; getAllMetaData: () => Promise>>; getByWikiFolderLocation(wikiFolderLocation: string): Promise; + /** + * Get workspace by human readable wiki name, if no workspace found, return undefined. If multiple workspace with same name, return the first one order by sidebar. + */ + getByWikiName(wikiName: string): Promise; getFirstWorkspace: () => Promise; /** * Get parent workspace of a subWorkspace, if the workspace you provided is a main workspace, return undefined. @@ -236,7 +240,7 @@ export const WorkspaceServiceIPCDescriptor = { get$: ProxyPropertyType.Function$, getActiveWorkspace: ProxyPropertyType.Function, getAllMetaData: ProxyPropertyType.Function, - getByName: ProxyPropertyType.Function, + getByWikiName: ProxyPropertyType.Function, getFirstWorkspace: ProxyPropertyType.Function, getMainWorkspace: ProxyPropertyType.Function, getMetaData: ProxyPropertyType.Function,