mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-04 22:02:16 +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
|
|
@ -5,7 +5,9 @@ import { createMainWindow } from './modules/window';
|
||||||
import { setupDeepLinks, handlePendingDeepLink } from './modules/deep-links';
|
import { setupDeepLinks, handlePendingDeepLink } from './modules/deep-links';
|
||||||
import { setupAutoUpdater } from './modules/auto-updater';
|
import { setupAutoUpdater } from './modules/auto-updater';
|
||||||
import { setupMenu } from './modules/menu';
|
import { setupMenu } from './modules/menu';
|
||||||
|
import { setupTray } from './modules/tray';
|
||||||
import { registerIpcHandlers } from './ipc/handlers';
|
import { registerIpcHandlers } from './ipc/handlers';
|
||||||
|
import { registerClipboardHandlers } from './modules/clipboard';
|
||||||
|
|
||||||
registerGlobalErrorHandlers();
|
registerGlobalErrorHandlers();
|
||||||
|
|
||||||
|
|
@ -14,6 +16,7 @@ if (!setupDeepLinks()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
registerIpcHandlers();
|
registerIpcHandlers();
|
||||||
|
registerClipboardHandlers();
|
||||||
|
|
||||||
// App lifecycle
|
// App lifecycle
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
|
|
@ -26,6 +29,7 @@ app.whenReady().then(async () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
createMainWindow();
|
createMainWindow();
|
||||||
|
setupTray();
|
||||||
setupAutoUpdater();
|
setupAutoUpdater();
|
||||||
|
|
||||||
handlePendingDeepLink();
|
handlePendingDeepLink();
|
||||||
|
|
|
||||||
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