basic manual update stuff + update check bar

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2017-06-03 15:12:46 +01:00
parent 0e6012ad45
commit efc68c078e
5 changed files with 139 additions and 11 deletions

View file

@ -17,7 +17,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import VectorBasePlatform from './VectorBasePlatform';
import VectorBasePlatform, {updateStateEnum} from './VectorBasePlatform';
import dis from 'matrix-react-sdk/lib/dispatcher';
import { _t } from 'matrix-react-sdk/lib/languageHandler';
import q from 'q';
@ -66,6 +66,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
constructor() {
super();
dis.register(_onAction);
this.updatable = Boolean(remote.autoUpdater.getFeedURL());
}
getHumanReadableName(): string {
@ -137,10 +138,28 @@ export default class ElectronPlatform extends VectorBasePlatform {
return q(remote.app.getVersion());
}
pollForUpdate() {
// In electron we control the update process ourselves, since
// it needs to run in the main process, so we just run the timer
// loop in the main electron process instead.
checkForUpdate() { // manual update check for this platform
const deferred = q.defer();
const _onUpdateAvailable = function() {
electron.autoUpdater.removeListener('update-not-available', _onUpdateNotAvailable);
deferred.resolve(updateStateEnum.Downloading);
}
const _onUpdateNotAvailable = function() {
electron.autoUpdater.removeListener('update-available', _onUpdateAvailable);
deferred.resolve(updateStateEnum.NotAvailable);
}
electron.autoUpdater.once('update-available', _onUpdateAvailable);
electron.autoUpdater.once('update-not-available', _onUpdateNotAvailable);
electron.ipcRenderer.send('checkForUpdates');
return deferred.promise.timeout(10000).catch(() => {
electron.autoUpdater.removeListener('update-not-available', _onUpdateNotAvailable);
electron.autoUpdater.removeListener('update-available', _onUpdateAvailable);
return updateStateEnum.Error;
});
}
installUpdate() {

View file

@ -22,6 +22,13 @@ import { _t } from 'matrix-react-sdk/lib/languageHandler';
import Favico from 'favico.js';
export const updateStateEnum = {
Error: -1,
NotAvailable: 0,
Downloading: 1,
Ready: 2,
};
/**
* Vector-specific extensions to the BasePlatform template
*/
@ -35,6 +42,7 @@ export default class VectorBasePlatform extends BasePlatform {
// so we'd need to fix that if enabling the animation.
this.favicon = new Favico({animation: 'none'});
this._updateFavicon();
this.updatable = true;
}
getHumanReadableName(): string {
@ -80,13 +88,21 @@ export default class VectorBasePlatform extends BasePlatform {
startUpdater() {
}
/**
* Whether we can call checkForUpdate on this platform build
*/
canSelfUpdate(): boolean {
return this.updatable;
}
/**
* Check for the availability of an update to the version of the
* app that's currently running.
* If an update is available, this function should dispatch the
* 'new_version' action.
* @returns Promise<updateStateEnum>
*/
pollForUpdate() {
checkForUpdate(): Promise<number> {
}
/**

View file

@ -17,7 +17,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import VectorBasePlatform from './VectorBasePlatform';
import VectorBasePlatform, {updateStateEnum} from './VectorBasePlatform';
import request from 'browser-request';
import dis from 'matrix-react-sdk/lib/dispatcher.js';
import { _t } from 'matrix-react-sdk/lib/languageHandler';
@ -135,12 +135,12 @@ export default class WebPlatform extends VectorBasePlatform {
}
startUpdater() {
this.pollForUpdate();
setInterval(this.pollForUpdate, POKE_RATE_MS);
this.checkForUpdate();
setInterval(this.checkForUpdate, POKE_RATE_MS);
}
pollForUpdate() {
this._getVersion().done((ver) => {
checkForUpdate() {
return this._getVersion().then((ver) => {
if (this.runningVersion === null) {
this.runningVersion = ver;
} else if (this.runningVersion !== ver) {
@ -149,9 +149,12 @@ export default class WebPlatform extends VectorBasePlatform {
currentVersion: this.runningVersion,
newVersion: ver,
});
return updateStateEnum.Ready;
}
return updateStateEnum.NotAvailable;
}, (err) => {
console.error("Failed to poll for update", err);
return updateStateEnum.Error;
});
}