mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 09:04:33 +02:00
Add hifi updater checker
This commit is contained in:
parent
8ea586fbe3
commit
845325ba73
2 changed files with 79 additions and 0 deletions
|
@ -4,6 +4,8 @@ const electron = require('electron');
|
|||
const app = electron.app; // Module to control application life.
|
||||
const BrowserWindow = electron.BrowserWindow;
|
||||
|
||||
const notifier = require('node-notifier');
|
||||
const util = require('util');
|
||||
const dialog = electron.dialog;
|
||||
const Menu = require('menu');
|
||||
const Tray = require('tray');
|
||||
|
@ -20,6 +22,8 @@ const request = require('request');
|
|||
const progress = require('request-progress');
|
||||
const osHomeDir = require('os-homedir');
|
||||
|
||||
const updater = require('./modules/hf-updater.js');
|
||||
|
||||
const Config = require('./modules/config').Config;
|
||||
|
||||
const hfprocess = require('./modules/hf-process.js');
|
||||
|
@ -565,6 +569,35 @@ app.on('ready', function() {
|
|||
tray.popUpContextMenu(tray.menu);
|
||||
});
|
||||
|
||||
// if (buildInfo.releaseType == 'PRODUCTION') {
|
||||
if (true) { // TODO: remove, uncomment line above
|
||||
var currentVersion = null;
|
||||
try {
|
||||
currentVersion = parseInt(buildInfo.buildIdentifier);
|
||||
} catch (e) {
|
||||
}
|
||||
currentVersion = 0; // TODO: remove
|
||||
|
||||
if (currentVersion !== null) {
|
||||
const CHECK_FOR_UPDATES_INTERVAL_SECONDS = 20;
|
||||
const updateChecker = new updater.UpdateChecker(currentVersion, CHECK_FOR_UPDATES_INTERVAL_SECONDS);
|
||||
updateChecker.on('update-available', function(latestVersion, url) {
|
||||
notifier.notify({
|
||||
icon: trayIcon,
|
||||
title: 'An update is available!',
|
||||
message: 'High Fidelity version ' + latestVersion + ' is available',
|
||||
wait: true,
|
||||
url: url
|
||||
});
|
||||
});
|
||||
notifier.on('click', function(notifierObject, options) {
|
||||
console.log("Got click", options.url);
|
||||
shell.openExternal(options.url);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
updateTrayMenu(ProcessGroupStates.STOPPED);
|
||||
|
||||
maybeInstallDefaultContentSet(function() {
|
||||
|
|
46
console/src/modules/hf-updater.js
Normal file
46
console/src/modules/hf-updater.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const request = require('request');
|
||||
const extend = require('extend');
|
||||
const util = require('util');
|
||||
const events = require('events');
|
||||
const cheerio = require('cheerio');
|
||||
const os = require('os');
|
||||
|
||||
const platform = os.type() == 'Windows_NT' ? 'windows' : 'mac';
|
||||
|
||||
const BUILDS_URL = 'https://highfidelity.com/builds.xml';
|
||||
|
||||
function UpdateChecker(currentVersion, checkForUpdatesEveryXSeconds) {
|
||||
this.currentVersion = currentVersion;
|
||||
console.log('cur', currentVersion);
|
||||
|
||||
setInterval(this.checkForUpdates.bind(this), checkForUpdatesEveryXSeconds * 1000);
|
||||
this.checkForUpdates();
|
||||
};
|
||||
util.inherits(UpdateChecker, events.EventEmitter);
|
||||
UpdateChecker.prototype = extend(UpdateChecker.prototype, {
|
||||
checkForUpdates: function() {
|
||||
console.log("Checking for updates");
|
||||
request(BUILDS_URL, (error, response, body) => {
|
||||
if (error) {
|
||||
console.log("Error", error);
|
||||
return;
|
||||
}
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
var $ = cheerio.load(body, { xmlMode: true });
|
||||
const latestBuild = $('project[name="interface"] platform[name="' + platform + '"]').children().first();
|
||||
const latestVersion = parseInt(latestBuild.find('version').text());
|
||||
console.log("Latest version is:", latestVersion, this.currentVersion);
|
||||
if (latestVersion > this.currentVersion) {
|
||||
const url = latestBuild.find('url').text();
|
||||
this.emit('update-available', latestVersion, url);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error when checking for updates", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
exports.UpdateChecker = UpdateChecker;
|
Loading…
Reference in a new issue