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.2 to 1.5.3

17

dist/AutoUpdater.d.ts

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

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 { AutoUpdateState } from "./types";
import { CheckForUpdatesInput, Source } from "./types";
export declare type AutoUpdaterConstructorOptions = {

@@ -13,9 +13,4 @@ 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[];

@@ -37,9 +32,5 @@ readonly updateInfo: TDUpdateInfo | null;

private _updaterAgent;
private _state;
get state(): Readonly<AutoUpdateState>;
constructor({ autoCheckInterval, // 10 min
logger, shouldAutoCheckOnLaunch, }: AutoUpdaterConstructorOptions);
checkForUpdates({ source, }?: {
source?: Source;
}): Promise<UpdateCheckResult>;
checkForUpdates({ source, disableUpdateReadyAction, }?: CheckForUpdatesInput): Promise<UpdateCheckResult>;
restartAndInstall({ isSilent, }?: {

@@ -46,0 +37,0 @@ isSilent?: boolean;

@@ -12,5 +12,2 @@ "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");

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

const version_1 = require("./version");
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 = {}));
const types_1 = require("./types");
class AutoUpdater extends eventemitter2_1.EventEmitter2 {

@@ -41,3 +33,2 @@ constructor({ autoCheckInterval = 10 * 60 * 1000, // 10 min

this._pendingCheckSources = [];
this._state = {};
this._logger = logger;

@@ -70,6 +61,3 @@ if (this._isActive) {

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

@@ -87,3 +75,3 @@ this._log("info", ".checkForUpdates called");

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

@@ -113,3 +101,3 @@ }

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

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

updateInfo,
disableUpdateReadyAction,
};

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

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

@@ -189,3 +179,4 @@ checkAfterTimeout();

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

@@ -199,3 +190,3 @@ }

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

@@ -220,3 +211,5 @@ /*

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

@@ -297,3 +290,2 @@ onEnd();

this.emit("checking-for-update");
this._state = { status: "checking-for-update" };
});

@@ -303,3 +295,2 @@ electronUpdater.autoUpdater.on("update-not-available", (info) => {

this.emit("update-not-available", info);
this._state = { status: "update-not-available", info };
});

@@ -309,3 +300,2 @@ electronUpdater.autoUpdater.on("update-available", (info) => {

this.emit("update-available", info);
this._state = { status: "update-available", info };
});

@@ -317,4 +307,4 @@ electronUpdater.autoUpdater.on("update-downloaded", (info) => {

updateInfo: info,
disableUpdateReadyAction: false,
});
this._state = { status: "update-downloaded", info };
});

@@ -321,0 +311,0 @@ electronUpdater.autoUpdater.on("download-progress", (info) => {

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

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

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

import { EventEmitter2 } from "eventemitter2";
import { AutoUpdaterConstructorOptions, Source, UpdateCheckResult } from "./AutoUpdater";
import { AutoUpdateState } from "./types";
import { AutoUpdaterConstructorOptions, UpdateCheckResult } from "./AutoUpdater";
import { CheckForUpdatesInput } from "./types";
export declare enum SimulateUpdatesFlag {

@@ -12,9 +12,6 @@ UpdateAvailable = "update-available",

private simulateUpdatesFlag;
private privateState;
get state(): Readonly<AutoUpdateState>;
private hasUpdateReadyToInstall;
constructor({ autoCheckInterval, // 10 min
logger, shouldAutoCheckOnLaunch, }: AutoUpdaterConstructorOptions);
checkForUpdates: ({ source, }?: {
source?: Source;
}) => Promise<UpdateCheckResult>;
checkForUpdates: ({ source, disableUpdateReadyAction, }?: CheckForUpdatesInput) => Promise<UpdateCheckResult>;
restartAndInstall: ({ isSilent, }?: {

@@ -21,0 +18,0 @@ isSilent?: boolean;

@@ -15,3 +15,3 @@ "use strict";

const eventemitter2_1 = require("eventemitter2");
const AutoUpdater_1 = require("./AutoUpdater");
const types_1 = require("./types");
function delay(ms) {

@@ -41,4 +41,4 @@ return new Promise((resolve) => setTimeout(resolve, ms));

this.simulateUpdatesFlag = (0, exports.parseSimulateUpdatesFlag)();
this.privateState = {};
this.checkForUpdates = ({ source = AutoUpdater_1.BuiltInSources.programmaticCall, } = {}) => __awaiter(this, void 0, void 0, function* () {
this.hasUpdateReadyToInstall = false;
this.checkForUpdates = ({ source = types_1.BuiltInSources.programmaticCall, disableUpdateReadyAction = false, } = {}) => __awaiter(this, void 0, void 0, function* () {
this.logger.info("checkForUpdates()", { source });

@@ -51,11 +51,9 @@ const tdUpdateInfo = {

this.emit("checking-for-update");
this.privateState = { status: "checking-for-update" };
yield delay(1000);
if (this.simulateUpdatesFlag === SimulateUpdatesFlag.UpdateNotAvailable) {
this.emit("update-not-available", info);
this.privateState = { status: "update-not-available", info };
return { updateInfo: null };
}
else {
this.emit("update-available", info);
this.privateState = { status: "update-available", info };
const getProgressInfo = (percent) => __awaiter(this, void 0, void 0, function* () {

@@ -75,12 +73,16 @@ const totalBytes = 1000000; // 100 mb

}
const eventPayload = { sources: [source], updateInfo: info };
this.hasUpdateReadyToInstall = true;
const eventPayload = {
sources: [source],
updateInfo: info,
disableUpdateReadyAction,
};
this.emit("update-downloaded", eventPayload);
this.emit("notify-after-update-downloaded", eventPayload);
this.privateState = { status: "update-downloaded", info };
return { updateInfo: tdUpdateInfo };
}
return { updateInfo: tdUpdateInfo };
});
this.restartAndInstall = ({ isSilent = false, } = {}) => {
this.logger.info("restartAndInstall()", { isSilent });
if (this.privateState.status !== "update-downloaded") {
if (!this.hasUpdateReadyToInstall) {
const error = new Error("Cannot restart and install. There is no update downloaded");

@@ -108,3 +110,3 @@ this.logger.error("error", error);

const interval = setInterval(() => {
this.checkForUpdates({ source: AutoUpdater_1.BuiltInSources.autoCheckOnInterval });
this.checkForUpdates({ source: types_1.BuiltInSources.autoCheckOnInterval });
// interval should be cleared once a prompt is shown, otherwise will re-prompt every interval

@@ -117,10 +119,7 @@ if (this.simulateUpdatesFlag === SimulateUpdatesFlag.UpdateAvailable) {

if (shouldAutoCheckOnLaunch) {
this.checkForUpdates({ source: AutoUpdater_1.BuiltInSources.autoCheckOnLaunch });
this.checkForUpdates({ source: types_1.BuiltInSources.autoCheckOnLaunch });
}
});
}
get state() {
return this.privateState;
}
}
exports.SimulatedAutoUpdater = SimulatedAutoUpdater;

@@ -1,9 +0,14 @@

import type { UpdateInfo } from "electron-updater";
import { Notification, NotificationConstructorOptions } from "electron";
import { MessageBoxOptions } from "electron/main";
import { UpdateAvailableEventPayload } from "./AutoUpdater";
export declare type AutoUpdateState = {
status?: "checking-for-update" | "update-available" | "update-not-available" | "update-downloaded";
info?: UpdateInfo;
export declare type CheckForUpdatesInput = {
source?: Source;
disableUpdateReadyAction?: boolean;
};
export declare enum BuiltInSources {
autoCheckOnLaunch = "auto-check-on-launch",
autoCheckOnInterval = "auto-check-on-interval",
programmaticCall = "programmatic-call"
}
export declare type Source = BuiltInSources | string;
export interface UpdateReadyAction {

@@ -10,0 +15,0 @@ showInstallAndRestartPrompt?: "always" | "whenInForeground" | "never" | ShowInstallAndRestartPrompt;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BuiltInSources = void 0;
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 = {}));

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

"name": "@todesktop/runtime",
"version": "1.5.2",
"version": "1.5.3",
"license": "MIT",

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

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

- [`.init(options)`](#initoptions)
- [`.autoUpdater.state`](#autoupdaterstate)
- [`.autoUpdater.checkForUpdates(options)`](#autoupdatercheckforupdatesoptions)

@@ -192,2 +191,3 @@ - [`.autoUpdater.on(eventName, callback)`](#autoupdateroneventname-callback)

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

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

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

@@ -320,9 +321,2 @@ - `updateInfo: TDUpdateInfo | null;`

### `.autoUpdater.state`
This getter retrieves the latest auto-update state that has occured internally. The state contains the following:
- `status`: `"checking-for-update" | "update-available" | "update-not-available" | "update-downloaded"` | `undefined`;
- `info`: `UpdateInfo` | `undefined`;
### `.autoUpdater.checkForUpdates(options)`

@@ -353,3 +347,3 @@

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

@@ -364,2 +358,10 @@ ##### `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

@@ -469,2 +471,3 @@

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

@@ -478,2 +481,4 @@ 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.

@@ -480,0 +485,0 @@

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