Merge pull request #138 from JsSucks/updater

Updater
This commit is contained in:
Alexei Stukov 2018-02-15 01:07:49 +02:00 committed by GitHub
commit fdb6ddd540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 5 deletions

View File

@ -17,6 +17,7 @@ export default class {
constructor() {
window.updater = this;
this.updatesAvailable = false;
this.init = this.init.bind(this);
this.checkForUpdates = this.checkForUpdates.bind(this);
}
@ -26,10 +27,17 @@ export default class {
}
init() {
setInterval(this.checkForUpdates, this.interval);
this.updateInterval = setInterval(this.checkForUpdates, this.interval);
}
update() {
// TODO
this.updatesAvailable = false;
Events.emit('update-check-end');
}
checkForUpdates() {
if (this.updatesAvailable) return;
Events.emit('update-check-start');
Logger.info('Updater', 'Checking for updates');
$.ajax({
@ -37,9 +45,19 @@ export default class {
url: 'https://rawgit.com/JsSucks/BetterDiscordApp/master/package.json',
cache: false,
success: e => {
Logger.info('Updater', `Latest Version: ${e.version} - Current Version: ${Globals.getObject('version')}`);
try {
Events.emit('update-check-end');
Logger.info('Updater',
`Latest Version: ${e.version} - Current Version: ${Globals.getObject('version')}`);
if (e.version !== Globals.getObject('version')) {
this.updatesAvailable = true;
Events.emit('updates-available');
}
} catch (err) {
Events.emit('update-check-fail', err);
}
},
fail: e => Events.emit('update-check-fail', e)
});
}

View File

@ -32,7 +32,7 @@ const { BrowserWindow, dialog } = require('electron');
const Common = {};
const dummyArgs = {
'version': '0.3.1',
'version': '2.0.0a',
'paths': [
{ 'id': 'base', 'path': 'basePath' },
{ 'id': 'data', 'path': __dataPath },

View File

@ -47,7 +47,9 @@
},
"scripts": {
"build": "npm run build --prefix client && npm run build --prefix core && npm run build --prefix csseditor",
"build_client": "npm run build --prefix client",
"watch_client": "npm run watch --prefix client",
"build_core": "npm run build --prefix core",
"watch_core": "npm run watch --prefix core",
"watch_csseditor": "npm run watch --prefix csseditor",
"lint": "eslint -f unix client/src core/src csseditor/src",