| 311 | } |
| 312 | |
| 313 | function createMainWindow() { |
| 314 | mainWin = new BrowserWindow({ |
| 315 | width: 1440, |
| 316 | height: 900, |
| 317 | minWidth: 800, |
| 318 | minHeight: 600, |
| 319 | show: false, |
| 320 | // App-shell background (--oh-background in src/index.css) — avoids white |
| 321 | // flashes during the show → maximize repaint after the splash closes. |
| 322 | backgroundColor: "#0b0e14", |
| 323 | titleBarStyle: process.platform === "darwin" ? "hiddenInset" : "default", |
| 324 | icon: appIconPath, |
| 325 | webPreferences: { |
| 326 | nodeIntegration: false, |
| 327 | contextIsolation: true, |
| 328 | }, |
| 329 | }); |
| 330 | |
| 331 | mainWin.loadURL("http://localhost:8000"); |
| 332 | |
| 333 | mainWin.once("ready-to-show", () => { |
| 334 | loadingWin?.destroy(); |
| 335 | loadingWin = null; |
| 336 | mainWin?.show(); |
| 337 | mainWin?.maximize(); |
| 338 | }); |
| 339 | |
| 340 | // Route window.open() calls appropriately. |
| 341 | mainWin.webContents.setWindowOpenHandler(({ url }) => { |
| 342 | // The "Login with OpenHands Cloud" device-flow opens about:blank immediately |
| 343 | // on the user's click (to beat popup blockers), then navigates the popup to |
| 344 | // the OAuth verification URL once it has one. We must allow about:blank |
| 345 | // through so window.open() returns a non-null WindowProxy; the did-create-window |
| 346 | // handler below redirects the popup to the system browser when it navigates. |
| 347 | if (url === "about:blank") { |
| 348 | return { |
| 349 | action: "allow", |
| 350 | overrideBrowserWindowOptions: { width: 800, height: 700 }, |
| 351 | }; |
| 352 | } |
| 353 | // All other external URLs open directly in the system browser. |
| 354 | if ( |
| 355 | !url.startsWith("http://localhost") && |
| 356 | !url.startsWith("http://127.0.0.1") |
| 357 | ) { |
| 358 | shell.openExternal(url); |
| 359 | return { action: "deny" }; |
| 360 | } |
| 361 | return { action: "allow" }; |
| 362 | }); |
| 363 | |
| 364 | // When the renderer opens a popup (the about:blank above), watch for its |
| 365 | // first navigation away from about:blank. That navigation will be to the |
| 366 | // OAuth verification URL — open it in the system browser and close the |
| 367 | // now-unneeded Electron popup. |
| 368 | mainWin.webContents.on("did-create-window", (popupWin) => { |
| 369 | popupWin.webContents.on("will-navigate", (_event, url) => { |
| 370 | if ( |