feat: use mac main menu (#366)

This commit is contained in:
Max Novich
2024-11-27 21:56:39 -08:00
committed by GitHub
parent 32b47712df
commit e951c6f832
2 changed files with 26 additions and 3 deletions
+6 -1
View File
@@ -215,13 +215,18 @@ function ChatContent({
}
export default function ChatWindow() {
// Shared function to create a chat window
const openNewChatWindow = () => {
window.electron.createChatWindow();
};
// Add keyboard shortcut handler
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
// Check for Command+N (Mac) or Control+N (Windows/Linux)
if ((event.metaKey || event.ctrlKey) && event.key === 'n') {
event.preventDefault(); // Prevent default browser behavior
window.electron.createChatWindow();
openNewChatWindow();
}
};
+20 -2
View File
@@ -1,6 +1,6 @@
import 'dotenv/config';
import { loadZshEnv } from './utils/loadEnv';
import { app, BrowserWindow, Tray, Menu, globalShortcut, ipcMain, Notification } from 'electron';
import { app, BrowserWindow, Tray, Menu, globalShortcut, ipcMain, Notification, MenuItem } from 'electron';
import path from 'node:path';
import { findAvailablePort, startGoosed } from './goosed';
import started from "electron-squirrel-startup";
@@ -208,6 +208,23 @@ app.whenReady().then(async () => {
// Show launcher input on key combo
globalShortcut.register('Control+Alt+Command+G', createLauncher);
// Preserve existing menu and add new items
const menu = Menu.getApplicationMenu();
const fileMenu = menu?.items.find(item => item.label === 'File');
// Add 'New Chat Window' to File menu
if (fileMenu && fileMenu.submenu) {
fileMenu.submenu.append(new MenuItem({
label: 'New Chat Window',
accelerator: 'CmdOrCtrl+N',
click() {
ipcMain.emit('create-chat-window');
},
}));
}
Menu.setApplicationMenu(menu);
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createChat(app);
@@ -266,4 +283,5 @@ app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
});