AppUpdater.d.ts 6.4 KB

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