Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions electron/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function createMenu(): void {
accelerator: 'CmdOrCtrl+N',
click: () => {
const win = BrowserWindow.getFocusedWindow();
win?.webContents.send('navigate', '/chat');
win?.webContents.send('new-chat');
},
},
{ type: 'separator' },
Expand Down Expand Up @@ -114,7 +114,7 @@ export function createMenu(): void {
accelerator: 'CmdOrCtrl+2',
click: () => {
const win = BrowserWindow.getFocusedWindow();
win?.webContents.send('navigate', '/chat');
win?.webContents.send('navigate', '/');
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions electron/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const electronAPI = {
'gateway:exit',
'gateway:error',
'navigate',
'new-chat',
'update:status-changed',
'update:checking',
'update:available',
Expand Down Expand Up @@ -216,6 +217,7 @@ const electronAPI = {
'gateway:exit',
'gateway:error',
'navigate',
'new-chat',
'update:status-changed',
'update:checking',
'update:available',
Expand Down
18 changes: 18 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Skills } from './pages/Skills';
import { Cron } from './pages/Cron';
import { Settings } from './pages/Settings';
import { Setup } from './pages/Setup';
import { useChatStore } from '@/stores/chat';
import { useSettingsStore } from './stores/settings';
import { useGatewayStore } from './stores/gateway';
import { useProviderStore } from './stores/providers';
Expand Down Expand Up @@ -143,6 +144,23 @@ function App() {
};
}, [navigate]);

// Listen for new-chat event from main process (Cmd+N / Ctrl+N)
useEffect(() => {
const handleNewChat = () => {
const { messages, newSession } = useChatStore.getState();
if (messages.length > 0) newSession();
navigate('/');
};

const unsubscribe = window.electron.ipcRenderer.on('new-chat', handleNewChat);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Allowlist new IPC channel before subscribing

Subscribing to window.electron.ipcRenderer.on('new-chat', ...) will throw at runtime because the preload bridge only permits channels listed in electron/preload/index.ts, and 'new-chat' is not in that allowlist (on() throws Invalid IPC channel for unknown values). This means the new effect can fail during app startup and the Cmd/Ctrl+N flow never gets a listener in production builds unless the preload allowlist is updated to include this event.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed in e350a5c. Added 'new-chat' to both the on() and once() allowlists in electron/preload/index.ts. 👍


return () => {
if (typeof unsubscribe === 'function') {
unsubscribe();
}
};
}, [navigate]);

// Apply theme
useEffect(() => {
const root = window.document.documentElement;
Expand Down
Loading