Skip to content

Commit 166446c

Browse files
committed
Scope preview tabs by thread
- Add IPC to activate a thread's preview set - Keep preview tabs and WebContentsView state isolated per thread - Pass thread IDs from the preview panel when opening tabs
1 parent 5105833 commit 166446c

File tree

5 files changed

+239
-48
lines changed

5 files changed

+239
-48
lines changed

apps/desktop/src/main.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
6565
const PREVIEW_CREATE_TAB_CHANNEL = "desktop:preview-create-tab";
6666
const PREVIEW_CLOSE_TAB_CHANNEL = "desktop:preview-close-tab";
6767
const PREVIEW_ACTIVATE_TAB_CHANNEL = "desktop:preview-activate-tab";
68+
const PREVIEW_ACTIVATE_THREAD_CHANNEL = "desktop:preview-activate-thread";
6869
const PREVIEW_GO_BACK_CHANNEL = "desktop:preview-go-back";
6970
const PREVIEW_GO_FORWARD_CHANNEL = "desktop:preview-go-forward";
7071
const PREVIEW_RELOAD_CHANNEL = "desktop:preview-reload";
@@ -1275,18 +1276,29 @@ function registerIpcHandlers(): void {
12751276
ipcMain.removeHandler(PREVIEW_CREATE_TAB_CHANNEL);
12761277
ipcMain.handle(
12771278
PREVIEW_CREATE_TAB_CHANNEL,
1278-
async (event, input: { url?: unknown; title?: unknown }) => {
1279+
async (event, input: { url?: unknown; title?: unknown; threadId?: unknown }) => {
12791280
const window = resolvePreviewWindow(event.sender);
12801281
if (!window) {
12811282
return { tabId: "", state: createEmptyTabsState() };
12821283
}
12831284
return getPreviewController(window).createTab({
12841285
url: input?.url,
12851286
title: input?.title,
1287+
threadId: input?.threadId,
12861288
});
12871289
},
12881290
);
12891291

1292+
ipcMain.removeHandler(PREVIEW_ACTIVATE_THREAD_CHANNEL);
1293+
ipcMain.handle(
1294+
PREVIEW_ACTIVATE_THREAD_CHANNEL,
1295+
async (event, input: { threadId?: string }) => {
1296+
const window = resolvePreviewWindow(event.sender);
1297+
if (!window || !input?.threadId) return createEmptyTabsState();
1298+
return getPreviewController(window).activateThread(input.threadId);
1299+
},
1300+
);
1301+
12901302
ipcMain.removeHandler(PREVIEW_CLOSE_TAB_CHANNEL);
12911303
ipcMain.handle(PREVIEW_CLOSE_TAB_CHANNEL, async (event, input: { tabId?: PreviewTabId }) => {
12921304
const window = resolvePreviewWindow(event.sender);

apps/desktop/src/preload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
1515
const PREVIEW_CREATE_TAB_CHANNEL = "desktop:preview-create-tab";
1616
const PREVIEW_CLOSE_TAB_CHANNEL = "desktop:preview-close-tab";
1717
const PREVIEW_ACTIVATE_TAB_CHANNEL = "desktop:preview-activate-tab";
18+
const PREVIEW_ACTIVATE_THREAD_CHANNEL = "desktop:preview-activate-thread";
1819
const PREVIEW_GO_BACK_CHANNEL = "desktop:preview-go-back";
1920
const PREVIEW_GO_FORWARD_CHANNEL = "desktop:preview-go-forward";
2021
const PREVIEW_RELOAD_CHANNEL = "desktop:preview-reload";
@@ -63,6 +64,7 @@ contextBridge.exposeInMainWorld("desktopBridge", {
6364
createTab: (input) => ipcRenderer.invoke(PREVIEW_CREATE_TAB_CHANNEL, input),
6465
closeTab: (input) => ipcRenderer.invoke(PREVIEW_CLOSE_TAB_CHANNEL, input),
6566
activateTab: (input) => ipcRenderer.invoke(PREVIEW_ACTIVATE_TAB_CHANNEL, input),
67+
activateThread: (input) => ipcRenderer.invoke(PREVIEW_ACTIVATE_THREAD_CHANNEL, input),
6668
goBack: () => ipcRenderer.invoke(PREVIEW_GO_BACK_CHANNEL),
6769
goForward: () => ipcRenderer.invoke(PREVIEW_GO_FORWARD_CHANNEL),
6870
reload: () => ipcRenderer.invoke(PREVIEW_RELOAD_CHANNEL),

0 commit comments

Comments
 (0)