Skip to content

Commit

Permalink
Add logging for IPC events (#108)
Browse files Browse the repository at this point in the history
* Add logging for IPC events

* Add params
  • Loading branch information
sergeichestakov authored Aug 17, 2023
1 parent c03c1c0 commit dfad561
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { authPage, baseUrl } from "./constants";
import { events } from "./events";
import store from "./store";
import isSupportedPage from "./isSupportedPage";
import log from "electron-log/main";

function logEvent(event: events, params?: Record<string, unknown>) {
log.info(
`Recieved IPC event: ${event}${
params ? ` with params ${JSON.stringify(params)}` : ""
}`
);
}

/**
* Set listeners for IPC, or inter-process communication, events that are
Expand All @@ -15,13 +24,15 @@ import isSupportedPage from "./isSupportedPage";
*/
export function setIpcEventListeners(): void {
ipcMain.on(events.CLOSE_CURRENT_WINDOW, (event) => {
logEvent(events.CLOSE_CURRENT_WINDOW);
const senderWindow = BrowserWindow.getAllWindows().find(
(win) => win.webContents.id === event.sender.id
);
senderWindow.close();
});

ipcMain.on(events.OPEN_WINDOW, (_, slug) => {
logEvent(events.OPEN_WINDOW, { slug });
if (!isSupportedPage(slug)) {
throw new Error("Page not supported");
}
Expand All @@ -31,11 +42,13 @@ export function setIpcEventListeners(): void {
});

ipcMain.on(events.OPEN_EXTERNAL_URL, (_, url) => {
logEvent(events.OPEN_EXTERNAL_URL, { url });
shell.openExternal(url);
});

// When logging out we have to close all the windows, and do the actual logout navigation in a splash window
ipcMain.on(events.LOGOUT, () => {
logEvent(events.LOGOUT);
store.setLastOpenRepl(null);
const url = `${baseUrl}/logout?goto=${authPage}`;

Expand All @@ -44,6 +57,7 @@ export function setIpcEventListeners(): void {
});

ipcMain.handle(events.SHOW_MESSAGE_BOX, async (event, params) => {
logEvent(events.SHOW_MESSAGE_BOX, params);
const { response } = await dialog.showMessageBox(params);

return response;
Expand Down

0 comments on commit dfad561

Please sign in to comment.