Skip to content

Commit

Permalink
Streamline code to clean logs based on version number
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Jul 20, 2018
1 parent 12f1932 commit f2a63c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@
await storage.put('version', currentVersion);

if (newVersion) {
if (currentVersion === '1.14.2' || currentVersion === '1.15.0-beta.2') {
if (
lastVersion &&
window.isBeforeVersion(lastVersion, 'v1.15.0-beta.4')
) {
await window.Signal.Logs.deleteAll();
window.restart();
}
Expand Down
13 changes: 13 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
console.log('preload');

const electron = require('electron');
const semver = require('semver');

const { deferredToPromise } = require('./js/modules/deferred_to_promise');

Expand All @@ -29,6 +30,18 @@ window.getExpiration = () => config.buildExpiration;
window.getNodeVersion = () => config.node_version;
window.getHostName = () => config.hostname;

window.isBeforeVersion = (toCheck, baseVersion) => {
try {
return semver.lt(toCheck, baseVersion);
} catch (error) {
console.log(
`isBeforeVersion error: toCheck: ${toCheck}, baseVersion: ${baseVersion}`,
error && error.stack ? error.stack : error
);
return true;
}
};

window.wrapDeferred = deferredToPromise;

const ipc = electron.ipcRenderer;
Expand Down

0 comments on commit f2a63c9

Please sign in to comment.