UNPKG

7.13 kBTypeScriptView Raw
1/// <reference types="node" />
2import { AllPublishOptions, CancellationToken, PublishConfiguration, UpdateInfo, DownloadOptions } from "builder-util-runtime";
3import { EventEmitter } from "events";
4import { OutgoingHttpHeaders } from "http";
5import { Lazy } from "lazy-val";
6import { SemVer } from "semver";
7import { AppAdapter } from "./AppAdapter";
8import { DownloadedUpdateHelper } from "./DownloadedUpdateHelper";
9import { Logger, Provider, ResolvedUpdateFileInfo, UpdateCheckResult, UpdateDownloadedEvent, UpdaterSignal } from "./main";
10import { ProviderPlatform } from "./providers/Provider";
11import Session = Electron.Session;
12export declare abstract class AppUpdater extends EventEmitter {
13 /**
14 * Whether to automatically download an update when it is found.
15 */
16 autoDownload: boolean;
17 /**
18 * Whether to automatically install a downloaded update on app quit (if `quitAndInstall` was not called before).
19 *
20 * Applicable only on Windows and Linux.
21 */
22 autoInstallOnAppQuit: boolean;
23 /**
24 * *GitHub provider only.* Whether to allow update to pre-release versions. Defaults to `true` if application version contains prerelease components (e.g. `0.12.1-alpha.1`, here `alpha` is a prerelease component), otherwise `false`.
25 *
26 * If `true`, downgrade will be allowed (`allowDowngrade` will be set to `true`).
27 */
28 allowPrerelease: boolean;
29 /**
30 * *GitHub provider only.* Get all release notes (from current version to latest), not just the latest.
31 * @default false
32 */
33 fullChangelog: boolean;
34 /**
35 * Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel).
36 *
37 * Taken in account only if channel differs (pre-release version component in terms of semantic versioning).
38 *
39 * @default false
40 */
41 allowDowngrade: boolean;
42 /**
43 * The current application version.
44 */
45 readonly currentVersion: SemVer;
46 private _channel;
47 protected downloadedUpdateHelper: DownloadedUpdateHelper | null;
48 /**
49 * Get the update channel. Not applicable for GitHub. Doesn't return `channel` from the update configuration, only if was previously set.
50 */
51 get channel(): string | null;
52 /**
53 * Set the update channel. Not applicable for GitHub. Overrides `channel` in the update configuration.
54 *
55 * `allowDowngrade` will be automatically set to `true`. If this behavior is not suitable for you, simple set `allowDowngrade` explicitly after.
56 */
57 set channel(value: string | null);
58 /**
59 * The request headers.
60 */
61 requestHeaders: OutgoingHttpHeaders | null;
62 protected _logger: Logger;
63 get netSession(): Session;
64 /**
65 * The logger. You can pass [electron-log](https://github.com/megahertz/electron-log), [winston](https://github.com/winstonjs/winston) or another logger with the following interface: `{ info(), warn(), error() }`.
66 * Set it to `null` if you would like to disable a logging feature.
67 */
68 get logger(): Logger | null;
69 set logger(value: Logger | null);
70 /**
71 * For type safety you can use signals, e.g. `autoUpdater.signals.updateDownloaded(() => {})` instead of `autoUpdater.on('update-available', () => {})`
72 */
73 readonly signals: UpdaterSignal;
74 private _appUpdateConfigPath;
75 /**
76 * test only
77 * @private
78 */
79 set updateConfigPath(value: string | null);
80 private clientPromise;
81 protected readonly stagingUserIdPromise: Lazy<string>;
82 private checkForUpdatesPromise;
83 protected readonly app: AppAdapter;
84 protected updateInfoAndProvider: UpdateInfoAndProvider | null;
85 protected constructor(options: AllPublishOptions | null | undefined, app?: AppAdapter);
86 getFeedURL(): string | null | undefined;
87 /**
88 * Configure update provider. If value is `string`, [GenericServerOptions](/configuration/publish#genericserveroptions) will be set with value as `url`.
89 * @param options If you want to override configuration in the `app-update.yml`.
90 */
91 setFeedURL(options: PublishConfiguration | AllPublishOptions | string): void;
92 /**
93 * Asks the server whether there is an update.
94 */
95 checkForUpdates(): Promise<UpdateCheckResult>;
96 isUpdaterActive(): boolean;
97 checkForUpdatesAndNotify(): Promise<UpdateCheckResult | null>;
98 private isStagingMatch;
99 private computeFinalHeaders;
100 private isUpdateAvailable;
101 protected getUpdateInfoAndProvider(): Promise<UpdateInfoAndProvider>;
102 private createProviderRuntimeOptions;
103 private doCheckForUpdates;
104 protected onUpdateAvailable(updateInfo: UpdateInfo): void;
105 /**
106 * Start downloading update manually. You can use this method if `autoDownload` option is set to `false`.
107 * @returns {Promise<string>} Path to downloaded file.
108 */
109 downloadUpdate(cancellationToken?: CancellationToken): Promise<any>;
110 protected dispatchError(e: Error): void;
111 protected dispatchUpdateDownloaded(event: UpdateDownloadedEvent): void;
112 protected abstract doDownloadUpdate(downloadUpdateOptions: DownloadUpdateOptions): Promise<Array<string>>;
113 /**
114 * Restarts the app and installs the update after it has been downloaded.
115 * It should only be called after `update-downloaded` has been emitted.
116 *
117 * **Note:** `autoUpdater.quitAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that.
118 * This is different from the normal quit event sequence.
119 *
120 * @param isSilent *windows-only* Runs the installer in silent mode. Defaults to `false`.
121 * @param isForceRunAfter Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.
122 */
123 abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void;
124 private loadUpdateConfig;
125 private computeRequestHeaders;
126 private getOrCreateStagingUserId;
127 private getOrCreateDownloadHelper;
128 protected executeDownload(taskOptions: DownloadExecutorTask): Promise<Array<string>>;
129}
130export interface DownloadUpdateOptions {
131 readonly updateInfoAndProvider: UpdateInfoAndProvider;
132 readonly requestHeaders: OutgoingHttpHeaders;
133 readonly cancellationToken: CancellationToken;
134}
135/** @private */
136export declare class NoOpLogger implements Logger {
137 info(message?: any): void;
138 warn(message?: any): void;
139 error(message?: any): void;
140}
141export interface UpdateInfoAndProvider {
142 info: UpdateInfo;
143 provider: Provider<any>;
144}
145export interface DownloadExecutorTask {
146 readonly fileExtension: string;
147 readonly fileInfo: ResolvedUpdateFileInfo;
148 readonly downloadUpdateOptions: DownloadUpdateOptions;
149 readonly task: (destinationFile: string, downloadOptions: DownloadOptions, packageFile: string | null, removeTempDirIfAny: () => Promise<any>) => Promise<any>;
150 readonly done?: (event: UpdateDownloadedEvent) => Promise<any>;
151}
152/** @private */
153export interface TestOnlyUpdaterOptions {
154 platform: ProviderPlatform;
155 isUseDifferentialDownload?: boolean;
156}