Files
Genarrative/apps/mobile-shell/src/shell/mobileShellNavigation.ts
T
kdletters 00b41b6a29 统一宿主壳目录边界
移动端壳拆分为 host-bridge 与 shell 目录

桌面端 Tauri 拆分为 host_bridge 与 shell Rust 模块

更新三端桥接层结构门禁与配置检查

同步宿主壳方案文档和项目共享决策
2026-06-18 16:02:55 +08:00

60 lines
1.2 KiB
TypeScript

import { normalizeHostBridgeExternalUrl } from '../../../../packages/shared/src/contracts/hostBridge';
export function shouldOpenInMobileShellWebView(
rawUrl: string,
allowedOrigin: string,
) {
if (rawUrl === 'about:blank') {
return true;
}
if (
!rawUrl.startsWith('/') &&
!rawUrl.startsWith('#') &&
!/^[a-z][a-z0-9+.-]*:/i.test(rawUrl)
) {
return false;
}
try {
const url = new URL(rawUrl, allowedOrigin);
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
return false;
}
return url.origin === allowedOrigin;
} catch {
return false;
}
}
export function resolveMobileShellExternalUrl(rawUrl: string) {
return normalizeHostBridgeExternalUrl(rawUrl);
}
export function shouldAcceptMobileShellHostBridgeMessage(
rawUrl: string,
allowedOrigin: string,
) {
return rawUrl !== 'about:blank' &&
shouldOpenInMobileShellWebView(rawUrl, allowedOrigin);
}
export function resolveMobileShellWebViewUrl(
rawUrl: string,
allowedOrigin: string,
) {
if (
rawUrl === 'about:blank' ||
!shouldOpenInMobileShellWebView(rawUrl, allowedOrigin)
) {
return null;
}
try {
return new URL(rawUrl, allowedOrigin).toString();
} catch {
return null;
}
}