guanghu/tests/helpers/fixtureVaultDesktopBridge.ts
冰朔 8739805f99
Some checks failed
Auto-update PR branches / Update open PR branches (push) Has been cancelled
CI / Frontend Static Quality Checks (push) Has been cancelled
CI / Frontend Tests & Coverage (push) Has been cancelled
CI / Rust Tests & Quality Checks (push) Has been cancelled
CI / Linux build verification (push) Has been cancelled
Release (Alpha) / Compute alpha version (push) Has been cancelled
Release (Alpha) / Build release artifacts (push) Has been cancelled
Release (Alpha) / GitHub Release (alpha) (push) Has been cancelled
Release (Alpha) / Update docs and release pages (push) Has been cancelled
Deploy docs / Build VitePress site (push) Has been cancelled
Deploy docs / Deploy to GitHub Pages (push) Has been cancelled
光湖开源源码快照 · Tolaria AGPL 分叉基线 · 独立更新链
2026-07-05 17:45:16 +08:00

28 lines
919 B
TypeScript

export function installFixtureVaultDesktopBridgeInBrowser(): void {
const dispatchBrowserMenuCommand =
window.__laputaTest?.dispatchBrowserMenuCommand
?? (() => { throw new Error('Tolaria test bridge is missing dispatchBrowserMenuCommand') })
const specialHandlers: Record<string, (args?: Record<string, unknown>) => unknown> = {
trigger_menu_command: (args) => {
dispatchBrowserMenuCommand(String(args?.id ?? ''))
return null
},
}
const invoke = (command: string, args?: Record<string, unknown>) => {
const handler = specialHandlers[command] ?? window.__mockHandlers?.[command]
if (!handler) throw new Error(`Unhandled invoke: ${command}`)
return handler(args)
}
Object.defineProperty(window, '__TAURI__', {
configurable: true,
value: {},
})
Object.defineProperty(window, '__TAURI_INTERNALS__', {
configurable: true,
value: { invoke },
})
}