Files
AstrBot/dashboard/src/utils/desktopRuntime.ts
エイカク 5d0fc8ac7a refactor(dashboard): replace legacy isElectron bridge fields with isDesktop (#5269)
* refactor dashboard desktop bridge fields from isElectron to isDesktop

* refactor dashboard runtime detection into shared helper
2026-02-21 01:35:23 +09:00

33 lines
924 B
TypeScript

export type DesktopRuntimeInfo = {
bridge: Window['astrbotDesktop'] | undefined
hasDesktopRuntimeProbe: boolean
hasDesktopRestartCapability: boolean
isDesktopRuntime: boolean
}
export async function getDesktopRuntimeInfo(): Promise<DesktopRuntimeInfo> {
const bridge = window.astrbotDesktop
const hasDesktopRuntimeProbe =
!!bridge && typeof bridge.isDesktopRuntime === 'function'
const hasDesktopRestartCapability =
!!bridge &&
typeof bridge.restartBackend === 'function' &&
hasDesktopRuntimeProbe
let isDesktopRuntime = !!bridge?.isDesktop
if (hasDesktopRuntimeProbe) {
try {
isDesktopRuntime = isDesktopRuntime || !!(await bridge.isDesktopRuntime())
} catch (error) {
console.warn('[desktop-runtime] Failed to detect desktop runtime.', error)
}
}
return {
bridge,
hasDesktopRuntimeProbe,
hasDesktopRestartCapability,
isDesktopRuntime,
}
}