feat(ipc): add updater and crash IPC handlers

This commit is contained in:
2026-06-08 06:19:15 +05:30
parent 77ad2fdb9d
commit b1b9aa3727
2 changed files with 53 additions and 0 deletions
+21
View File
@@ -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 };
+32
View File
@@ -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 };