mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
@@ -6,3 +6,4 @@ export * from './popup';
|
||||
export * from './string2color';
|
||||
export * from './toast';
|
||||
export * from './unflatten-object';
|
||||
export * from './url';
|
||||
|
||||
33
packages/frontend/core/src/utils/url.ts
Normal file
33
packages/frontend/core/src/utils/url.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { appInfo } from '@affine/electron-api';
|
||||
|
||||
interface AppUrlOptions {
|
||||
desktop?: boolean | string;
|
||||
openInHiddenWindow?: boolean;
|
||||
redirectFromWeb?: boolean;
|
||||
}
|
||||
|
||||
export function buildAppUrl(path: string, opts: AppUrlOptions = {}) {
|
||||
// TODO(@EYHN): should use server base url
|
||||
const webBase = runtimeConfig.serverUrlPrefix;
|
||||
// TODO(@pengx17): how could we know the corresponding app schema in web environment
|
||||
if (opts.desktop && appInfo?.schema) {
|
||||
const urlCtor = new URL(path, webBase);
|
||||
|
||||
if (opts.openInHiddenWindow) {
|
||||
urlCtor.searchParams.set('hidden', 'true');
|
||||
}
|
||||
|
||||
const url = `${appInfo.schema}://${urlCtor.pathname}${urlCtor.search}`;
|
||||
|
||||
if (opts.redirectFromWeb) {
|
||||
const redirect_uri = new URL('/open-app/url', webBase);
|
||||
redirect_uri.searchParams.set('url', url);
|
||||
|
||||
return redirect_uri.toString();
|
||||
}
|
||||
|
||||
return url;
|
||||
} else {
|
||||
return new URL(path, webBase).toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user