Merge pull request #758 from neuroscr/version-check
Version check, de-signal.org-ificationpull/780/head
commit
5bbd136493
@ -1,22 +1,62 @@
|
|||||||
|
/* global LokiAppDotNetServerAPI, LokiFileServerAPI, semver, log */
|
||||||
// eslint-disable-next-line func-names
|
// eslint-disable-next-line func-names
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
let BUILD_EXPIRATION = 0;
|
// hold last result
|
||||||
try {
|
let expiredVersion = null;
|
||||||
BUILD_EXPIRATION = parseInt(window.getExpiration(), 10);
|
|
||||||
if (BUILD_EXPIRATION) {
|
window.tokenlessFileServerAdnAPI = new LokiAppDotNetServerAPI(
|
||||||
window.log.info(
|
'', // no pubkey needed
|
||||||
'Build expires: ',
|
window.getDefaultFileServer()
|
||||||
new Date(BUILD_EXPIRATION).toISOString()
|
);
|
||||||
);
|
window.tokenlessFileServerAdnAPI.pubKey = window.Signal.Crypto.base64ToArrayBuffer(
|
||||||
|
LokiFileServerAPI.secureRpcPubKey
|
||||||
|
);
|
||||||
|
|
||||||
|
const checkForUpgrades = async () => {
|
||||||
|
const response = await window.tokenlessFileServerAdnAPI.serverRequest(
|
||||||
|
'loki/v1/version/client/desktop'
|
||||||
|
);
|
||||||
|
if (response && response.response) {
|
||||||
|
const latestVer = semver.clean(response.response.data[0][0]);
|
||||||
|
if (semver.valid(latestVer)) {
|
||||||
|
const ourVersion = window.getVersion();
|
||||||
|
if (latestVer === ourVersion) {
|
||||||
|
log.info('You have the latest version', latestVer);
|
||||||
|
// change the following to true ot test/see expiration banner
|
||||||
|
expiredVersion = false;
|
||||||
|
} else {
|
||||||
|
// expire if latest is newer than current
|
||||||
|
expiredVersion = semver.gt(latestVer, ourVersion);
|
||||||
|
if (expiredVersion) {
|
||||||
|
log.info('There is a newer version available', latestVer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// give it a minute
|
||||||
|
log.warn('Could not check to see if newer version is available');
|
||||||
|
setTimeout(async () => {
|
||||||
|
await checkForUpgrades();
|
||||||
|
}, 60 * 1000); // wait a minute
|
||||||
}
|
}
|
||||||
} catch (e) {
|
// no message logged means serverRequest never returned...
|
||||||
// nothing
|
};
|
||||||
}
|
checkForUpgrades();
|
||||||
|
|
||||||
window.extension = window.extension || {};
|
window.extension = window.extension || {};
|
||||||
|
|
||||||
window.extension.expired = () =>
|
window.extension.expired = cb => {
|
||||||
BUILD_EXPIRATION && Date.now() > BUILD_EXPIRATION;
|
if (expiredVersion === null) {
|
||||||
|
// just give it another second
|
||||||
|
log.info('Delaying expire banner determination for 1s');
|
||||||
|
setTimeout(() => {
|
||||||
|
window.extension.expired(cb);
|
||||||
|
}, 1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// yes we know
|
||||||
|
cb(expiredVersion);
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue