2020-05-19 10:54:00 +02:00
|
|
|
import {autoUpdater} from "electron-updater";
|
|
|
|
|
|
|
|
export default class Updater {
|
2020-05-19 11:21:12 +02:00
|
|
|
#updateInfo;
|
2020-05-19 10:54:00 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
autoUpdater.autoDownload = false;
|
|
|
|
autoUpdater.on('error', err => {
|
2020-05-19 11:21:12 +02:00
|
|
|
this.notifyUpdate(false, err);
|
2020-05-19 10:54:00 +02:00
|
|
|
});
|
|
|
|
autoUpdater.on('update-available', v => {
|
2020-05-19 11:21:12 +02:00
|
|
|
this.notifyUpdate(true, v);
|
2020-05-19 10:54:00 +02:00
|
|
|
});
|
|
|
|
autoUpdater.on('update-not-available', () => {
|
2020-05-19 11:21:12 +02:00
|
|
|
this.notifyUpdate(false);
|
2020-05-19 10:54:00 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
|
|
|
checkForUpdates(callback) {
|
2020-05-19 11:21:12 +02:00
|
|
|
if (this.#updateInfo) {
|
|
|
|
callback(this.#updateInfo.version !== this.getCurrentVersion().raw, this.#updateInfo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-19 10:54:00 +02:00
|
|
|
autoUpdater.checkForUpdates().then(r => {
|
2020-05-19 11:21:12 +02:00
|
|
|
this.#updateInfo = r.updateInfo;
|
|
|
|
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-19 11:21:12 +02:00
|
|
|
|
|
|
|
notifyUpdate(available, data) {
|
|
|
|
console.log('Update:', available, data);
|
|
|
|
}
|
2020-05-19 10:54:00 +02:00
|
|
|
}
|