2022-03-16 09:49:48 +00:00
|
|
|
import { autoUpdater, UpdateInfo } from 'electron-updater';
|
|
|
|
import { Main } from '../main';
|
2022-03-31 07:33:58 +00:00
|
|
|
import { IPC_CHANNELS } from '../utils/messages';
|
2022-03-16 09:49:48 +00:00
|
|
|
|
|
|
|
export default function registerAutoUpdaterListeners(main: Main) {
|
|
|
|
autoUpdater.autoDownload = false;
|
|
|
|
autoUpdater.autoInstallOnAppQuit = false;
|
|
|
|
|
|
|
|
autoUpdater.on('checking-for-update', () => {
|
|
|
|
if (!main.checkedForUpdate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
main.mainWindow!.webContents.send(IPC_CHANNELS.CHECKING_FOR_UPDATE);
|
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on('update-available', (info: UpdateInfo) => {
|
|
|
|
if (!main.checkedForUpdate) {
|
|
|
|
main.checkedForUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
main.mainWindow!.webContents.send(
|
|
|
|
IPC_CHANNELS.UPDATE_AVAILABLE,
|
|
|
|
info.version
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on('update-not-available', () => {
|
|
|
|
if (!main.checkedForUpdate) {
|
|
|
|
main.checkedForUpdate = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
main.mainWindow!.webContents.send(IPC_CHANNELS.UPDATE_NOT_AVAILABLE);
|
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on('update-downloaded', () => {
|
|
|
|
main.mainWindow!.webContents.send(IPC_CHANNELS.UPDATE_DOWNLOADED);
|
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on('error', (error) => {
|
|
|
|
if (!main.checkedForUpdate) {
|
|
|
|
main.checkedForUpdate = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
main.mainWindow!.webContents.send(IPC_CHANNELS.UPDATE_ERROR, error);
|
|
|
|
});
|
|
|
|
}
|