From b1b9aa3727173616e0abcddd3688420fccdc3989 Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Mon, 8 Jun 2026 06:19:15 +0530 Subject: [PATCH] feat(ipc): add updater and crash IPC handlers --- src/main/ipc/crash-handlers.js | 21 +++++++++++++++++++++ src/main/ipc/updater-handlers.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/main/ipc/crash-handlers.js create mode 100644 src/main/ipc/updater-handlers.js diff --git a/src/main/ipc/crash-handlers.js b/src/main/ipc/crash-handlers.js new file mode 100644 index 0000000..9de58b5 --- /dev/null +++ b/src/main/ipc/crash-handlers.js @@ -0,0 +1,21 @@ +const { ipcMain, shell } = require('electron'); + +function register({ crash, getMainWindow }) { + ipcMain.handle('crash:read', () => { + return crash.list(); + }); + + ipcMain.on('crash:open-dir', () => { + shell.openPath(crash.path()); + }); + + ipcMain.handle('crash:delete', (_event, filename) => { + if (typeof filename === 'string' && /^\d+(-\d+)?-(uncaughtException|unhandledRejection)\.json$/.test(filename)) { + crash.delete(filename); + return true; + } + return false; + }); +} + +module.exports = { register }; diff --git a/src/main/ipc/updater-handlers.js b/src/main/ipc/updater-handlers.js new file mode 100644 index 0000000..9c9c1d6 --- /dev/null +++ b/src/main/ipc/updater-handlers.js @@ -0,0 +1,32 @@ +const { ipcMain } = require('electron'); +const { resolveFeedUrl } = require('../updater/feed-config'); + +function register({ updater, getMainWindow, getChannel }) { + ipcMain.handle('updater:check', async () => { + const channel = getChannel(); + const version = require('electron').app.getVersion(); + const platform = process.platform; + const feed = resolveFeedUrl(channel, version, platform); + updater.autoUpdater.setFeedURL({ url: feed.replace(/\/latest-[^/]+\.yml$/, '') }); + await updater.check(); + return { state: updater.state }; + }); + + ipcMain.handle('updater:install', () => { + updater.install(); + }); + + ipcMain.handle('updater:get-state', () => { + return { state: updater.state }; + }); + + // Forward status events to renderer + updater.on('status', (payload) => { + const win = getMainWindow(); + if (win && !win.isDestroyed()) { + win.webContents.send('updater:status', payload); + } + }); +} + +module.exports = { register };