@todesktop/runtime
Advanced tools
Comparing version 1.2.2-0 to 1.2.2-1
@@ -28,3 +28,2 @@ import { EventEmitter2 } from "eventemitter2"; | ||
private _hasAppFinishedLaunching; | ||
private _hasNotified; | ||
private _hasUpdateReadyToInstall; | ||
@@ -35,6 +34,5 @@ private readonly _isActive; | ||
private _pendingUpdateCheckPromise; | ||
private _shouldNotify; | ||
private _updaterAgent; | ||
constructor({ autoCheckInterval, // 10 min | ||
logger, shouldAutoCheckOnLaunch, shouldNotify, }: AutoUpdaterConstructorOptions); | ||
logger, shouldAutoCheckOnLaunch, }: AutoUpdaterConstructorOptions); | ||
checkForUpdates({ source, }?: { | ||
@@ -41,0 +39,0 @@ source?: Source; |
@@ -19,3 +19,2 @@ "use strict"; | ||
const fs = require("fs"); | ||
const once = require("lodash.once"); | ||
const path = require("path"); | ||
@@ -34,7 +33,6 @@ const getConfig_1 = require("./getConfig"); | ||
constructor({ autoCheckInterval = 10 * 60 * 1000, // 10 min | ||
logger, shouldAutoCheckOnLaunch = true, shouldNotify = true, }) { | ||
logger, shouldAutoCheckOnLaunch = true, }) { | ||
super(); | ||
this._createdAt = Date.now(); | ||
this._hasAppFinishedLaunching = false; | ||
this._hasNotified = false; | ||
this._hasUpdateReadyToInstall = false; | ||
@@ -44,3 +42,2 @@ this._isActive = electron.app.isPackaged; | ||
this._logger = logger; | ||
this._shouldNotify = shouldNotify; | ||
if (this._isActive) { | ||
@@ -136,59 +133,21 @@ this._initializeUpdaterAgent(); | ||
this._log("debug", "Emitting update-downloaded event"); | ||
const emitPromise = this.emitAsync("update-downloaded", eventPayload); | ||
/* | ||
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 (this._shouldNotify && !this._hasNotified) { | ||
/* | ||
The default behaviour is to notify the end user. | ||
We allow this to be cancelled by returning false from any event listener (plain/Promise), | ||
within a time window. If the time elapses, we carry on with the default behaviour and | ||
ignore the listener response(s). | ||
*/ | ||
// This is needed in case they plainly return false and then the setTimeout fires afterwards | ||
let hasReturnedFalseInEventListener = false; | ||
// This will notify the first time it's called. Subsequent calls are ignored | ||
const notify = once(() => { | ||
if (hasReturnedFalseInEventListener) { | ||
return; | ||
} | ||
this._hasNotified = true; | ||
const notification = new electron.Notification({ | ||
title: "A new update is ready to install", | ||
body: `${electron.app.name} version ${updateInfo.version} has been downloaded and will be automatically installed on exit`, | ||
}); | ||
notification.show(); | ||
}); | ||
// They have a time-limited window to respond. Try to notify when it ends | ||
(0, setTimeout_1.default)(() => { | ||
Promise.race([ | ||
this.emitAsync("update-downloaded", eventPayload), | ||
new Promise((r) => { | ||
this._log("debug", "before notify call in setTimeout"); | ||
notify(); | ||
}, 500); | ||
emitPromise | ||
.catch((e) => { | ||
this._log("debug", "event callback errored", e); | ||
// Ignore the error but immediately continue with the default behaviour | ||
notify(); | ||
}) | ||
.then((responses = []) => { | ||
// Ignore if they have returned false from any listener | ||
if (responses.some((response) => response === false)) { | ||
hasReturnedFalseInEventListener = true; | ||
return; | ||
} | ||
setTimeout(r, 500); | ||
}), | ||
]) | ||
.then((emitResult) => { | ||
if (!Array.isArray(emitResult) || !emitResult.includes(false)) { | ||
this._log("debug", "calling notify after event listener Promise settled"); | ||
// This won't do anything if they took too long to respond | ||
notify(); | ||
}); | ||
} | ||
else { | ||
// i.e. !shouldNotify | ||
// Reset the collected sources | ||
this._pendingCheckSources = []; | ||
emitPromise.catch((e) => { | ||
this._log("debug", "event callback errored", e); | ||
// ignore | ||
}); | ||
} | ||
this.emit("notify-after-update-downloaded", eventPayload); | ||
} | ||
}) | ||
.catch((e) => { | ||
this._log("debug", "Error occurred in update-downloaded handler", e); | ||
this.emit("notify-after-update-downloaded", eventPayload); | ||
}); | ||
// Reset the collected sources | ||
this._pendingCheckSources = []; | ||
// Return as soon as possible (don't wait for listener responses) | ||
@@ -308,3 +267,3 @@ return { updateInfo }; | ||
} | ||
firstArgument += `AutoUpdater (${electron.app.name})${timeSinceCreatedAt}:`; | ||
firstArgument = `AutoUpdater (${electron.app.name})${timeSinceCreatedAt}:`; | ||
} | ||
@@ -311,0 +270,0 @@ else { |
import AutoUpdater from "./AutoUpdater"; | ||
import { LoggerInterface } from "./Logger"; | ||
import { UpdateReadyAction } from "./Notifier"; | ||
declare type initParams = { | ||
autoUpdater?: boolean; | ||
customLogger?: LoggerInterface; | ||
updateReadyAction?: UpdateReadyAction; | ||
}; | ||
@@ -7,0 +9,0 @@ declare class ToDesktop { |
@@ -6,2 +6,3 @@ "use strict"; | ||
const MockedAutoUpdater_1 = require("./MockedAutoUpdater"); | ||
const Notifier_1 = require("./Notifier"); | ||
class ToDesktop { | ||
@@ -20,18 +21,18 @@ constructor() { | ||
} | ||
_init({ autoUpdater = true, customLogger, } = {}) { | ||
_init({ autoUpdater = true, customLogger, updateReadyAction, } = {}) { | ||
const logger = new Logger_1.default(customLogger); | ||
let autoUpdaterInstance; | ||
if (autoUpdater) { | ||
return new AutoUpdater_1.default({ | ||
logger, | ||
}); | ||
autoUpdaterInstance = new AutoUpdater_1.default({ logger }); | ||
new Notifier_1.default({ autoUpdater: autoUpdaterInstance, updateReadyAction }); | ||
} | ||
else { | ||
// Disables the default behaviour | ||
return new AutoUpdater_1.default({ | ||
autoUpdaterInstance = new AutoUpdater_1.default({ | ||
autoCheckInterval: 0, | ||
logger, | ||
shouldAutoCheckOnLaunch: false, | ||
shouldNotify: false, | ||
}); | ||
} | ||
return autoUpdaterInstance; | ||
} | ||
@@ -38,0 +39,0 @@ } |
@@ -1,1 +0,1 @@ | ||
export declare const CLIENT_VERSION = "1.2.2-0"; | ||
export declare const CLIENT_VERSION = "1.2.2-1"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CLIENT_VERSION = void 0; | ||
exports.CLIENT_VERSION = "1.2.2-0"; | ||
exports.CLIENT_VERSION = "1.2.2-1"; |
@@ -7,3 +7,3 @@ { | ||
"name": "@todesktop/runtime", | ||
"version": "1.2.2-0", | ||
"version": "1.2.2-1", | ||
"license": "MIT", | ||
@@ -10,0 +10,0 @@ "author": "ToDesktop <hi@todesktop.com> (https://www.todesktop.com/)", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
66865
29
1171
2