Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@todesktop/runtime

Package Overview
Dependencies
Maintainers
3
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@todesktop/runtime - npm Package Compare versions

Comparing version 1.5.7 to 1.6.0

75

dist/AutoUpdater.d.ts

@@ -1,7 +0,6 @@

import type { AllPublishOptions, PublishConfiguration } from "builder-util-runtime";
import { ProgressInfo } from "electron-updater";
import { CancelablePromise, EventEmitter2, GeneralEventEmitter, ListenToOptions, WaitForFilter, WaitForOptions } from "eventemitter2";
import type { PublishConfiguration, AllPublishOptions } from "builder-util-runtime";
import { LoggerInterface } from "./Logger";
import { TDUpdateInfo } from "./updaterAgents";
import { CheckForUpdatesInput, RestartAndInstallInput, Source } from "./types";
export declare type AutoUpdaterConstructorOptions = {

@@ -13,4 +12,9 @@ readonly autoCheckInterval?: number;

};
export declare enum BuiltInSources {
autoCheckOnLaunch = "auto-check-on-launch",
autoCheckOnInterval = "auto-check-on-interval",
programmaticCall = "programmatic-call"
}
export declare type Source = BuiltInSources | string;
export declare type UpdateAvailableEventPayload = {
readonly disableUpdateReadyAction: boolean;
readonly sources: Source[];

@@ -34,4 +38,8 @@ readonly updateInfo: TDUpdateInfo | null;

logger, shouldAutoCheckOnLaunch, }: AutoUpdaterConstructorOptions);
checkForUpdates({ source, disableUpdateReadyAction, }?: CheckForUpdatesInput): Promise<UpdateCheckResult>;
restartAndInstall({ isSilent, }?: RestartAndInstallInput): void;
checkForUpdates({ source, }?: {
source?: Source;
}): Promise<UpdateCheckResult>;
restartAndInstall({ isSilent, }?: {
isSilent?: boolean;
}): void;
setFeedURL(options: PublishConfiguration | AllPublishOptions | string): void;

@@ -48,31 +56,30 @@ private _actuallyPerformCheck;

declare interface AutoUpdater {
addListener<E extends keyof AutoUpdaterEvents>(event: E, listener: AutoUpdaterEvents[E]): this;
emit<E extends keyof AutoUpdaterEvents>(event: E, ...args: Parameters<AutoUpdaterEvents[E]>): boolean;
emitAsync<E extends keyof AutoUpdaterEvents>(event: E, ...args: Parameters<AutoUpdaterEvents[E]>): Promise<unknown[]>;
hasListeners<E extends keyof AutoUpdaterEvents>(event?: E): boolean;
eventNames(): (keyof AutoUpdaterEvents | string)[];
listenerCount<E extends keyof AutoUpdaterEvents>(event: E): number;
listeners<E extends keyof AutoUpdaterEvents>(event: E): AutoUpdaterEvents[E][];
listenersAny<E extends keyof AutoUpdaterEvents>(): AutoUpdaterEvents[E][];
listenTo<E extends keyof AutoUpdaterEvents>(target: GeneralEventEmitter, events: E | E[], options?: ListenToOptions): this;
listenTo<E extends keyof AutoUpdaterEvents>(target: GeneralEventEmitter, events: Record<E, AutoUpdaterEvents[E]>, options?: ListenToOptions): this;
many<E extends keyof AutoUpdaterEvents>(event: E, timesToListen: number, listener: AutoUpdaterEvents[E], options?: boolean | object): this;
off<E extends keyof AutoUpdaterEvents>(event: E, listener: AutoUpdaterEvents[E]): this;
offAny<E extends keyof AutoUpdaterEvents>(listener: AutoUpdaterEvents[E]): this;
on<E extends keyof AutoUpdaterEvents>(event: E, listener: AutoUpdaterEvents[E]): this;
onAny<E extends keyof AutoUpdaterEvents>(listener: (event: E, values: unknown[]) => void): this;
once<E extends keyof AutoUpdaterEvents>(event: E, listener: AutoUpdaterEvents[E]): this;
prependAny<E extends keyof AutoUpdaterEvents>(listener: (event: E, values: unknown[]) => void): this;
prependListener<E extends keyof AutoUpdaterEvents>(event: E, listener: AutoUpdaterEvents[E]): this;
prependMany<E extends keyof AutoUpdaterEvents>(event: E, timesToListen: number, listener: AutoUpdaterEvents[E], options?: boolean | object): this;
prependOnceListener<E extends keyof AutoUpdaterEvents>(event: E, listener: AutoUpdaterEvents[E]): this;
removeAllListeners<E extends keyof AutoUpdaterEvents>(event?: E): this;
removeListener<E extends keyof AutoUpdaterEvents>(event: E, listener: AutoUpdaterEvents[E]): this;
stopListeningTo<E extends keyof AutoUpdaterEvents>(target?: GeneralEventEmitter, event?: E): boolean;
waitFor<E extends keyof AutoUpdaterEvents>(event: E, timeout?: number): CancelablePromise<Parameters<AutoUpdaterEvents[E]>>;
waitFor<E extends keyof AutoUpdaterEvents>(event: E, filter?: WaitForFilter): CancelablePromise<Parameters<AutoUpdaterEvents[E]>>;
waitFor<E extends keyof AutoUpdaterEvents>(event: E, options?: WaitForOptions): CancelablePromise<Parameters<AutoUpdaterEvents[E]>>;
addListener<E extends keyof EventMap>(event: E, listener: EventMap[E]): this;
emit<E extends keyof EventMap>(event: E, ...args: Parameters<EventMap[E]>): boolean;
emitAsync<E extends keyof EventMap>(event: E, ...args: Parameters<EventMap[E]>): Promise<unknown[]>;
hasListeners<E extends keyof EventMap>(event?: E): boolean;
eventNames(): (keyof EventMap | string)[];
listenerCount<E extends keyof EventMap>(event: E): number;
listeners<E extends keyof EventMap>(event: E): EventMap[E][];
listenersAny<E extends keyof EventMap>(): EventMap[E][];
listenTo<E extends keyof EventMap>(target: GeneralEventEmitter, events: E | E[], options?: ListenToOptions): this;
listenTo<E extends keyof EventMap>(target: GeneralEventEmitter, events: Record<E, EventMap[E]>, options?: ListenToOptions): this;
many<E extends keyof EventMap>(event: E, timesToListen: number, listener: EventMap[E], options?: boolean | object): this;
off<E extends keyof EventMap>(event: E, listener: EventMap[E]): this;
offAny<E extends keyof EventMap>(listener: EventMap[E]): this;
on<E extends keyof EventMap>(event: E, listener: EventMap[E]): this;
onAny<E extends keyof EventMap>(listener: (event: E, values: unknown[]) => void): this;
once<E extends keyof EventMap>(event: E, listener: EventMap[E]): this;
prependAny<E extends keyof EventMap>(listener: (event: E, values: unknown[]) => void): this;
prependListener<E extends keyof EventMap>(event: E, listener: EventMap[E]): this;
prependMany<E extends keyof EventMap>(event: E, timesToListen: number, listener: EventMap[E], options?: boolean | object): this;
prependOnceListener<E extends keyof EventMap>(event: E, listener: EventMap[E]): this;
removeAllListeners<E extends keyof EventMap>(event?: E): this;
removeListener<E extends keyof EventMap>(event: E, listener: EventMap[E]): this;
stopListeningTo<E extends keyof EventMap>(target?: GeneralEventEmitter, event?: E): boolean;
waitFor<E extends keyof EventMap>(event: E, timeout?: number): CancelablePromise<Parameters<EventMap[E]>>;
waitFor<E extends keyof EventMap>(event: E, filter?: WaitForFilter): CancelablePromise<Parameters<EventMap[E]>>;
waitFor<E extends keyof EventMap>(event: E, options?: WaitForOptions): CancelablePromise<Parameters<EventMap[E]>>;
}
export declare type AutoUpdaterEvents = {
["error"](error: Error, message?: string): void;
interface EventMap {
["before-quit-for-update"](...args: unknown[]): void;

@@ -85,2 +92,2 @@ ["checking-for-update"](): void;

["update-not-available"](info: TDUpdateInfo): void;
};
}

@@ -12,2 +12,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.BuiltInSources = void 0;
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const electron = require("electron");

@@ -22,3 +25,8 @@ const electronUpdater = require("electron-updater");

const version_1 = require("./version");
const types_1 = require("./types");
var BuiltInSources;
(function (BuiltInSources) {
BuiltInSources["autoCheckOnLaunch"] = "auto-check-on-launch";
BuiltInSources["autoCheckOnInterval"] = "auto-check-on-interval";
BuiltInSources["programmaticCall"] = "programmatic-call";
})(BuiltInSources = exports.BuiltInSources || (exports.BuiltInSources = {}));
class AutoUpdater extends eventemitter2_1.EventEmitter2 {

@@ -31,5 +39,14 @@ constructor({ autoCheckInterval = 10 * 60 * 1000, // 10 min

this._hasUpdateReadyToInstall = false;
this._isActive = electron.app.isPackaged;
this._isActive = true;
this._pendingCheckSources = [];
this._logger = logger;
let inactiveReason = "";
if (!electron.app.isPackaged) {
this._isActive = false;
inactiveReason = "application is not packaged";
}
if (process.platform === "linux" && !process.env.APPIMAGE) {
this._isActive = false;
inactiveReason = "application is not in AppImage";
}
if (this._isActive) {

@@ -39,3 +56,3 @@ this._initializeUpdaterAgent();

else {
const message = "@todesktop/runtime: skipping autoUpdater initialization because application is not packed.";
const message = `@todesktop/runtime: skipping autoUpdater initialization because ${inactiveReason}.`;
console.log(message);

@@ -62,3 +79,3 @@ this._log("info", message);

}
checkForUpdates({ source = types_1.BuiltInSources.programmaticCall, disableUpdateReadyAction = false, } = {}) {
checkForUpdates({ source = BuiltInSources.programmaticCall, } = {}) {
return __awaiter(this, void 0, void 0, function* () {

@@ -76,3 +93,3 @@ this._log("info", ".checkForUpdates called");

}
return yield this._check({ source, disableUpdateReadyAction });
return yield this._check({ source });
});

@@ -102,3 +119,3 @@ }

}
_actuallyPerformCheck({ disableUpdateReadyAction, }) {
_actuallyPerformCheck() {
return __awaiter(this, void 0, void 0, function* () {

@@ -127,3 +144,2 @@ this._log("debug", "_actuallyPerformCheck called");

updateInfo,
disableUpdateReadyAction,
};

@@ -160,4 +176,3 @@ this._log("debug", "Emitting update-downloaded event");

yield this._check({
source: types_1.BuiltInSources.autoCheckOnInterval,
disableUpdateReadyAction: false,
source: BuiltInSources.autoCheckOnInterval,
});

@@ -180,4 +195,3 @@ checkAfterTimeout();

yield this._check({
source: types_1.BuiltInSources.autoCheckOnLaunch,
disableUpdateReadyAction: false,
source: BuiltInSources.autoCheckOnLaunch,
});

@@ -191,3 +205,3 @@ }

}
_check({ source, disableUpdateReadyAction, }) {
_check({ source, }) {
return __awaiter(this, void 0, void 0, function* () {

@@ -212,5 +226,3 @@ /*

};
this._pendingUpdateCheckPromise = this._actuallyPerformCheck({
disableUpdateReadyAction,
})
this._pendingUpdateCheckPromise = this._actuallyPerformCheck()
.then((updateCheckResult) => {

@@ -284,6 +296,2 @@ onEnd();

});
electronUpdater.autoUpdater.on("error", (error, message) => {
this._log("info", "error");
this.emit("error", error, message);
});
electronUpdater.autoUpdater.on("checking-for-update", () => {

@@ -293,5 +301,5 @@ this._log("info", "checking-for-update");

});
electronUpdater.autoUpdater.on("update-not-available", (info) => {
this._log("info", "update-not-available", info);
this.emit("update-not-available", info);
electronUpdater.autoUpdater.on("download-progress", (info) => {
this._log("info", "download-progress", info);
this.emit("download-progress", info);
});

@@ -302,6 +310,5 @@ electronUpdater.autoUpdater.on("update-available", (info) => {

});
// we emit update-downloaded ourselves in `_actuallyPerformCheck`
electronUpdater.autoUpdater.on("download-progress", (info) => {
this._log("info", "download-progress", info);
this.emit("download-progress", info);
electronUpdater.autoUpdater.on("update-not-available", (info) => {
this._log("info", "update-not-available", info);
this.emit("update-not-available", info);
});

@@ -308,0 +315,0 @@ }

import AutoUpdater from "./AutoUpdater";
import { LoggerInterface } from "./Logger";
import { UpdateReadyAction } from "./types";
declare type ToDesktopRuntimeParams = {
import { UpdateReadyAction } from "./Notifier";
declare type initParams = {
autoUpdater?: boolean;
autoCheckInterval?: number;
shouldAutoCheckOnLaunch?: boolean;
customLogger?: LoggerInterface;

@@ -14,7 +12,6 @@ updateReadyAction?: UpdateReadyAction;

isSmokeTestMode: boolean;
init(params?: ToDesktopRuntimeParams): void;
init(params?: initParams): void;
private _init;
}
declare const _default: ToDesktop;
export default _default;
export type { ToDesktopRuntimeParams };
export = _default;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const AutoUpdater_1 = require("./AutoUpdater");

@@ -8,3 +7,2 @@ const cache_1 = require("./cache");

const Notifier_1 = require("./Notifier");
const SimulatedAutoUpdater_1 = require("./SimulatedAutoUpdater");
class ToDesktop {

@@ -23,19 +21,15 @@ constructor() {

}
_init({ autoUpdater = true, autoCheckInterval, shouldAutoCheckOnLaunch, customLogger, updateReadyAction, } = {}) {
_init({ autoUpdater = true, customLogger, updateReadyAction, } = {}) {
const logger = new Logger_1.default(customLogger);
const Updater = (0, SimulatedAutoUpdater_1.parseSimulateUpdatesFlag)()
? SimulatedAutoUpdater_1.SimulatedAutoUpdater
: AutoUpdater_1.default;
let autoUpdaterInstance;
if (autoUpdater) {
autoUpdaterInstance = new Updater({
logger,
autoCheckInterval,
shouldAutoCheckOnLaunch,
autoUpdaterInstance = new AutoUpdater_1.default({ logger });
new Notifier_1.default({
autoUpdater: autoUpdaterInstance,
updateReadyAction,
});
new Notifier_1.default({ autoUpdater: autoUpdaterInstance, updateReadyAction });
}
else {
// Disables the default behaviour
autoUpdaterInstance = new Updater({
autoUpdaterInstance = new AutoUpdater_1.default({
autoCheckInterval: 0,

@@ -63,2 +57,2 @@ logger,

}
exports.default = todesktop;
module.exports = todesktop;
import { Notification, NotificationConstructorOptions } from "electron";
import AutoUpdater from "./AutoUpdater";
import { UpdateReadyAction } from "./types";
import AutoUpdater, { UpdateAvailableEventPayload } from "./AutoUpdater";
import { MessageBoxOptions } from "electron/main";
/**

@@ -28,2 +28,24 @@ * A proxy to a real Electron API.

}
export interface UpdateReadyAction {
showInstallAndRestartPrompt?: "always" | "whenInForeground" | "never" | ShowInstallAndRestartPrompt;
showNotification?: "always" | "whenInBackground" | "never" | ShowNotification;
}
export declare type ShowNotification = (context: UpdateContext) => Awaitable<Omit<NotificationConstructorOptions, "actions"> | ((api: ShowNotificationApi) => Awaitable<void>) | void>;
declare type ShowNotificationApi = {
showNotification(options: NotificationConstructorOptions): Notification;
};
export declare type ShowInstallAndRestartPrompt = (context: UpdateContext) => Awaitable<(Omit<MessageBoxOptions, "buttons"> & {
installOnNextLaunchButton: string;
restartAndInstallButton: string;
}) | ((api: ShowInstallAndRestartPromptApi) => Awaitable<void>) | void>;
declare type ShowInstallAndRestartPromptApi = {
showInstallAndRestartPrompt(options: Electron.MessageBoxOptions): Promise<Electron.MessageBoxReturnValue>;
restartAndInstall({ isSilent }?: {
isSilent?: boolean;
}): void;
};
declare type UpdateContext = UpdateAvailableEventPayload & {
appIsInForeground: boolean;
};
declare type Awaitable<T> = T | Promise<T>;
export {};

@@ -60,4 +60,2 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
if (payload.disableUpdateReadyAction)
return;
if (this._lastUpdate.isProcessing ||

@@ -64,0 +62,0 @@ this._lastUpdate.version === payload.updateInfo.version) {

@@ -30,2 +30,3 @@ "use strict";

electronUpdater.autoUpdater.logger = logger;
electronUpdater.autoUpdater.allowDowngrade = true;
const config = (0, getConfig_1.default)();

@@ -69,5 +70,2 @@ /*

});
if (!semver.gt(latestVersion, currentVersion)) {
return null;
}
// if latest version is already downloaded, return it

@@ -74,0 +72,0 @@ if (currentlyDownloadedVersion === latestVersion) {

@@ -7,3 +7,3 @@ {

"name": "@todesktop/runtime",
"version": "1.5.7",
"version": "1.6.0",
"license": "MIT",

@@ -10,0 +10,0 @@ "author": "ToDesktop <hi@todesktop.com> (https://www.todesktop.com/)",

@@ -16,3 +16,2 @@ # @todesktop/runtime

- [Default Behaviour](#default-behviour)
- [Simulate Updates](#simulate-updates)
- [Smoke Test](#smoke-test)

@@ -86,15 +85,4 @@ - [API](#api)

## Simulate updates
Passing `--runtime-simulate-updates` as a flag with an associated value will run `@todesktop/runtime` in simulation mode:
- `--runtime-simulate-updates=update-available` simulates the situation where an auto-update exists and will be downloaded.
- `--runtime-simulate-updates=update-not-available` simulates the situation where an auto update is not available.
Internally, this replaces the `autoUpdater` [API](#api) implementation with an alternative that simulates the above auto-update workflows. This is useful if you're running your application in local development and want to test `@todesktop/runtime`'s auto-update behaviour.
## Smoke test
Setting `TODESKTOP_SMOKE_TEST` in your environment to `true` will run `@todesktop/runtime` in simulation mode.
When an application is run in Smoke Test mode the auto-update behavior is forcibly enabled. To successfully pass a Smoke Test your application should not expect any user interaction like showing some dialog on app start.

@@ -134,18 +122,2 @@

##### `options.autoCheckInterval` (Optional)
Type: `number`
Default: `10 * 60 * 1000` (10 min)
The interval at which ToDesktop should check for updates.
##### `options.shouldAutoCheckOnLaunch` (Optional)
Type: `boolean`
Default: `true`
Whether the app should check for auto-updates on launch.
##### `options.customLogger` (Optional)

@@ -193,3 +165,2 @@

- `context` contains update information:
- `disableUpdateReadyAction: boolean;`
- `sources: Source[];`

@@ -269,3 +240,2 @@ - `updateInfo: TDUpdateInfo | null;`

- `context` contains update information:
- `disableUpdateReadyAction: boolean;`
- `sources: Source[];`

@@ -348,3 +318,3 @@ - `updateInfo: TDUpdateInfo | null;`

Default: `{ source: "programmatic-call", disableUpdateReadyAction: false }`
Default: `{ source: "programmatic-call" }`

@@ -359,10 +329,2 @@ ##### `options.source` (Optional)

##### `options.disableUpdateReadyAction` (Optional)
Type: `boolean`
Default: `false`
Whether to disable the configured `updateReadyAction` behaviour. If disabled, the `updateReadyAction` prompt or notification will not display in response to invoking `.autoUpdater.checkForUpdates`.
#### Example

@@ -472,3 +434,2 @@

{
disableUpdateReadyAction: false,
sources: ["auto-check-on-interval"],

@@ -482,4 +443,2 @@ updateInfo: {

`disableUpdateReadyAction` is a boolean that signals whether the configured `updateReadyAction` was disabled.
`sources` (an array of strings) are the sources/triggers of the update check. The default built-in sources are `auto-check-on-launch`, `auto-check-on-interval`, and `programmatic-call`. You can pass a custom source to [`.autoUpdater.checkForUpdates`](#async-autoupdatercheckforupdatesoptions). NOTE: `sources` is an array because multiple checks could be triggered around the same time. They do not cancel an existing update check but piggyback onto it instead.

@@ -627,3 +586,3 @@

Actions which require a user interaction may break Smoke Test, especially
Actions which require a user interaction may brake Smoke Test, especially
dialogs from electron dialog API. Use the following code to disable such a

@@ -630,0 +589,0 @@ behavior in a Smoke Test mode:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc