mark electron renderer for codex bridge
This commit is contained in:
parent
31a8e07a5b
commit
a54e847c8e
5 changed files with 82 additions and 17 deletions
|
|
@ -38,6 +38,10 @@ type DesktopAiRuntime = {
|
|||
|
||||
declare global {
|
||||
interface Window {
|
||||
islandflowDesktopRuntime?: {
|
||||
app?: string | null;
|
||||
shell?: string | null;
|
||||
};
|
||||
islandflowDesktop?: DesktopAiBridge;
|
||||
}
|
||||
}
|
||||
|
|
@ -59,14 +63,28 @@ type DesktopAiContextValue = {
|
|||
|
||||
const BRIDGE_POLL_INTERVAL_MS = 250;
|
||||
const BRIDGE_POLL_MAX_ATTEMPTS = 20;
|
||||
const ELECTRON_USER_AGENT_PATTERN = /\bElectron\/\S+/i;
|
||||
const ELECTRON_USER_AGENT_PATTERN = /\b(?:Electron|IslandflowDesktop)\/\S+/i;
|
||||
|
||||
export const detectDesktopShell = (userAgent: string | null | undefined): boolean =>
|
||||
Boolean(userAgent && ELECTRON_USER_AGENT_PATTERN.test(userAgent));
|
||||
|
||||
export const detectDesktopRuntimeMarker = (
|
||||
runtime:
|
||||
| {
|
||||
app?: string | null;
|
||||
shell?: string | null;
|
||||
}
|
||||
| null
|
||||
| undefined
|
||||
): boolean => runtime?.app === "islandflow" && runtime.shell === "electron";
|
||||
|
||||
export const resolveDesktopAiRuntime = (
|
||||
value:
|
||||
| {
|
||||
islandflowDesktopRuntime?: {
|
||||
app?: string | null;
|
||||
shell?: string | null;
|
||||
};
|
||||
islandflowDesktop?: DesktopAiBridge;
|
||||
navigator?: { userAgent?: string | null };
|
||||
}
|
||||
|
|
@ -75,7 +93,10 @@ export const resolveDesktopAiRuntime = (
|
|||
): DesktopAiRuntime => {
|
||||
const bridge = value?.islandflowDesktop?.ai ? value.islandflowDesktop : null;
|
||||
const bridgeAvailable = Boolean(bridge?.ai);
|
||||
const shellAvailable = bridgeAvailable || detectDesktopShell(value?.navigator?.userAgent);
|
||||
const shellAvailable =
|
||||
bridgeAvailable ||
|
||||
detectDesktopRuntimeMarker(value?.islandflowDesktopRuntime) ||
|
||||
detectDesktopShell(value?.navigator?.userAgent);
|
||||
|
||||
return {
|
||||
shellAvailable,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue