mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-03 02:11:07 +05:30
feat(ipc): add updater and crash IPC handlers
This commit is contained in:
@@ -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 };
|
||||
@@ -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 };
|
||||
Reference in New Issue
Block a user