mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 01:36:30 +02:00
feat(desktop): add system tray with clipboard-to-chat support
This commit is contained in:
parent
ecdd7354e9
commit
275fa86ecd
3 changed files with 91 additions and 0 deletions
14
surfsense_desktop/src/modules/clipboard.ts
Normal file
14
surfsense_desktop/src/modules/clipboard.ts
Normal 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;
|
||||
});
|
||||
}
|
||||
73
surfsense_desktop/src/modules/tray.ts
Normal file
73
surfsense_desktop/src/modules/tray.ts
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue