Skip to content

Commit d63933e

Browse files
authored
Merge pull request #266 from OpenKnots/okcode/project-thread-preview-scope
Scope desktop preview tabs by thread
2 parents a3c6ccb + 166446c commit d63933e

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
@@ -66,6 +66,7 @@ const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
6666
const PREVIEW_CREATE_TAB_CHANNEL = "desktop:preview-create-tab";
6767
const PREVIEW_CLOSE_TAB_CHANNEL = "desktop:preview-close-tab";
6868
const PREVIEW_ACTIVATE_TAB_CHANNEL = "desktop:preview-activate-tab";
69+
const PREVIEW_ACTIVATE_THREAD_CHANNEL = "desktop:preview-activate-thread";
6970
const PREVIEW_GO_BACK_CHANNEL = "desktop:preview-go-back";
7071
const PREVIEW_GO_FORWARD_CHANNEL = "desktop:preview-go-forward";
7172
const PREVIEW_RELOAD_CHANNEL = "desktop:preview-reload";
@@ -1276,18 +1277,29 @@ function registerIpcHandlers(): void {
12761277
ipcMain.removeHandler(PREVIEW_CREATE_TAB_CHANNEL);
12771278
ipcMain.handle(
12781279
PREVIEW_CREATE_TAB_CHANNEL,
1279-
async (event, input: { url?: unknown; title?: unknown }) => {
1280+
async (event, input: { url?: unknown; title?: unknown; threadId?: unknown }) => {
12801281
const window = resolvePreviewWindow(event.sender);
12811282
if (!window) {
12821283
return { tabId: "", state: createEmptyTabsState() };
12831284
}
12841285
return getPreviewController(window).createTab({
12851286
url: input?.url,
12861287
title: input?.title,
1288+
threadId: input?.threadId,
12871289
});
12881290
},
12891291
);
12901292

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