Skip to content
Merged
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
20 changes: 11 additions & 9 deletions src/node/services/ipcMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class IpcMain {
workspaceId: string,
snapshot: WorkspaceActivitySnapshot | null
): void {
if (!this.mainWindow) {
if (!this.mainWindow || this.mainWindow?.isDestroyed()) {
return;
}
this.mainWindow.webContents.send(IPC_CHANNELS.WORKSPACE_ACTIVITY, {
Expand Down Expand Up @@ -508,15 +508,15 @@ export class IpcMain {
});

const chatUnsubscribe = session.onChatEvent((event) => {
if (!this.mainWindow) {
if (!this.mainWindow || this.mainWindow?.isDestroyed()) {
return;
}
const channel = getChatChannel(event.workspaceId);
this.mainWindow.webContents.send(channel, event.message);
});

const metadataUnsubscribe = session.onMetadataEvent((event) => {
if (!this.mainWindow) {
if (!this.mainWindow || this.mainWindow?.isDestroyed()) {
return;
}
this.mainWindow.webContents.send(IPC_CHANNELS.WORKSPACE_METADATA, {
Expand Down Expand Up @@ -969,7 +969,7 @@ export class IpcMain {
const session = this.sessions.get(workspaceId);
if (session) {
session.emitMetadata(updatedMetadata);
} else if (this.mainWindow) {
} else if (this.mainWindow && !this.mainWindow?.isDestroyed()) {
this.mainWindow.webContents.send(IPC_CHANNELS.WORKSPACE_METADATA, {
workspaceId,
metadata: updatedMetadata,
Expand Down Expand Up @@ -1379,7 +1379,9 @@ export class IpcMain {
type: "delete",
historySequences: deletedSequences,
};
this.mainWindow.webContents.send(getChatChannel(workspaceId), deleteMessage);
if (this.mainWindow && !this.mainWindow?.isDestroyed()) {
this.mainWindow.webContents.send(getChatChannel(workspaceId), deleteMessage);
}
}

return { success: true, data: undefined };
Expand Down Expand Up @@ -1417,7 +1419,7 @@ export class IpcMain {
}

// Send delete event to frontend for all old messages
if (deletedSequences.length > 0 && this.mainWindow) {
if (deletedSequences.length > 0 && this.mainWindow && !this.mainWindow?.isDestroyed()) {
const deleteMessage: DeleteMessage = {
type: "delete",
historySequences: deletedSequences,
Expand All @@ -1426,7 +1428,7 @@ export class IpcMain {
}

// Send the new summary message to frontend
if (this.mainWindow) {
if (this.mainWindow && !this.mainWindow?.isDestroyed()) {
this.mainWindow.webContents.send(getChatChannel(workspaceId), summaryMessage);
}

Expand Down Expand Up @@ -1632,7 +1634,7 @@ export class IpcMain {
const existingSession = this.sessions.get(workspaceId);
if (existingSession) {
existingSession.emitMetadata(null);
} else if (this.mainWindow) {
} else if (this.mainWindow && !this.mainWindow?.isDestroyed()) {
this.mainWindow.webContents.send(IPC_CHANNELS.WORKSPACE_METADATA, {
workspaceId,
metadata: null,
Expand Down Expand Up @@ -2091,7 +2093,7 @@ export class IpcMain {
const chatChannel = getChatChannel(workspaceId);

await session.replayHistory((event) => {
if (!this.mainWindow) {
if (!this.mainWindow || this.mainWindow?.isDestroyed()) {
return;
}
this.mainWindow.webContents.send(chatChannel, event.message);
Expand Down
1 change: 1 addition & 0 deletions tests/ipcMain/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function createMockBrowserWindow(): {
openDevTools: jest.fn(),
} as unknown as WebContents,
isMinimized: jest.fn(() => false),
isDestroyed: jest.fn(() => false),
restore: jest.fn(),
focus: jest.fn(),
loadURL: jest.fn(),
Expand Down