mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-05 18:20:39 -08:00
parent
f1ac503a96
commit
105b87f981
1 changed files with 25 additions and 21 deletions
|
|
@ -18,30 +18,34 @@ export class DeepLinkService implements IDeepLinkService {
|
||||||
*/
|
*/
|
||||||
private readonly deepLinkHandler: (requestUrl: string) => Promise<void> = async (requestUrl) => {
|
private readonly deepLinkHandler: (requestUrl: string) => Promise<void> = async (requestUrl) => {
|
||||||
logger.info(`Receiving deep link`, { requestUrl, function: 'deepLinkHandler' });
|
logger.info(`Receiving deep link`, { requestUrl, function: 'deepLinkHandler' });
|
||||||
// hostname is workspace id or name
|
try {
|
||||||
const { hostname, hash, pathname } = new URL(requestUrl);
|
// hostname is workspace id or name
|
||||||
let workspace = await this.workspaceService.get(hostname);
|
const { hostname, hash, pathname } = new URL(requestUrl);
|
||||||
if (workspace === undefined) {
|
let workspace = await this.workspaceService.get(hostname);
|
||||||
logger.info(`Workspace not found, try get by name`, { hostname, function: 'deepLinkHandler' });
|
|
||||||
let workspaceName = hostname;
|
|
||||||
// Host name can't use Chinese or it becomes `xn--1-376ap73a`, so use `w` host, and get workspace name from path
|
|
||||||
if (hostname === 'w') {
|
|
||||||
workspaceName = decodeURIComponent(pathname.split('/')[1] ?? '');
|
|
||||||
logger.info(`Workspace name from w/`, { hostname, pathname, workspaceName, function: 'deepLinkHandler' });
|
|
||||||
}
|
|
||||||
workspace = await this.workspaceService.getByWikiName(workspaceName);
|
|
||||||
if (workspace === undefined) {
|
if (workspace === undefined) {
|
||||||
return;
|
logger.info(`Workspace not found, try get by name`, { hostname, function: 'deepLinkHandler' });
|
||||||
|
let workspaceName = hostname;
|
||||||
|
// Host name can't use Chinese or it becomes `xn--1-376ap73a`, so use `w` host, and get workspace name from path
|
||||||
|
if (hostname === 'w') {
|
||||||
|
workspaceName = decodeURIComponent(pathname.split('/')[1] ?? '');
|
||||||
|
logger.info(`Workspace name from w/`, { hostname, pathname, workspaceName, function: 'deepLinkHandler' });
|
||||||
|
}
|
||||||
|
workspace = await this.workspaceService.getByWikiName(workspaceName);
|
||||||
|
if (workspace === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
let tiddlerName = hash.substring(1); // remove '#:'
|
||||||
|
if (tiddlerName.includes(':')) {
|
||||||
|
tiddlerName = tiddlerName.split(':')[1];
|
||||||
|
}
|
||||||
|
// Support CJK
|
||||||
|
tiddlerName = decodeURIComponent(tiddlerName);
|
||||||
|
logger.info(`Open deep link`, { workspaceId: workspace.id, tiddlerName, function: 'deepLinkHandler' });
|
||||||
|
await this.workspaceService.openWorkspaceTiddler(workspace, tiddlerName);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Invalid URL`, { requestUrl, error, function: 'deepLinkHandler' });
|
||||||
}
|
}
|
||||||
let tiddlerName = hash.substring(1); // remove '#:'
|
|
||||||
if (tiddlerName.includes(':')) {
|
|
||||||
tiddlerName = tiddlerName.split(':')[1];
|
|
||||||
}
|
|
||||||
// Support CJK
|
|
||||||
tiddlerName = decodeURIComponent(tiddlerName);
|
|
||||||
logger.info(`Open deep link`, { workspaceId: workspace.id, tiddlerName, function: 'deepLinkHandler' });
|
|
||||||
await this.workspaceService.openWorkspaceTiddler(workspace, tiddlerName);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public initializeDeepLink(protocol: string) {
|
public initializeDeepLink(protocol: string) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue