2020-06-19 18:03:52 +02:00
|
|
|
import { ipcMain } from 'electron';
|
|
|
|
import { autoUpdater } from 'electron-updater';
|
2021-02-27 17:28:01 +01:00
|
|
|
import Store from 'electron-store';
|
|
|
|
const persistentStore = new Store({ name: 'settings' });
|
2020-06-19 18:03:52 +02:00
|
|
|
|
|
|
|
let mainWindow;
|
2021-02-27 17:28:01 +01:00
|
|
|
autoUpdater.allowPrerelease = persistentStore.get('allow_prerelease', true);
|
2020-06-19 18:03:52 +02:00
|
|
|
|
|
|
|
export default () => {
|
2020-08-18 18:03:59 +02:00
|
|
|
ipcMain.on('check-for-updates', event => {
|
2020-06-19 18:03:52 +02:00
|
|
|
mainWindow = event;
|
|
|
|
|
|
|
|
autoUpdater.checkForUpdatesAndNotify().catch(() => {
|
2020-08-18 18:03:59 +02:00
|
|
|
mainWindow.reply('check-failed');
|
2020-06-19 18:03:52 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-18 18:03:59 +02:00
|
|
|
ipcMain.on('restart-to-update', () => {
|
2020-06-19 18:03:52 +02:00
|
|
|
autoUpdater.quitAndInstall();
|
|
|
|
});
|
|
|
|
|
|
|
|
// auto-updater events
|
|
|
|
autoUpdater.on('checking-for-update', () => {
|
2020-08-18 18:03:59 +02:00
|
|
|
mainWindow.reply('checking-for-update');
|
2020-06-19 18:03:52 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on('update-available', () => {
|
2020-08-18 18:03:59 +02:00
|
|
|
mainWindow.reply('update-available');
|
2020-06-19 18:03:52 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on('update-not-available', () => {
|
2020-08-18 18:03:59 +02:00
|
|
|
mainWindow.reply('update-not-available');
|
2020-06-19 18:03:52 +02:00
|
|
|
});
|
|
|
|
|
2020-08-18 18:03:59 +02:00
|
|
|
autoUpdater.on('download-progress', data => {
|
|
|
|
mainWindow.reply('download-progress', data);
|
2020-06-19 18:03:52 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on('update-downloaded', () => {
|
2020-08-18 18:03:59 +02:00
|
|
|
mainWindow.reply('update-downloaded');
|
2020-06-19 18:03:52 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.logger = require('electron-log');
|
|
|
|
autoUpdater.logger.transports.console.format = '{h}:{i}:{s} {text}';
|
|
|
|
autoUpdater.logger.transports.file.level = 'info';
|
|
|
|
};
|