Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(desktop): add New Window to the File menu, opening the current workspace (#21928)

AmAzing-33472dc5a31b
diff --git a/apps/desktop/resources/locales/en/menu.json b/apps/desktop/resources/locales/en/menu.json
index 97f1779a02b..3dd6ab3f124 100644
--- a/apps/desktop/resources/locales/en/menu.json
+++ b/apps/desktop/resources/locales/en/menu.json
@@ -49,6 +49,7 @@
"file.newAgentGroup": "New Agent Group",
"file.newPage": "New Page",
"file.newTopic": "New Topic",
+ "file.newWindow": "New Window",
"file.preferences": "Preferences",
"file.quit": "Quit",
"file.title": "File",
diff --git a/apps/desktop/resources/locales/zh-CN/menu.json b/apps/desktop/resources/locales/zh-CN/menu.json
index 8f17ce5d805..02f98b2cb6c 100644
--- a/apps/desktop/resources/locales/zh-CN/menu.json
+++ b/apps/desktop/resources/locales/zh-CN/menu.json
@@ -51,6 +51,7 @@
"file.newPage": "新建页面",
"file.newTab": "新建标签页",
"file.newTopic": "新建话题",
+ "file.newWindow": "新建窗口",
"file.preferences": "设置…",
"file.quit": "退出",
"file.title": "文件",
diff --git a/apps/desktop/src/main/locales/default/menu.ts b/apps/desktop/src/main/locales/default/menu.ts
index 1095b258038..9d5ffa5fdc4 100644
--- a/apps/desktop/src/main/locales/default/menu.ts
+++ b/apps/desktop/src/main/locales/default/menu.ts
@@ -51,6 +51,7 @@ const menu = {
'file.newPage': 'New Page',
'file.newTab': 'New Tab',
'file.newTopic': 'New Topic',
+ 'file.newWindow': 'New Window',
'file.preferences': 'Preferences',
'file.quit': 'Quit',
'file.title': 'File',
diff --git a/apps/desktop/src/main/menus/impls/BaseMenuPlatform.test.ts b/apps/desktop/src/main/menus/impls/BaseMenuPlatform.test.ts
index 488b70adfcb..08864194f5d 100644
--- a/apps/desktop/src/main/menus/impls/BaseMenuPlatform.test.ts
+++ b/apps/desktop/src/main/menus/impls/BaseMenuPlatform.test.ts
@@ -11,6 +11,11 @@ class TestMenuPlatform extends BaseMenuPlatform {
return this.buildReloadMenuItem('Reload', ignoreCache);
}
}
+class TestNewWindowMenuPlatform extends BaseMenuPlatform {
+ triggerNewWindow(targetWindow?: ElectronBrowserWindow | null) {
+ this.openNewWindow(targetWindow);
+ }
+}
class TestDevToolsMenuPlatform extends BaseMenuPlatform {
buildDevToolsItem(label = 'Developer Tools', accelerator = 'F12') {
return this.buildDevToolsMenuItem(label, accelerator);
@@ -274,4 +279,64 @@ describe('BaseMenuPlatform', () => {
expect(focusedDefaultDevToolsWindow.webContents.openDevTools).not.toHaveBeenCalled();
});
});
+
+ describe('openNewWindow', () => {
+ let newWindowMenuPlatform: TestNewWindowMenuPlatform;
+ let mainWindow: { broadcast: ReturnType<typeof vi.fn> };
+
+ const registerBrowser = (identifier: string, path: string, target: ElectronBrowserWindow) => {
+ const browser = { broadcast: vi.fn(), options: { path }, webContents: target.webContents };
+ mockApp.browserManager.browsers.set(identifier, browser as any);
+ return browser;
+ };
+
+ beforeEach(() => {
+ mainWindow = { broadcast: vi.fn() };
+ vi.mocked(mockApp.browserManager.getMainWindow).mockReturnValue(mainWindow as any);
+ newWindowMenuPlatform = new TestNewWindowMenuPlatform(mockApp);
+ });
+
+ afterEach(() => {
+ mockApp.browserManager.browsers.clear();
+ });
+
+ it('asks the focused app-shell window to open its workspace in a new window', () => {
+ const target = createBrowserWindow({});
+ const workspaceWindow = registerBrowser('workspace_ws1', '/acme', target);
+
+ newWindowMenuPlatform.triggerNewWindow(target);
+
+ expect(workspaceWindow.broadcast).toHaveBeenCalledWith('openNewWindow');
+ expect(mainWindow.broadcast).not.toHaveBeenCalled();
+ });
+
+ it('uses the OS-focused window when the menu has no target window', () => {
+ const target = createBrowserWindow({});
+ const workspaceWindow = registerBrowser('workspace_ws1', '/acme', target);
+ vi.mocked(BrowserWindow.getFocusedWindow).mockReturnValue(target);
+
+ newWindowMenuPlatform.triggerNewWindow(null);
+
+ expect(workspaceWindow.broadcast).toHaveBeenCalledWith('openNewWindow');
+ });
+
+ it.each(['/popup/agent/a/t', '/desktop/devtools'])(
+ 'falls back to the main window when the focused window has no app shell (%s)',
+ (path) => {
+ const target = createBrowserWindow({});
+ const popup = registerBrowser('popup', path, target);
+
+ newWindowMenuPlatform.triggerNewWindow(target);
+
+ expect(popup.broadcast).not.toHaveBeenCalled();
+ expect(mainWindow.broadcast).toHaveBeenCalledWith('openNewWindow');
+ },
+ );
+
+ it('falls back to the main window when no window is focused', () => {
+ newWindowMenuPlatform.triggerNewWindow(null);
+
+ expect(mainWindow.broadcast).toHaveBeenCalledWith('openNewWindow');
+ });
+ });
});
diff --git a/apps/desktop/src/main/menus/impls/BaseMenuPlatform.ts b/apps/desktop/src/main/menus/impls/BaseMenuPlatform.ts
index 8916b2326ab..40389a00bae 100644
--- a/apps/desktop/src/main/menus/impls/BaseMenuPlatform.ts
+++ b/apps/desktop/src/main/menus/impls/BaseMenuPlatform.ts
@@ -5,6 +5,9 @@ import { BrowserWindow } from 'electron';
import type { App } from '@/core/App';
import ZoomService, { type ZoomAction } from '@/services/zoomSrv';
+// Popup (`/popup/*`) and desktop utility (`/desktop/*`) windows run without the app shell.
+const NON_APP_SHELL_PATH = /^\/(?:popup|desktop)(?:\/|$)/;
+
export abstract class BaseMenuPlatform {
protected app: App;
private readonly devToolsWindows = new Map<BrowserWindow, BrowserWindow>();
@@ -66,6 +69,28 @@ export abstract class BaseMenuPlatform {
};
}
+ /**
+ * File > New Window: ask the window the user is working in to open its current
+ * workspace in a new window. Only full-app windows mount the File-menu bridge,
+ * so popups, devtools, or no focused window fall back to the main window.
+ */
+ protected openNewWindow(targetWindow?: BaseWindow | null): void {
+ const focused =
+ targetWindow && 'webContents' in targetWindow
+ ? (targetWindow as BrowserWindow)
+ : BrowserWindow.getFocusedWindow();
+ const focusedBrowser = focused
+ ? [...this.app.browserManager.browsers.values()].find(
+ (browser) => browser.webContents === focused.webContents,
+ )
+ : undefined;
+ const isAppShell = focusedBrowser && !NON_APP_SHELL_PATH.test(focusedBrowser.options.path);
+
+ (isAppShell ? focusedBrowser : this.app.browserManager.getMainWindow()).broadcast(
+ 'openNewWindow',
+ );
+ }
+
protected closeFocusedTabOrWindow(targetWindow?: BaseWindow | null): void {
const focused =
targetWindow && 'webContents' in targetWindow
diff --git a/apps/desktop/src/main/menus/impls/linux.ts b/apps/desktop/src/main/menus/impls/linux.ts
index 1bdbe161d53..a80b9665b6b 100644
--- a/apps/desktop/src/main/menus/impls/linux.ts
+++ b/apps/desktop/src/main/menus/impls/linux.ts
@@ -79,6 +79,11 @@ export class LinuxMenu extends BaseMenuPlatform implements IMenuPlatform {
},
label: t('file.newTab'),
},
+ {
+ accelerator: 'Ctrl+Shift+N',
+ click: (_item, targetWindow) => this.openNewWindow(targetWindow),
+ label: t('file.newWindow'),
+ },
{ type: 'separator' },
{
accelerator: 'Alt+Ctrl+A',
diff --git a/apps/desktop/src/main/menus/impls/macOS.test.ts b/apps/desktop/src/main/menus/impls/macOS.test.ts
index 59984b92af2..6a4a1a457e6 100644
--- a/apps/desktop/src/main/menus/impls/macOS.test.ts
+++ b/apps/desktop/src/main/menus/impls/macOS.test.ts
@@ -8,6 +8,9 @@ import { MacOSMenu } from './macOS';
// Mock Electron modules
vi.mock('electron', () => ({
+ BrowserWindow: {
+ getFocusedWindow: vi.fn(() => null),
+ },
Menu: {
buildFromTemplate: vi.fn((template) => ({ template })),
setApplicationMenu: vi.fn(),
@@ -259,6 +262,22 @@ describe('MacOSMenu', () => {
expect(mainWindow.broadcast).toHaveBeenCalledWith('createNewTab', { path: '/settings' });
});
+ it('should place New Window after New Tab in the File menu', () => {
+ macOSMenu.buildAndSetAppMenu();
+
+ const template = (Menu.buildFromTemplate as any).mock.calls[0][0];
+ const fileMenu = template.find((item: any) => item.label === 'File');
+ const labels = fileMenu.submenu.map((item: any) => item.label);
+ const newWindowItem = fileMenu.submenu.find((item: any) => item.label === 'New Window');
+
+ expect(labels.indexOf('New Window')).toBe(labels.indexOf('New Tab') + 1);
+ expect(newWindowItem.accelerator).toBe('Shift+Command+N');
+
+ newWindowItem.click(undefined, null);
+ const mainWindow = (mockApp.browserManager.getMainWindow as any).mock.results.at(-1).value;
+ expect(mainWindow.broadcast).toHaveBeenCalledWith('openNewWindow');
+ });
+
it('should handle visit website click', async () => {
macOSMenu.buildAndSetAppMenu();
diff --git a/apps/desktop/src/main/menus/impls/macOS.ts b/apps/desktop/src/main/menus/impls/macOS.ts
index b66bf5f02dc..d846f81963c 100644
--- a/apps/desktop/src/main/menus/impls/macOS.ts
+++ b/apps/desktop/src/main/menus/impls/macOS.ts
@@ -137,6 +137,11 @@ export class MacOSMenu extends BaseMenuPlatform implements IMenuPlatform {
},
label: t('file.newTab'),
},
+ {
+ accelerator: 'Shift+Command+N',
+ click: (_item, targetWindow) => this.openNewWindow(targetWindow),
+ label: t('file.newWindow'),
+ },
{ type: 'separator' },
{
accelerator: 'Alt+Command+A',
diff --git a/apps/desktop/src/main/menus/impls/windows.ts b/apps/desktop/src/main/menus/impls/windows.ts
index fcf8bda0a6d..4e973f6f6c4 100644
--- a/apps/desktop/src/main/menus/impls/windows.ts
+++ b/apps/desktop/src/main/menus/impls/windows.ts
@@ -80,6 +80,11 @@ export class WindowsMenu extends BaseMenuPlatform implements IMenuPlatform {
},
label: t('file.newTab'),
},
+ {
+ accelerator: 'Ctrl+Shift+N',
+ click: (_item, targetWindow) => this.openNewWindow(targetWindow),
+ label: t('file.newWindow'),
+ },
{ type: 'separator' },
{
accelerator: 'Alt+Ctrl+A',
diff --git a/packages/electron-client-ipc/src/events/navigation.ts b/packages/electron-client-ipc/src/events/navigation.ts
index bc1aa43b941..a87fbd5351e 100644
--- a/packages/electron-client-ipc/src/events/navigation.ts
+++ b/packages/electron-client-ipc/src/events/navigation.ts
@@ -55,6 +55,12 @@ export interface NavigationBroadcastEvents {
/** Ask the renderer to open the all-agents surface. */
openAllAgents: () => void;
+ /**
+ * Ask renderer to open its current workspace (or personal home) in a new window.
+ * Triggered from the main process File menu.
+ */
+ openNewWindow: () => void;
+
/** Ask the renderer to open the Recently Viewed surface. */
openRecentlyViewed: () => void;
}
diff --git a/src/features/DesktopFileMenuBridge/index.tsx b/src/features/DesktopFileMenuBridge/index.tsx
index 02459eab511..b416065d0f3 100644
--- a/src/features/DesktopFileMenuBridge/index.tsx
+++ b/src/features/DesktopFileMenuBridge/index.tsx
@@ -10,9 +10,11 @@ import { useAgentStore } from '@/store/agent';
import { builtinAgentSelectors } from '@/store/agent/selectors';
import { useChatStore } from '@/store/chat';
+import { openCurrentWorkspaceInNewWindow } from './openCurrentWorkspaceInNewWindow';
+
/**
* Bridge component for handling File menu actions from Electron main process
- * Listens to broadcast events for creating new topics, agents, agent groups, and pages
+ * Listens to broadcast events for creating new topics, agents, agent groups, pages and windows
*/
const DesktopFileMenuBridge = () => {
const { createAgent, createEmptyGroup, createPage } = useCreateMenuItems();
@@ -52,6 +54,7 @@ const DesktopFileMenuBridge = () => {
useWatchBroadcast('createNewAgent', handleCreateNewAgent);
useWatchBroadcast('createNewAgentGroup', handleCreateNewAgentGroup);
useWatchBroadcast('createNewPage', handleCreateNewPage);
+ useWatchBroadcast('openNewWindow', openCurrentWorkspaceInNewWindow);
return null;
};
diff --git a/src/features/DesktopFileMenuBridge/openCurrentWorkspaceInNewWindow.test.ts b/src/features/DesktopFileMenuBridge/openCurrentWorkspaceInNewWindow.test.ts
new file mode 100644
index 00000000000..085ac3e3903
--- /dev/null
+++ b/src/features/DesktopFileMenuBridge/openCurrentWorkspaceInNewWindow.test.ts
@@ -0,0 +1,48 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { PERSONAL_TAB_SCOPE } from '@/features/Electron/titlebar/TabBar/scope';
+import { useElectronStore } from '@/store/electron';
+
+import { openCurrentWorkspaceInNewWindow } from './openCurrentWorkspaceInNewWindow';
+
+const createMultiInstanceWindow = vi.hoisted(() => vi.fn());
+
+vi.mock('@/utils/electron/ipc', () => ({
+ ensureElectronIpc: () => ({ windows: { createMultiInstanceWindow } }),
+}));
+
+describe('openCurrentWorkspaceInNewWindow', () => {
+ beforeEach(() => {
+ createMultiInstanceWindow.mockReset();
+ createMultiInstanceWindow.mockResolvedValue({ success: true, windowId: 'chatSingle_1' });
+ });
+
+ it('opens the active workspace home in a fresh window sized like the current one', async () => {
+ useElectronStore.setState({ activeTabScope: { slug: 'acme', type: 'workspace' } });
+
+ await openCurrentWorkspaceInNewWindow();
+
+ expect(createMultiInstanceWindow).toHaveBeenCalledWith({
+ inheritCurrentWindowSize: true,
+ path: '/acme',
+ templateId: 'chatSingle',
+ });
+ });
+
+ it('opens the personal home when the active tab is in the personal scope', async () => {
+ useElectronStore.setState({ activeTabScope: PERSONAL_TAB_SCOPE });
+
+ await openCurrentWorkspaceInNewWindow();
+
+ expect(createMultiInstanceWindow).toHaveBeenCalledWith(expect.objectContaining({ path: '/' }));
+ });
+
+ it('does not throw when the window cannot be created', async () => {
+ const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
+ createMultiInstanceWindow.mockRejectedValue(new Error('ipc down'));
+
+ await expect(openCurrentWorkspaceInNewWindow()).resolves.toBeUndefined();
+ expect(consoleError).toHaveBeenCalled();
+ consoleError.mockRestore();
+ });
+});
diff --git a/src/features/DesktopFileMenuBridge/openCurrentWorkspaceInNewWindow.ts b/src/features/DesktopFileMenuBridge/openCurrentWorkspaceInNewWindow.ts
new file mode 100644
index 00000000000..da9213ffc06
--- /dev/null
+++ b/src/features/DesktopFileMenuBridge/openCurrentWorkspaceInNewWindow.ts
@@ -0,0 +1,20 @@
+import { tabScopeHomeUrl } from '@/features/Electron/titlebar/TabBar/scope';
+import { useElectronStore } from '@/store/electron';
+import { ensureElectronIpc } from '@/utils/electron/ipc';
+
+// Open the active tab's workspace (or personal home) in a new window, sized like this one.
+// No uniqueId: every New Window opens a fresh window, like a browser.
+export const openCurrentWorkspaceInNewWindow = async () => {
+ try {
+ const { activeTabScope } = useElectronStore.getState();
+ const result = await ensureElectronIpc().windows.createMultiInstanceWindow({
+ inheritCurrentWindowSize: true,
+ path: tabScopeHomeUrl(activeTabScope),
+ templateId: 'chatSingle',
+ });
+
+ if (!result.success) console.error('Failed to open new window:', result.error);
+ } catch (error) {
+ console.error('Error opening new window:', error);
+ }
+};