@todesktop/runtime
Advanced tools
Comparing version 0.1.0-rc.0 to 0.1.0-rc.1
@@ -33,9 +33,9 @@ import * as electronUpdater from "electron-updater"; | ||
restartAndInstall(): void; | ||
private _actuallyPerformCheck; | ||
private _autoCheckOnInterval; | ||
private _autoCheckOnLaunch; | ||
private _check; | ||
private _initializeInternalAutoUpdater; | ||
private _log; | ||
private _check; | ||
private _actuallyPerformCheck; | ||
private _subscribeToElectronEvents; | ||
} |
@@ -15,3 +15,3 @@ "use strict"; | ||
}; | ||
var _autoUpdater, _createdAt, _hasAppFinishedLaunching, _hasUpdateReadyToInstall, _pendingCheckSources, _pendingUpdateCheckPromise, _shouldNotify; | ||
var _autoUpdater, _createdAt, _hasAppFinishedLaunching, _hasNotified, _hasUpdateReadyToInstall, _pendingCheckSources, _pendingUpdateCheckPromise, _shouldNotify; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -24,2 +24,3 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
const once = require("lodash.once"); | ||
const semver = require("semver"); | ||
const logger_1 = require("./logger"); | ||
@@ -39,2 +40,3 @@ var BuiltInSources; | ||
_hasAppFinishedLaunching.set(this, false); | ||
_hasNotified.set(this, false); | ||
_hasUpdateReadyToInstall.set(this, false); | ||
@@ -80,79 +82,2 @@ _pendingCheckSources.set(this, []); | ||
} | ||
_autoCheckOnInterval(interval) { | ||
const checkAfterTimeout = () => { | ||
this._log("checkAfterTimeout"); | ||
setTimeout(async () => { | ||
try { | ||
await this._check({ | ||
source: BuiltInSources.autoCheckOnInterval, | ||
}); | ||
checkAfterTimeout(); | ||
} | ||
catch (e) { | ||
// Ignore and continute to check on interval | ||
checkAfterTimeout(); | ||
} | ||
}, interval); | ||
}; | ||
checkAfterTimeout(); | ||
} | ||
async _autoCheckOnLaunch() { | ||
try { | ||
await this._check({ | ||
source: BuiltInSources.autoCheckOnLaunch, | ||
}); | ||
} | ||
catch (e) { | ||
// Ignore. Auto-check on interval and programmatic API still supported | ||
} | ||
} | ||
_initializeInternalAutoUpdater() { | ||
__classPrivateFieldSet(this, _autoUpdater, electronUpdater.autoUpdater); | ||
} | ||
_log(...args) { | ||
if (!logger_1.default) { | ||
return; | ||
} | ||
let timeSinceCreatedAt; | ||
// This can fail when there's a ReferenceError in a test and Date is overwritten | ||
try { | ||
timeSinceCreatedAt = ` (${Date.now() - __classPrivateFieldGet(this, _createdAt)}ms)`; | ||
} | ||
catch (e) { | ||
// Ignore | ||
} | ||
logger_1.default.info(`AutoUpdater (${electron.app.name})${timeSinceCreatedAt}: ` + | ||
args.map((arg) => JSON.stringify(arg)).join(" ")); | ||
} | ||
async _check({ source, }) { | ||
/* | ||
We collect the sources and emit them with the update-available event. | ||
Other noteworthy bits: | ||
- The update check promise is reused by electron-updater. | ||
- We don't want more than one event emitted. | ||
- There's no sorting or de-duplication of the sources, on purpose. | ||
*/ | ||
__classPrivateFieldGet(this, _pendingCheckSources).push(source); | ||
this._log("_check called", { | ||
source, | ||
sources: __classPrivateFieldGet(this, _pendingCheckSources), | ||
}); | ||
if (__classPrivateFieldGet(this, _pendingUpdateCheckPromise)) { | ||
return __classPrivateFieldGet(this, _pendingUpdateCheckPromise); | ||
} | ||
const onEnd = () => { | ||
this._log("onEnd called"); | ||
__classPrivateFieldSet(this, _pendingUpdateCheckPromise, null); | ||
}; | ||
__classPrivateFieldSet(this, _pendingUpdateCheckPromise, this._actuallyPerformCheck() | ||
.then((updateCheckResult) => { | ||
onEnd(); | ||
return updateCheckResult; | ||
}) | ||
.catch((e) => { | ||
onEnd(); | ||
throw e; | ||
})); | ||
return __classPrivateFieldGet(this, _pendingUpdateCheckPromise); | ||
} | ||
async _actuallyPerformCheck() { | ||
@@ -176,4 +101,16 @@ this._log("_actuallyPerformCheck called"); | ||
__classPrivateFieldSet(this, _pendingCheckSources, []); | ||
let isThereAnUpdate = false; | ||
if (updateCheckResult && updateCheckResult.updateInfo) { | ||
// We need to make sure the version is actually newer | ||
const currentVersion = electron.app.getVersion(); | ||
const newVersion = updateCheckResult.updateInfo.version; | ||
this._log("Analysing autoUpdater.checkForUpdates result", { | ||
currentVersion, | ||
newVersion, | ||
updateInfo: updateCheckResult.updateInfo, | ||
}); | ||
isThereAnUpdate = semver.gt(newVersion, currentVersion); | ||
} | ||
// No update available; exit early | ||
if (!updateCheckResult || !updateCheckResult.updateInfo) { | ||
if (!isThereAnUpdate) { | ||
// To be safe | ||
@@ -196,4 +133,7 @@ __classPrivateFieldSet(this, _hasUpdateReadyToInstall, false); | ||
const emitPromise = this.emitAsync("update-available", eventPayload); | ||
// If they haven't disabled the default behaviour | ||
if (__classPrivateFieldGet(this, _shouldNotify)) { | ||
/* | ||
If they haven't disabled the default behaviour or they've already been notified of an update | ||
(we don't want to notify them on interval) | ||
*/ | ||
if (__classPrivateFieldGet(this, _shouldNotify) && !__classPrivateFieldGet(this, _hasNotified)) { | ||
/* | ||
@@ -212,2 +152,3 @@ The default behaviour is to notify the end user. | ||
} | ||
__classPrivateFieldSet(this, _hasNotified, true); | ||
const notification = new electron.Notification({ | ||
@@ -253,2 +194,79 @@ title: "A new update is ready to install", | ||
} | ||
_autoCheckOnInterval(interval) { | ||
const checkAfterTimeout = () => { | ||
this._log("checkAfterTimeout"); | ||
setTimeout(async () => { | ||
try { | ||
await this._check({ | ||
source: BuiltInSources.autoCheckOnInterval, | ||
}); | ||
checkAfterTimeout(); | ||
} | ||
catch (e) { | ||
// Ignore and continute to check on interval | ||
checkAfterTimeout(); | ||
} | ||
}, interval); | ||
}; | ||
checkAfterTimeout(); | ||
} | ||
async _autoCheckOnLaunch() { | ||
try { | ||
await this._check({ | ||
source: BuiltInSources.autoCheckOnLaunch, | ||
}); | ||
} | ||
catch (e) { | ||
// Ignore. Auto-check on interval and programmatic API still supported | ||
} | ||
} | ||
async _check({ source, }) { | ||
/* | ||
We collect the sources and emit them with the update-available event. | ||
Other noteworthy bits: | ||
- The update check promise is reused by electron-updater. | ||
- We don't want more than one event emitted. | ||
- There's no sorting or de-duplication of the sources, on purpose. | ||
*/ | ||
__classPrivateFieldGet(this, _pendingCheckSources).push(source); | ||
this._log("_check called", { | ||
source, | ||
sources: __classPrivateFieldGet(this, _pendingCheckSources), | ||
}); | ||
if (__classPrivateFieldGet(this, _pendingUpdateCheckPromise)) { | ||
return __classPrivateFieldGet(this, _pendingUpdateCheckPromise); | ||
} | ||
const onEnd = () => { | ||
this._log("onEnd called"); | ||
__classPrivateFieldSet(this, _pendingUpdateCheckPromise, null); | ||
}; | ||
__classPrivateFieldSet(this, _pendingUpdateCheckPromise, this._actuallyPerformCheck() | ||
.then((updateCheckResult) => { | ||
onEnd(); | ||
return updateCheckResult; | ||
}) | ||
.catch((e) => { | ||
onEnd(); | ||
throw e; | ||
})); | ||
return __classPrivateFieldGet(this, _pendingUpdateCheckPromise); | ||
} | ||
_initializeInternalAutoUpdater() { | ||
__classPrivateFieldSet(this, _autoUpdater, electronUpdater.autoUpdater); | ||
} | ||
_log(...args) { | ||
if (!logger_1.default) { | ||
return; | ||
} | ||
let timeSinceCreatedAt; | ||
// This can fail when there's a ReferenceError in a test and Date is overwritten | ||
try { | ||
timeSinceCreatedAt = ` (${Date.now() - __classPrivateFieldGet(this, _createdAt)}ms)`; | ||
} | ||
catch (e) { | ||
// Ignore | ||
} | ||
logger_1.default.info(`AutoUpdater (${electron.app.name})${timeSinceCreatedAt}: ` + | ||
args.map((arg) => JSON.stringify(arg)).join(" ")); | ||
} | ||
_subscribeToElectronEvents() { | ||
@@ -261,2 +279,2 @@ electron.autoUpdater.on("before-quit-for-update", (...args) => { | ||
exports.default = AutoUpdater; | ||
_autoUpdater = new WeakMap(), _createdAt = new WeakMap(), _hasAppFinishedLaunching = new WeakMap(), _hasUpdateReadyToInstall = new WeakMap(), _pendingCheckSources = new WeakMap(), _pendingUpdateCheckPromise = new WeakMap(), _shouldNotify = new WeakMap(); | ||
_autoUpdater = new WeakMap(), _createdAt = new WeakMap(), _hasAppFinishedLaunching = new WeakMap(), _hasNotified = new WeakMap(), _hasUpdateReadyToInstall = new WeakMap(), _pendingCheckSources = new WeakMap(), _pendingUpdateCheckPromise = new WeakMap(), _shouldNotify = new WeakMap(); |
@@ -18,5 +18,5 @@ "use strict"; | ||
const extraTransports = []; | ||
// if (process.env.CI && shouldDebugOnCI) { | ||
extraTransports.push(new winston.transports.Console({ format: winston.format.simple() })); | ||
// } | ||
if (process.env.CI && shouldDebugOnCI) { | ||
extraTransports.push(new winston.transports.Console({ format: winston.format.simple() })); | ||
} | ||
logger = winston.createLogger({ | ||
@@ -23,0 +23,0 @@ level: "info", |
{ | ||
"private": false, | ||
"name": "@todesktop/runtime", | ||
"version": "0.1.0-rc.0", | ||
"version": "0.1.0-rc.1", | ||
"license": "MIT", | ||
@@ -29,3 +29,4 @@ "author": "Adam Lynch <contact@adamlynch.com> (http://adamlynch.com/)", | ||
"eventemitter2": "^6.3.1", | ||
"lodash.once": "^4.1.1" | ||
"lodash.once": "^4.1.1", | ||
"semver": "^7.3.2" | ||
}, | ||
@@ -32,0 +33,0 @@ "devDependencies": { |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20388
397
0
4
4
+ Addedsemver@^7.3.2