Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(desktop): open external links in the system browser (#304)

Tashfeen0ef43f9d3ad1
diff --git a/README.md b/README.md
index 815fbec5..752a1c5f 100644
--- a/README.md
+++ b/README.md
@@ -558,6 +558,7 @@ PRs should include a test, keep the existing test suite green, and match the `.e
<a href="https://github.com/immanuelsavio"><img src="https://images.weserv.nl/?url=github.com/immanuelsavio.png&w=60&h=60&fit=cover&mask=circle" width="60" alt="@immanuelsavio" /></a>
<a href="https://github.com/Slyker"><img src="https://images.weserv.nl/?url=github.com/Slyker.png&w=60&h=60&fit=cover&mask=circle" width="60" alt="@Slyker" /></a>
<a href="https://github.com/wells1013"><img src="https://images.weserv.nl/?url=github.com/wells1013.png&w=60&h=60&fit=cover&mask=circle" width="60" alt="@wells1013" /></a>
+<a href="https://github.com/evgkrsk"><img src="https://images.weserv.nl/?url=github.com/evgkrsk.png&w=60&h=60&fit=cover&mask=circle" width="60" alt="@evgkrsk" /></a>
<a href="https://github.com/aaronjmars"><img src="https://images.weserv.nl/?url=github.com/aaronjmars.png&w=60&h=60&fit=cover&mask=circle" width="60" alt="@aaronjmars" /></a>
<a href="https://github.com/Robs87"><img src="https://images.weserv.nl/?url=github.com/Robs87.png&w=60&h=60&fit=cover&mask=circle" width="60" alt="@Robs87" /></a>
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index 34d8c046..8ba97767 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -1,6 +1,6 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
-import { app, dialog, ipcMain, clipboard, nativeTheme } from 'electron';
+import { app, dialog, ipcMain, clipboard, nativeTheme, shell } from 'electron';
import { startServer, ensureSessionToken, getUnifiedApiKey } from './server.mjs';
import { loadConfig, saveConfig } from './config.js';
import { buildTray } from './tray.js';
@@ -38,6 +38,33 @@ if (!app.requestSingleInstanceLock()) {
// The app lives in the tray; closing the dashboard window must not quit.
app.on('window-all-closed', () => {});
+ // Every window is a view onto the local dashboard, so anything that isn't
+ // the local server belongs in the system browser. Without a window-open
+ // handler, target="_blank" links (e.g. "Get API key" on the Keys page)
+ // spawn a bare child window that inherits our preload and renders blank
+ // (#304) — deny the window and hand the URL to the OS instead. Only
+ // http(s) ever reaches openExternal.
+ const isExternal = (url: string) => {
+ try {
+ const u = new URL(url);
+ return (u.protocol === 'http:' || u.protocol === 'https:') && u.hostname !== '127.0.0.1';
+ } catch {
+ return false;
+ }
+ };
+ app.on('web-contents-created', (_event, contents) => {
+ contents.setWindowOpenHandler(({ url }) => {
+ if (isExternal(url)) shell.openExternal(url);
+ return { action: 'deny' };
+ });
+ contents.on('will-navigate', (event, url) => {
+ if (isExternal(url)) {
+ event.preventDefault();
+ shell.openExternal(url);
+ }
+ });
+ });
+
// ── popover IPC ──────────────────────────────────────────────────────────
ipcMain.handle('freeapi:snapshot', () => {
const s = todayStats();