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

feat(desktop): glass tray popover with live 24h chart + native dashboard window

Tashfeen4077684d0ba5
diff --git a/electron-builder.yml b/electron-builder.yml
index 947b654a..fb54ffad 100644
--- a/electron-builder.yml
+++ b/electron-builder.yml
@@ -4,6 +4,7 @@ directories:
output: dist-electron
files:
- build/**/*
+ - renderer/**/*
- assets/**/*
- "!**/*.map"
asar: true
diff --git a/package.json b/package.json
index 375c582e..53d8e28e 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"scripts": {
"bundle:server": "node scripts/bundle-server.mjs",
"build:main": "esbuild src/main.ts --bundle --platform=node --format=esm --external:electron --external:./server.mjs --outfile=build/main.mjs",
- "build:preload": "esbuild src/preload.ts --bundle --platform=node --format=cjs --external:electron --outfile=build/preload.cjs",
+ "build:preload": "esbuild src/preload.ts src/preload-popover.ts --bundle --platform=node --format=cjs --external:electron --outdir=build --out-extension:.js=.cjs",
"build:all": "npm run bundle:server && npm run build:main && npm run build:preload",
"rebuild:native": "electron-rebuild -f -w better-sqlite3",
"dev": "npm run build:all && electron .",
diff --git a/renderer/popover.html b/renderer/popover.html
new file mode 100644
index 00000000..b4ea16f6
--- /dev/null
+++ b/renderer/popover.html
@@ -0,0 +1,241 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="UTF-8" />
+<style>
+ :root {
+ --fg: rgba(255, 255, 255, 0.92);
+ --fg-dim: rgba(255, 255, 255, 0.55);
+ --fg-faint: rgba(255, 255, 255, 0.32);
+ --hairline: rgba(255, 255, 255, 0.10);
+ --accent: #6aa6ff;
+ --accent-2: #8e7bff;
+ --ok: #34c759;
+ }
+ * { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }
+ html, body { background: transparent; }
+ body {
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
+ -webkit-font-smoothing: antialiased;
+ color: var(--fg);
+ padding: 8px;
+ }
+ .panel {
+ position: relative;
+ border-radius: 18px;
+ background: linear-gradient(180deg, rgba(46,46,52,0.62), rgba(28,28,32,0.66));
+ box-shadow:
+ inset 0 1px 0 rgba(255,255,255,0.14),
+ inset 0 0 0 0.5px rgba(255,255,255,0.08),
+ 0 18px 48px rgba(0,0,0,0.42);
+ overflow: hidden;
+ padding: 14px 14px 12px;
+ }
+ body.no-vibrancy .panel { background: linear-gradient(180deg, #2c2c31, #1d1d21); }
+ /* gloss sheen */
+ .panel::before {
+ content: "";
+ position: absolute; inset: 0 0 auto 0; height: 110px;
+ background: radial-gradient(120% 100% at 50% -20%, rgba(255,255,255,0.16), rgba(255,255,255,0) 70%);
+ pointer-events: none;
+ }
+
+ .head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
+ .mark {
+ width: 22px; height: 22px; border-radius: 7px; flex: none;
+ background: linear-gradient(180deg, #3a3a40, #232327);
+ box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
+ display: grid; place-items: center;
+ }
+ .mark svg { display: block; }
+ .title { font-size: 13px; font-weight: 600; letter-spacing: 0.1px; }
+ .addr { font-size: 11px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
+ .status { margin-left: auto; display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--fg-dim); }
+ .dot {
+ width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
+ box-shadow: 0 0 6px rgba(52,199,89,0.9);
+ animation: pulse 2.4s ease-in-out infinite;
+ }
+ @keyframes pulse { 50% { opacity: 0.55; } }
+
+ .stats { display: flex; gap: 8px; margin-bottom: 10px; }
+ .stat {
+ flex: 1; padding: 9px 11px 8px;
+ border-radius: 12px;
+ background: rgba(255,255,255,0.055);
+ box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.10);
+ }
+ .stat .v { font-size: 19px; font-weight: 650; letter-spacing: -0.3px; font-variant-numeric: tabular-nums; }
+ .stat .l { font-size: 10px; color: var(--fg-dim); margin-top: 1px; text-transform: uppercase; letter-spacing: 0.5px; }
+ .stat .sub { font-size: 10px; color: var(--ok); margin-top: 1px; }
+
+ .chartwrap { padding: 4px 2px 0; }
+ canvas { display: block; width: 100%; height: 64px; }
+ .axis { display: flex; justify-content: space-between; font-size: 9px; color: var(--fg-faint); padding: 3px 2px 0; }
+
+ .lastmodel {
+ display: flex; align-items: center; gap: 6px;
+ font-size: 11px; color: var(--fg-dim);
+ padding: 9px 2px 10px;
+ border-bottom: 0.5px solid var(--hairline);
+ margin-bottom: 10px;
+ }
+ .lastmodel b { color: var(--fg); font-weight: 500; max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+
+ .actions { display: flex; gap: 7px; margin-bottom: 10px; }
+ button {
+ font: inherit; color: var(--fg); border: 0; cursor: pointer;
+ border-radius: 10px; font-size: 11.5px; font-weight: 550;
+ white-space: nowrap;
+ transition: transform 0.06s ease, filter 0.15s ease;
+ }
+ button:active { transform: scale(0.97); }
+ .primary {
+ flex: 1.6; padding: 8px 8px;
+ background: linear-gradient(180deg, var(--accent), #4d86e8);
+ box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 2px 8px rgba(74,134,232,0.35);
+ }
+ .primary:hover { filter: brightness(1.07); }
+ .ghost {
+ flex: 1; padding: 8px 4px;
+ background: rgba(255,255,255,0.08);
+ box-shadow: inset 0 0.5px 0 rgba(255,255,255,0.12);
+ color: var(--fg);
+ }
+ .ghost:hover { background: rgba(255,255,255,0.13); }
+ .ghost.copied { color: var(--ok); }
+
+ .foot { display: flex; align-items: center; font-size: 11.5px; color: var(--fg-dim); }
+ .switch {
+ position: relative; width: 30px; height: 18px; border-radius: 9px;
+ background: rgba(255,255,255,0.16); margin-right: 7px; flex: none;
+ transition: background 0.18s ease; cursor: pointer;
+ box-shadow: inset 0 1px 2px rgba(0,0,0,0.25);
+ }
+ .switch::after {
+ content: ""; position: absolute; top: 2px; left: 2px;
+ width: 14px; height: 14px; border-radius: 50%;
+ background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.3);
+ transition: left 0.18s ease;
+ }
+ .switch.on { background: var(--ok); }
+ .switch.on::after { left: 14px; }
+ .quit {
+ margin-left: auto; background: none; color: var(--fg-dim);
+ font-size: 11.5px; padding: 4px 6px; border-radius: 7px;
+ }
+ .quit:hover { background: rgba(255,255,255,0.08); color: var(--fg); }
+</style>
+</head>
+<body>
+ <div class="panel">
+ <div class="head">
+ <div class="mark">
+ <svg width="13" height="13" viewBox="0 0 64 64">
+ <circle cx="32" cy="32" r="11" fill="#fafafa"/>
+ <circle cx="32" cy="32" r="22" fill="none" stroke="#fafafa" stroke-opacity=".45"
+ stroke-width="6" stroke-linecap="round" stroke-dasharray="104 34"
+ transform="rotate(-60 32 32)"/>
+ </svg>
+ </div>
+ <div>
+ <div class="title">FreeLLMAPI</div>
+ <div class="addr" id="addr">127.0.0.1:…</div>
+ </div>
+ <div class="status"><span class="dot"></span>running</div>
+ </div>
+
+ <div class="stats">
+ <div class="stat">
+ <div class="v" id="reqs">0</div>
+ <div class="l">Requests today</div>
+ <div class="sub" id="rate"></div>
+ </div>
+ <div class="stat">
+ <div class="v" id="tokens">0</div>
+ <div class="l">Tokens today</div>
+ </div>
+ </div>
+
+ <div class="chartwrap">
+ <canvas id="chart" width="0" height="0"></canvas>
+ <div class="axis"><span>24h ago</span><span id="peak"></span><span>now</span></div>
+ </div>
+
+ <div class="lastmodel">Last model <b id="model">—</b></div>
+
+ <div class="actions">
+ <button class="primary" id="open">Open Dashboard</button>
+ <button class="ghost" id="copyurl">Copy URL</button>
+ <button class="ghost" id="copykey">Copy Key</button>
+ </div>
+
+ <div class="foot">
+ <div class="switch" id="login"></div>
+ <span>Start at login</span>
+ <button class="quit" id="quit">Quit</button>
+ </div>
+ </div>
+
+<script>
+ const $ = (id) => document.getElementById(id);
+ const fmt = (n) => n >= 1e6 ? (n / 1e6).toFixed(1) + 'M' : n >= 1e3 ? (n / 1e3).toFixed(1) + 'k' : String(n);
+
+ function drawChart(hourly) {
+ const c = $('chart');
+ const cssW = c.clientWidth, cssH = 64, dpr = window.devicePixelRatio || 2;
+ c.width = cssW * dpr; c.height = cssH * dpr;
+ const ctx = c.getContext('2d');
+ ctx.scale(dpr, dpr);
+ const n = hourly.length, gap = 3;
+ const bw = (cssW - gap * (n - 1)) / n;
+ const max = Math.max(...hourly, 1);
+ const grad = ctx.createLinearGradient(0, 0, 0, cssH);
+ grad.addColorStop(0, 'rgba(142,123,255,0.95)');
+ grad.addColorStop(1, 'rgba(106,166,255,0.55)');
+ for (let i = 0; i < n; i++) {
+ const v = hourly[i];
+ const h = v === 0 ? 2 : Math.max(3, (v / max) * (cssH - 6));
+ const x = i * (bw + gap), y = cssH - h;
+ ctx.fillStyle = v === 0 ? 'rgba(255,255,255,0.10)' : grad;
+ ctx.beginPath();
+ ctx.roundRect(x, y, bw, h, Math.min(3, bw / 2));
+ ctx.fill();
+ }
+ $('peak').textContent = max > 1 ? 'peak ' + max + '/h' : '';
+ }
+
+ let loginOn = false;
+ async function refresh() {
+ const s = await window.freeapi.snapshot();
+ $('addr').textContent = '127.0.0.1:' + s.port;
+ $('reqs').textContent = fmt(s.requests);
+ $('tokens').textContent = fmt(s.tokens);
+ $('rate').textContent = s.successRate == null ? '' : s.successRate + '% success';
+ $('model').textContent = s.lastModel;
+ loginOn = s.loginItem;
+ $('login').classList.toggle('on', loginOn);
+ drawChart(s.hourly);
+ }
+
+ function flash(btn, label) {
+ const orig = btn.textContent;
+ btn.textContent = label; btn.classList.add('copied');
+ setTimeout(() => { btn.textContent = orig; btn.classList.remove('copied'); }, 1100);
+ }
+
+ $('open').addEventListener('click', () => window.freeapi.openDashboard());
+ $('copyurl').addEventListener('click', (e) => { window.freeapi.copyBaseUrl(); flash(e.target, 'Copied ✓'); });
+ $('copykey').addEventListener('click', (e) => { window.freeapi.copyApiKey(); flash(e.target, 'Copied ✓'); });
+ $('quit').addEventListener('click', () => window.freeapi.quit());
+ $('login').addEventListener('click', () => {
+ loginOn = !loginOn;
+ $('login').classList.toggle('on', loginOn);
+ window.freeapi.setLoginItem(loginOn);
+ });
+
+ window.freeapi.onRefresh(refresh);
+ refresh();
+</script>
+</body>
+</html>
diff --git a/src/main.ts b/src/main.ts
index e2593177..ca3c9ec6 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,10 +1,11 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
-import { app, dialog } from 'electron';
-import { startServer, ensureSessionToken } from './server.mjs';
+import { app, dialog, ipcMain, clipboard } from 'electron';
+import { startServer, ensureSessionToken, getUnifiedApiKey } from './server.mjs';
import { loadConfig, saveConfig } from './config.js';
import { buildTray } from './tray.js';
import { openDashboard } from './window.js';
+import { todayStats, hourlyRequests, successRateToday } from './stats.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const DEFAULT_PORT = 31415;
@@ -27,6 +28,25 @@ if (!app.requestSingleInstanceLock()) {
// The app lives in the tray; closing the dashboard window must not quit.
app.on('window-all-closed', () => {});
+ // ── popover IPC ──────────────────────────────────────────────────────────
+ ipcMain.handle('freeapi:snapshot', () => {
+ const s = todayStats();
+ return {
+ port: resolvedPort,
+ requests: s.requests,
+ tokens: s.tokens,
+ lastModel: s.lastModel,
+ successRate: successRateToday(),
+ hourly: hourlyRequests(),
+ loginItem: app.getLoginItemSettings().openAtLogin,
+ };
+ });
+ ipcMain.handle('freeapi:open-dashboard', () => openDashboard(resolvedPort, sessionToken));
+ ipcMain.handle('freeapi:copy-base-url', () => clipboard.writeText(`http://127.0.0.1:${resolvedPort}/v1`));
+ ipcMain.handle('freeapi:copy-api-key', () => clipboard.writeText(getUnifiedApiKey()));
+ ipcMain.handle('freeapi:set-login-item', (_e, open: boolean) => app.setLoginItemSettings({ openAtLogin: open }));
+ ipcMain.handle('freeapi:quit', () => app.quit());
+
app.whenReady().then(async () => {
if (process.platform === 'darwin') app.dock?.hide();
@@ -48,8 +68,27 @@ if (!app.requestSingleInstanceLock()) {
resolvedPort = port;
saveConfig({ ...cfg, port });
sessionToken = ensureSessionToken();
- buildTray(port, sessionToken);
+ const tray = buildTray(port, sessionToken);
console.log(`[desktop] FreeLLMAPI running on http://127.0.0.1:${port}`);
+
+ // Dev-only UI verification: FREEAPI_SHOT=1 opens the popover and the
+ // dashboard, captures both to /tmp, and quits. Never set when packaged.
+ if (process.env.FREEAPI_SHOT && !app.isPackaged) {
+ const fs = await import('node:fs');
+ const { togglePopover, getPopoverWindow } = await import('./popover.js');
+ const { getDashboardWindow } = await import('./window.js');
+ const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
+ await sleep(800);
+ togglePopover(tray);
+ await sleep(1500);
+ const pop = await getPopoverWindow()?.webContents.capturePage();
+ if (pop) fs.writeFileSync('/tmp/freeapi-popover.png', pop.toPNG());
+ openDashboard(port, sessionToken);
+ await sleep(3000);
+ const dash = await getDashboardWindow()?.webContents.capturePage();
+ if (dash) fs.writeFileSync('/tmp/freeapi-dashboard.png', dash.toPNG());
+ app.quit();
+ }
} catch (err: any) {
dialog.showErrorBox(
'FreeLLMAPI failed to start',
diff --git a/src/popover.ts b/src/popover.ts
new file mode 100644
index 00000000..1d6201c1
--- /dev/null
+++ b/src/popover.ts
@@ -0,0 +1,79 @@
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { BrowserWindow, type Tray } from 'electron';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+
+const WIDTH = 332;
+const HEIGHT = 356;
+
+let popover: BrowserWindow | null = null;
+
+// A Control-Center-style glass panel anchored under the tray icon. Created
+// once, then shown/hidden — cheap to keep around (one small renderer) and
+// instant to open. Hides on blur like a real menu.
+function createPopover(): BrowserWindow {
+ const win = new BrowserWindow({
+ width: WIDTH,
+ height: HEIGHT,
+ show: false,
+ frame: false,
+ transparent: true,
+ resizable: false,
+ movable: false,
+ minimizable: false,
+ maximizable: false,
+ fullscreenable: false,
+ skipTaskbar: true,
+ alwaysOnTop: true,
+ hasShadow: false, // the panel draws its own soft shadow (transparent margins)
+ ...(process.platform === 'darwin'
+ ? { vibrancy: 'popover' as const, visualEffectState: 'active' as const }
+ : {}),
+ webPreferences: {
+ preload: path.join(__dirname, 'preload-popover.cjs'),
+ contextIsolation: true,
+ sandbox: false,
+ nodeIntegration: false,
+ },
+ });
+
+ // Show over fullscreen apps, like every menu bar utility.
+ win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
+
+ win.loadFile(path.join(__dirname, '../renderer/popover.html')).then(() => {
+ if (process.platform !== 'darwin') {
+ win.webContents.executeJavaScript("document.body.classList.add('no-vibrancy')");
+ }
+ });
+
+ win.on('blur', () => win.hide());
+ win.on('closed', () => {
+ popover = null;
+ });
+ return win;
+}
+
+export function getPopoverWindow(): BrowserWindow | null {
+ return popover;
+}
+
+export function togglePopover(tray: Tray): void {
+ if (!popover || popover.isDestroyed()) popover = createPopover();
+
+ if (popover.isVisible()) {
+ popover.hide();
+ return;
+ }
+
+ const b = tray.getBounds();
+ // Centered under the icon; tray bounds are in screen coordinates.
+ const x = Math.round(b.x + b.width / 2 - WIDTH / 2);
+ const y = process.platform === 'darwin'
+ ? Math.round(b.y + b.height + 4)
+ : Math.round(b.y - HEIGHT - 4); // Windows tray sits at the bottom
+ popover.setPosition(x, y, false);
+ popover.webContents.send('freeapi:refresh');
+ popover.show();
+ popover.focus();
+}
diff --git a/src/preload-popover.ts b/src/preload-popover.ts
new file mode 100644
index 00000000..7151c72a
--- /dev/null
+++ b/src/preload-popover.ts
@@ -0,0 +1,13 @@
+// Built to build/preload-popover.cjs. Exposes the minimal IPC surface the
+// popover UI needs — no Node access in the renderer.
+import { contextBridge, ipcRenderer } from 'electron';
+
+contextBridge.exposeInMainWorld('freeapi', {
+ snapshot: () => ipcRenderer.invoke('freeapi:snapshot'),
+ openDashboard: () => ipcRenderer.invoke('freeapi:open-dashboard'),
+ copyBaseUrl: () => ipcRenderer.invoke('freeapi:copy-base-url'),
+ copyApiKey: () => ipcRenderer.invoke('freeapi:copy-api-key'),
+ setLoginItem: (open: boolean) => ipcRenderer.invoke('freeapi:set-login-item', open),
+ quit: () => ipcRenderer.invoke('freeapi:quit'),
+ onRefresh: (cb: () => void) => ipcRenderer.on('freeapi:refresh', cb),
+});
diff --git a/src/preload.ts b/src/preload.ts
index f96fa4a8..1d858b4f 100644
--- a/src/preload.ts
+++ b/src/preload.ts
@@ -3,6 +3,8 @@
// token into localStorage so AuthGate's very first /api/auth/status call is
// authenticated. The token arrives via additionalArguments (process.argv),
// which avoids templating strings into executeJavaScript.
+import { contextBridge } from 'electron';
+
const TOKEN_KEY = 'freellmapi_dashboard_token';
const arg = process.argv.find((a) => a.startsWith('--freeapi-token='));
if (arg) {
@@ -12,3 +14,7 @@ if (arg) {
// localStorage unavailable — the dashboard will show its login screen.
}
}
+
+// Lets the client adapt its chrome (drag region, traffic-light padding,
+// no Sign out) when running inside the desktop shell.
+contextBridge.exposeInMainWorld('__FREEAPI_DESKTOP__', true);
diff --git a/src/stats.ts b/src/stats.ts
index 3ef95f6e..a7263f1c 100644
--- a/src/stats.ts
+++ b/src/stats.ts
@@ -33,3 +33,39 @@ export function formatTokens(n: number): string {
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`;
return String(n);
}
+
+// 24 hourly buckets, oldest → newest, for the popover chart. created_at is
+// UTC "YYYY-MM-DD HH:MM:SS" text — parse with an explicit Z.
+export function hourlyRequests(): number[] {
+ const buckets = new Array<number>(24).fill(0);
+ try {
+ const rows = getDb().prepare(
+ "SELECT created_at FROM requests WHERE created_at >= datetime('now', '-24 hours')",
+ ).all() as { created_at: string }[];
+ const now = Date.now();
+ for (const r of rows) {
+ const t = Date.parse(r.created_at.replace(' ', 'T') + 'Z');
+ if (Number.isNaN(t)) continue;
+ const hoursAgo = Math.floor((now - t) / 3_600_000);
+ if (hoursAgo >= 0 && hoursAgo < 24) buckets[23 - hoursAgo]++;
+ }
+ } catch {
+ // fresh DB / no requests table content — all zeros is fine
+ }
+ return buckets;
+}
+
+export function successRateToday(): number | null {
+ try {
+ const row = getDb().prepare(`
+ SELECT COUNT(*) AS total,
+ SUM(CASE WHEN status = 'success' THEN 1 ELSE 0 END) AS ok
+ FROM requests
+ WHERE datetime(created_at, 'localtime') >= datetime('now', 'localtime', 'start of day')
+ `).get() as { total: number; ok: number };
+ if (!row.total) return null;
+ return Math.round((row.ok / row.total) * 100);
+ } catch {
+ return null;
+ }
+}
diff --git a/src/tray.ts b/src/tray.ts
index b056f512..97d8268f 100644
--- a/src/tray.ts
+++ b/src/tray.ts
@@ -1,16 +1,15 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
-import { Tray, Menu, app, clipboard, nativeImage } from 'electron';
-import { todayStats, formatTokens } from './stats.js';
+import { Tray, Menu, app, nativeImage } from 'electron';
+import { togglePopover } from './popover.js';
import { openDashboard } from './window.js';
-import { getUnifiedApiKey } from './server.mjs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
let tray: Tray | null = null;
-// The menu is rebuilt on every open (popUpContextMenu instead of a static
-// setContextMenu) so the stats lines are always fresh — no polling timer.
+// Left-click opens the glass popover; right-click keeps a minimal native
+// menu as an escape hatch (quit even if the popover renderer breaks).
export function buildTray(port: number, token: string): Tray {
const iconPath = path.join(__dirname, '../assets/trayTemplate.png');
const icon = nativeImage.createFromPath(iconPath);
@@ -19,32 +18,15 @@ export function buildTray(port: number, token: string): Tray {
tray = new Tray(icon);
tray.setToolTip('FreeLLMAPI — local LLM router');
- const show = () => tray!.popUpContextMenu(buildMenu(port, token));
- tray.on('click', show);
- tray.on('right-click', show);
+ tray.on('click', () => togglePopover(tray!));
+ tray.on('right-click', () => {
+ tray!.popUpContextMenu(Menu.buildFromTemplate([
+ { label: `Running on 127.0.0.1:${port}`, enabled: false },
+ { label: 'Open Dashboard', click: () => openDashboard(port, token) },
+ { type: 'separator' },
+ { label: 'Quit FreeLLMAPI', click: () => app.quit() },
+ ]));
+ });
return tray;
}
-
-function buildMenu(port: number, token: string): Menu {
- const s = todayStats();
- return Menu.buildFromTemplate([
- { label: `Running on 127.0.0.1:${port}`, enabled: false },
- { type: 'separator' },
- { label: `Requests today: ${s.requests}`, enabled: false },
- { label: `Tokens today: ${formatTokens(s.tokens)}`, enabled: false },
- { label: `Last model: ${s.lastModel}`, enabled: false },
- { type: 'separator' },
- { label: 'Open Dashboard', accelerator: 'CmdOrCtrl+D', click: () => openDashboard(port, token) },
- { label: 'Copy API Base URL', click: () => clipboard.writeText(`http://127.0.0.1:${port}/v1`) },
- { label: 'Copy API Key', click: () => clipboard.writeText(getUnifiedApiKey()) },
- { type: 'separator' },
- {
- label: 'Start at Login',
- type: 'checkbox',
- checked: app.getLoginItemSettings().openAtLogin,
- click: (item) => app.setLoginItemSettings({ openAtLogin: item.checked }),
- },
- { label: 'Quit FreeLLMAPI', accelerator: 'CmdOrCtrl+Q', click: () => app.quit() },
- ]);
-}
diff --git a/src/window.ts b/src/window.ts
index 8d8ebed0..b63b41bc 100644
--- a/src/window.ts
+++ b/src/window.ts
@@ -6,6 +6,10 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
let dashboardWindow: BrowserWindow | null = null;
+export function getDashboardWindow(): BrowserWindow | null {
+ return dashboardWindow;
+}
+
// One window at a time, destroyed on close — the app lives in the tray, the
// window is an on-demand view. The session token rides in via
// additionalArguments so the CJS preload can seed localStorage before any
@@ -23,6 +27,12 @@ export function openDashboard(port: number, token: string): void {
minWidth: 720,
minHeight: 480,
title: 'FreeLLMAPI',
+ // Native feel: traffic lights float over the app's own header (the client
+ // adds a drag region + left padding when it detects the desktop shell).
+ ...(process.platform === 'darwin'
+ ? { titleBarStyle: 'hiddenInset' as const }
+ : {}),
+ backgroundColor: '#09090b',
webPreferences: {
preload: path.join(__dirname, 'preload.cjs'),
contextIsolation: true,