mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-31 19:45:15 +02:00
feat(tray): refactor context menu creation for improved screenshot functionality and quit option
This commit is contained in:
parent
7276210403
commit
baba31ab43
1 changed files with 27 additions and 14 deletions
|
|
@ -10,6 +10,30 @@ let tray: Tray | null = null;
|
||||||
let registeredGeneralAssist: string | null = null;
|
let registeredGeneralAssist: string | null = null;
|
||||||
let registeredScreenshotAssist: string | null = null;
|
let registeredScreenshotAssist: string | null = null;
|
||||||
|
|
||||||
|
function buildContextMenu(screenshotAccelerator: string): Menu {
|
||||||
|
return Menu.buildFromTemplate([
|
||||||
|
{ label: 'Open SurfSense', click: () => showMainWindow('tray_menu') },
|
||||||
|
{
|
||||||
|
label: 'Take Screenshot\u2026',
|
||||||
|
accelerator: screenshotAccelerator || undefined,
|
||||||
|
click: () => {
|
||||||
|
trackEvent('desktop_tray_screenshot_clicked');
|
||||||
|
void Promise.resolve(runScreenshotAssistShortcut()).catch((err) => {
|
||||||
|
console.error('[tray] Screenshot Assist failed:', err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: 'Quit',
|
||||||
|
click: () => {
|
||||||
|
trackEvent('desktop_tray_quit_clicked');
|
||||||
|
app.exit(0);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
function getTrayIcon(): NativeImage {
|
function getTrayIcon(): NativeImage {
|
||||||
const iconName =
|
const iconName =
|
||||||
process.platform === 'darwin'
|
process.platform === 'darwin'
|
||||||
|
|
@ -59,22 +83,10 @@ export async function createTray(): Promise<void> {
|
||||||
tray = new Tray(getTrayIcon());
|
tray = new Tray(getTrayIcon());
|
||||||
tray.setToolTip('SurfSense');
|
tray.setToolTip('SurfSense');
|
||||||
|
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
const shortcuts = await getShortcuts();
|
||||||
{ label: 'Open SurfSense', click: () => showMainWindow('tray_menu') },
|
tray.setContextMenu(buildContextMenu(shortcuts.screenshotAssist));
|
||||||
{ type: 'separator' },
|
|
||||||
{
|
|
||||||
label: 'Quit',
|
|
||||||
click: () => {
|
|
||||||
trackEvent('desktop_tray_quit_clicked');
|
|
||||||
app.exit(0);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
tray.setContextMenu(contextMenu);
|
|
||||||
tray.on('double-click', () => showMainWindow('tray_click'));
|
tray.on('double-click', () => showMainWindow('tray_click'));
|
||||||
|
|
||||||
const shortcuts = await getShortcuts();
|
|
||||||
registeredGeneralAssist = registerOne(
|
registeredGeneralAssist = registerOne(
|
||||||
null,
|
null,
|
||||||
shortcuts.generalAssist,
|
shortcuts.generalAssist,
|
||||||
|
|
@ -107,6 +119,7 @@ export async function reregisterScreenshotAssist(): Promise<void> {
|
||||||
runScreenshotAssistShortcut,
|
runScreenshotAssistShortcut,
|
||||||
'Screenshot Assist'
|
'Screenshot Assist'
|
||||||
);
|
);
|
||||||
|
tray?.setContextMenu(buildContextMenu(shortcuts.screenshotAssist));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function destroyTray(): void {
|
export function destroyTray(): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue