fix electron codex bridge loading

This commit is contained in:
dirtydishes 2026-05-20 19:44:45 -04:00
parent 32e965d782
commit 31a8e07a5b
5 changed files with 299 additions and 2 deletions

View file

@ -5,7 +5,7 @@
"version": "0.1.0",
"main": "dist/main.js",
"scripts": {
"build": "tsc -p tsconfig.json",
"build": "tsc -p tsconfig.json && cp src/preload.cjs dist/preload.cjs",
"typecheck": "tsc -p tsconfig.json --noEmit",
"test": "bun test src",
"start": "bun run build && electron-forge start",

View file

@ -27,7 +27,7 @@ const WINDOW_TITLE = "Islandflow";
let mainWindow: BrowserWindow | null = null;
let desktopAiService: IslandflowDesktopAiService | null = null;
const PRELOAD_PATH = fileURLToPath(new URL("./preload.js", import.meta.url));
const PRELOAD_PATH = fileURLToPath(new URL("./preload.cjs", import.meta.url));
const canOpenExternalUrl = (sourceUrl: string, targetUrl: string): boolean => {
return isTrustedAppUrl(sourceUrl) && isSafeExternalUrl(targetUrl);
@ -87,6 +87,9 @@ const createMainWindow = (): BrowserWindow => {
});
installNavigationGuards(window);
window.webContents.setUserAgent(
`${window.webContents.getUserAgent()} IslandflowDesktop/${app.getVersion()} Electron/${process.versions.electron}`
);
window.once("ready-to-show", () => {
window.show();

View file

@ -0,0 +1,36 @@
const { contextBridge, ipcRenderer } = require("electron");
const DESKTOP_AI_STATE_CHANNEL = "islandflow:desktop-ai:state";
const DESKTOP_AI_GET_STATE = "islandflow:desktop-ai:get-state";
const DESKTOP_AI_LOGIN_BROWSER = "islandflow:desktop-ai:login-browser";
const DESKTOP_AI_LOGIN_DEVICE = "islandflow:desktop-ai:login-device";
const DESKTOP_AI_CANCEL_LOGIN = "islandflow:desktop-ai:cancel-login";
const DESKTOP_AI_LOGOUT = "islandflow:desktop-ai:logout";
const DESKTOP_AI_UPDATE_PREFERENCES = "islandflow:desktop-ai:update-preferences";
const DESKTOP_AI_RUN_TASK = "islandflow:desktop-ai:run-task";
const DESKTOP_AI_CANCEL_TASK = "islandflow:desktop-ai:cancel-task";
const bridge = {
ai: {
getState: () => ipcRenderer.invoke(DESKTOP_AI_GET_STATE),
loginWithBrowser: () => ipcRenderer.invoke(DESKTOP_AI_LOGIN_BROWSER),
loginWithDeviceCode: () => ipcRenderer.invoke(DESKTOP_AI_LOGIN_DEVICE),
cancelLogin: () => ipcRenderer.invoke(DESKTOP_AI_CANCEL_LOGIN),
logout: () => ipcRenderer.invoke(DESKTOP_AI_LOGOUT),
updatePreferences: (next) => ipcRenderer.invoke(DESKTOP_AI_UPDATE_PREFERENCES, next),
runTask: (request) => ipcRenderer.invoke(DESKTOP_AI_RUN_TASK, request),
cancelTask: (taskId) => ipcRenderer.invoke(DESKTOP_AI_CANCEL_TASK, taskId),
subscribe: (listener) => {
const handler = (_event, state) => {
listener(state);
};
ipcRenderer.on(DESKTOP_AI_STATE_CHANNEL, handler);
return () => {
ipcRenderer.off(DESKTOP_AI_STATE_CHANNEL, handler);
};
}
}
};
contextBridge.exposeInMainWorld("islandflowDesktop", bridge);