feat(desktop): add system tray with clipboard-to-chat support

This commit is contained in:
CREDO23 2026-03-20 20:22:37 +02:00
parent ecdd7354e9
commit 275fa86ecd
3 changed files with 91 additions and 0 deletions

View file

@ -0,0 +1,14 @@
import { ipcMain } from 'electron';
import { IPC_CHANNELS } from '../ipc/channels';
let lastClipboardContent = '';
export function setClipboardContent(text: string): void {
lastClipboardContent = text;
}
export function registerClipboardHandlers(): void {
ipcMain.handle(IPC_CHANNELS.GET_CLIPBOARD_CONTENT, () => {
return lastClipboardContent;
});
}

View file

@ -0,0 +1,73 @@
import { app, BrowserWindow, clipboard, Menu, Tray } from 'electron';
import path from 'path';
import { getServerPort } from './server';
import { setClipboardContent } from './clipboard';
let tray: Tray | null = null;
let clipWindow: BrowserWindow | null = null;
function getIconPath(): string {
if (app.isPackaged) {
return path.join(process.resourcesPath, 'icon.png');
}
return path.join(__dirname, '..', 'assets', 'icon.png');
}
function createClipWindow(): BrowserWindow {
if (clipWindow && !clipWindow.isDestroyed()) {
clipWindow.focus();
return clipWindow;
}
clipWindow = new BrowserWindow({
width: 420,
height: 620,
resizable: true,
minimizable: false,
maximizable: false,
fullscreenable: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
},
show: false,
titleBarStyle: 'hiddenInset',
});
clipWindow.loadURL(`http://localhost:${getServerPort()}/dashboard`);
clipWindow.once('ready-to-show', () => {
clipWindow?.show();
});
clipWindow.on('closed', () => {
clipWindow = null;
});
return clipWindow;
}
export function setupTray(): void {
tray = new Tray(getIconPath());
tray.setToolTip('SurfSense');
const contextMenu = Menu.buildFromTemplate([
{
label: 'Ask about clipboard',
click: () => {
const text = clipboard.readText();
setClipboardContent(text);
createClipWindow();
},
},
{ type: 'separator' },
{
label: 'Quit',
click: () => app.quit(),
},
]);
tray.setContextMenu(contextMenu);
}