2020-05-21 07:38:44 +02:00
|
|
|
import {autoUpdater, UpdateInfo} from "electron-updater";
|
2020-05-19 10:54:00 +02:00
|
|
|
|
|
|
|
export default class Updater {
|
2020-05-21 07:38:44 +02:00
|
|
|
private updateInfo?: UpdateInfo;
|
2020-05-19 10:54:00 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
autoUpdater.autoDownload = false;
|
|
|
|
autoUpdater.on('error', err => {
|
2020-05-21 07:38:44 +02:00
|
|
|
console.log('Error while checking for updates', err);
|
2020-05-19 10:54:00 +02:00
|
|
|
});
|
|
|
|
autoUpdater.on('update-available', v => {
|
2020-05-21 07:38:44 +02:00
|
|
|
console.log('Update available', v);
|
2020-05-19 10:54:00 +02:00
|
|
|
});
|
|
|
|
autoUpdater.on('update-not-available', () => {
|
2020-05-21 07:38:44 +02:00
|
|
|
console.log('No update available.');
|
2020-05-19 10:54:00 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
2020-05-21 07:38:44 +02:00
|
|
|
checkForUpdates(callback: UpdateCheckCallback) {
|
|
|
|
if (this.updateInfo) {
|
|
|
|
callback(this.updateInfo.version !== this.getCurrentVersion().raw, this.updateInfo);
|
2020-05-19 11:21:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-19 10:54:00 +02:00
|
|
|
autoUpdater.checkForUpdates().then(r => {
|
2020-05-21 07:38:44 +02:00
|
|
|
this.updateInfo = r.updateInfo;
|
2020-05-19 11:21:12 +02:00
|
|
|
callback(r.updateInfo.version !== this.getCurrentVersion().raw, r.updateInfo);
|
2020-05-19 10:54:00 +02:00
|
|
|
}).catch(err => {
|
2020-05-19 11:21:12 +02:00
|
|
|
callback(false, err);
|
2020-05-19 10:54:00 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentVersion() {
|
|
|
|
return autoUpdater.currentVersion;
|
|
|
|
}
|
2020-05-21 07:38:44 +02:00
|
|
|
}
|
2020-05-19 11:21:12 +02:00
|
|
|
|
2020-05-21 07:38:44 +02:00
|
|
|
export type UpdateCheckCallback = (available: boolean, data: UpdateInfo) => void;
|