fix: more work on menus

This commit is contained in:
2026-02-17 11:25:50 +01:00
parent 7b5829e965
commit 70bc0b1b09
7 changed files with 442 additions and 33 deletions

View File

@@ -1,4 +1,4 @@
import { ipcMain, dialog, shell } from 'electron';
import { app, ipcMain, dialog, shell } from 'electron';
import * as path from 'path';
import * as fsPromises from 'fs/promises';
import { eq } from 'drizzle-orm';
@@ -715,6 +715,22 @@ export function registerIpcHandlers(): void {
safeHandle('app:triggerMenuAction', async (event, action: string) => {
const typedAction = action as AppMenuAction;
if (typedAction === 'quit') {
app.quit();
return;
}
if (typedAction === 'viewOnGitHub') {
await shell.openExternal('https://github.com/rfc1437/bDS');
return;
}
if (typedAction === 'reportIssue') {
await shell.openExternal('https://github.com/rfc1437/bDS/issues');
return;
}
const handledByWebContents = runWebContentsMenuAction((event as any)?.sender, typedAction);
if (handledByWebContents) {
return;

View File

@@ -179,6 +179,21 @@ function createApplicationMenu(): Menu {
}, {});
const triggerMenuAction = (action: AppMenuAction): void => {
if (action === 'quit') {
app.quit();
return;
}
if (action === 'viewOnGitHub') {
void shell.openExternal('https://github.com/rfc1437/bDS');
return;
}
if (action === 'reportIssue') {
void shell.openExternal('https://github.com/rfc1437/bDS/issues');
return;
}
const channel = APP_MENU_ACTION_EVENT_MAP[action];
if (channel) {
mainWindow?.webContents.send(channel);
@@ -251,13 +266,7 @@ function createApplicationMenu(): Menu {
},
},
{ type: 'separator' },
{
label: 'Exit',
accelerator: process.platform === 'darwin' ? 'Cmd+Q' : 'Alt+F4',
click: () => {
app.quit();
},
},
buildSharedMenuItem('quit'),
],
},
{
@@ -313,22 +322,7 @@ function createApplicationMenu(): Menu {
},
{
label: 'Help',
submenu: [
buildSharedMenuItem('about'),
{ type: 'separator' },
{
label: 'View on GitHub',
click: async () => {
await shell.openExternal('https://github.com/rfc1437/bDS');
},
},
{
label: 'Report Issue',
click: async () => {
await shell.openExternal('https://github.com/rfc1437/bDS/issues');
},
},
],
submenu: buildSharedGroupMenuItems('Help'),
},
];

View File

@@ -2,6 +2,7 @@ export type AppMenuAction =
| 'newPost'
| 'importMedia'
| 'save'
| 'quit'
| 'undo'
| 'redo'
| 'cut'
@@ -20,7 +21,9 @@ export type AppMenuAction =
| 'rebuildDatabase'
| 'reindexText'
| 'metadataDiff'
| 'about';
| 'about'
| 'viewOnGitHub'
| 'reportIssue';
export type AppMenuRole = 'undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'delete' | 'selectAll';
@@ -44,6 +47,8 @@ export const APP_MENU_GROUPS: AppMenuGroupDefinition[] = [
{ label: 'New Post', action: 'newPost', accelerator: 'CmdOrCtrl+N' },
{ label: 'Import Media...', action: 'importMedia', accelerator: 'CmdOrCtrl+I' },
{ label: 'Save', action: 'save', accelerator: 'CmdOrCtrl+S' },
{ label: '', action: 'file-separator-1', separator: true },
{ label: 'Quit', action: 'quit', accelerator: 'CmdOrCtrl+Q' },
],
},
{
@@ -86,6 +91,9 @@ export const APP_MENU_GROUPS: AppMenuGroupDefinition[] = [
label: 'Help',
items: [
{ label: 'About Blogging Desktop Server', action: 'about' },
{ label: '', action: 'help-separator-1', separator: true },
{ label: 'View on GitHub', action: 'viewOnGitHub' },
{ label: 'Report Issue', action: 'reportIssue' },
],
},
];