Skip to content

Commit

Permalink
mac main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Kvadratni committed Nov 28, 2024
1 parent 24e00d7 commit bb2f665
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ui/desktop/src/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,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();
}
};

Expand Down
22 changes: 20 additions & 2 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -266,4 +283,5 @@ app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
});

0 comments on commit bb2f665

Please sign in to comment.