graceful-updater 1.2.0 → 34.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -188,11 +188,11 @@ Triggered when an error occurs inside the updater
188
188
 
189
189
  ## Contributors
190
190
 
191
- |[<img src="https://avatars.githubusercontent.com/u/4081746?v=4" width="100px;"/><br/><sub><b>zlyi</b></sub>](https://github.com/zlyi)<br/>|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|
192
- | :---: | :---: | :---: |
191
+ |[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/4081746?v=4" width="100px;"/><br/><sub><b>zlyi</b></sub>](https://github.com/zlyi)<br/>|[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|[<img src="https://avatars.githubusercontent.com/u/46579290?v=4" width="100px;"/><br/><sub><b>yinrouni</b></sub>](https://github.com/yinrouni)<br/>|
192
+ | :---: | :---: | :---: | :---: |
193
193
 
194
194
 
195
- This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Jan 31 2023 14:31:40 GMT+0800`.
195
+ This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Wed May 21 2025 20:05:27 GMT+0800`.
196
196
 
197
197
  <!-- GITCONTRIBUTOR_END -->
198
198
 
package/README.md CHANGED
@@ -186,13 +186,13 @@ electronUpdator.on(EventType.UPDATE_DOWNLOAD_PROGRESS, (data) => {
186
186
 
187
187
  <!-- GITCONTRIBUTOR_START -->
188
188
 
189
- ## Contributors
189
+ ## 贡献者
190
190
 
191
- |[<img src="https://avatars.githubusercontent.com/u/4081746?v=4" width="100px;"/><br/><sub><b>zlyi</b></sub>](https://github.com/zlyi)<br/>|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|
192
- | :---: | :---: | :---: |
191
+ |[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/4081746?v=4" width="100px;"/><br/><sub><b>zlyi</b></sub>](https://github.com/zlyi)<br/>|[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|[<img src="https://avatars.githubusercontent.com/u/46579290?v=4" width="100px;"/><br/><sub><b>yinrouni</b></sub>](https://github.com/yinrouni)<br/>|
192
+ | :---: | :---: | :---: | :---: |
193
193
 
194
194
 
195
- This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Jan 31 2023 14:31:40 GMT+0800`.
195
+ [git-contributor 说明](https://github.com/xudafeng/git-contributor),自动生成时间:`Wed May 21 2025 20:05:27 GMT+0800`。
196
196
 
197
197
  <!-- GITCONTRIBUTOR_END -->
198
198
 
@@ -0,0 +1,42 @@
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import { ILogger, IInstallResult, IAppUpdatorOptions, IUpdateInfo, IAvailableUpdate, IAppAdapter } from "./common/types";
3
+ import { ExecuteType } from "./common/constants";
4
+ export declare abstract class AppUpdator extends EventEmitter {
5
+ private state;
6
+ updateInfo?: IUpdateInfo | undefined;
7
+ logger: ILogger;
8
+ availableUpdate: IAvailableUpdate;
9
+ options?: IAppUpdatorOptions;
10
+ startUuid: string;
11
+ protected _windowHelperExeDir?: string;
12
+ protected readonly app: IAppAdapter;
13
+ constructor(options: IAppUpdatorOptions, app?: IAppAdapter);
14
+ _getStartUuid(): string;
15
+ _wrapLogger(logger: ILogger): {
16
+ info(message: string, ...args: any[]): void;
17
+ warn(message: string, ...args: any[]): void;
18
+ error(message: string | Error, ...args: any[]): void;
19
+ };
20
+ private setState;
21
+ setFeedUrl(url: string): void;
22
+ checkForUpdates(executeType?: ExecuteType): Promise<void>;
23
+ downloadUpdate(executeType?: ExecuteType): Promise<void>;
24
+ quitAndInstall(): Promise<void>;
25
+ protected preCheckForAsar(): Promise<IInstallResult>;
26
+ protected preCheck(executeType: ExecuteType): Promise<IInstallResult | {
27
+ success: boolean;
28
+ error: any;
29
+ }>;
30
+ protected downloadUpdateFile(updateInfo: IUpdateInfo, executeType: ExecuteType): Promise<void>;
31
+ protected unzip(): Promise<IInstallResult>;
32
+ dispatchError(e: Error): void;
33
+ logError(e: Error): void;
34
+ /**
35
+ * 由子类实现的自定义方法
36
+ */
37
+ protected abstract doGetAvailableUpdateInfo(updateInfo: IUpdateInfo): IAvailableUpdate;
38
+ protected abstract doPreCheckForPackage(): Promise<IInstallResult>;
39
+ protected abstract doQuitAndInstallAsar(): Promise<IInstallResult>;
40
+ protected abstract doQuitAndInstallPackage(): Promise<IInstallResult>;
41
+ protected abstract doUnzip(): Promise<IInstallResult>;
42
+ }
@@ -242,4 +242,3 @@ class AppUpdator extends eventemitter3_1.EventEmitter {
242
242
  }
243
243
  }
244
244
  exports.AppUpdator = AppUpdator;
245
- //# sourceMappingURL=app-updator.js.map
@@ -0,0 +1,111 @@
1
+ /**
2
+ * 更新包备份前缀
3
+ */
4
+ export declare const OldArchivePrefix = "old-";
5
+ /**
6
+ * 安装结果类型
7
+ */
8
+ export declare enum InstallResultType {
9
+ UpdateUnzipError = "update-unzip-error",
10
+ DownloadError = "download-error",
11
+ UpdateSuccess = "update-success",
12
+ CheckForUpdatesError = "check-for-updates-error"
13
+ }
14
+ /**
15
+ * 更新状态
16
+ */
17
+ export declare enum StateType {
18
+ /**
19
+ * 空闲
20
+ */
21
+ Idle = "idle",
22
+ /**
23
+ * 检查更新中
24
+ */
25
+ CheckingForUpdate = "checking-for-update",
26
+ /**
27
+ * 下载中
28
+ */
29
+ Downloading = "downloading",
30
+ /**
31
+ * 下载完成
32
+ */
33
+ Downloaded = "downloaded"
34
+ }
35
+ /**
36
+ * 更新类型
37
+ */
38
+ export declare enum UpdateType {
39
+ /** 全量更新 */
40
+ Package = "package",
41
+ /** 动态更新 */
42
+ Asar = "asar",
43
+ /** 更新包更新 */
44
+ Assets = "assets"
45
+ }
46
+ /**
47
+ * 执行类型
48
+ */
49
+ export declare enum ExecuteType {
50
+ /**
51
+ * 自动触发
52
+ */
53
+ User = "user",
54
+ /**
55
+ * 手动触发
56
+ */
57
+ Auto = "auto"
58
+ }
59
+ /**
60
+ * 执行类型
61
+ */
62
+ export declare enum DownloadProgressStatus {
63
+ /**
64
+ * 开始
65
+ */
66
+ Begin = "begin",
67
+ /**
68
+ * 下载中
69
+ */
70
+ Downloading = "downloading",
71
+ /**
72
+ * 结束
73
+ */
74
+ End = "end"
75
+ }
76
+ /**
77
+ * 事件类型
78
+ */
79
+ export declare enum EventType {
80
+ /**
81
+ * 下载完成
82
+ */
83
+ UPDATE_DOWNLOADED = "update-downloaded",
84
+ /**
85
+ * 下载进度
86
+ */
87
+ UPDATE_DOWNLOAD_PROGRESS = "update-download-progress",
88
+ /**
89
+ * 用户调用 quitAndInstall 之后发出,可在次事件后完成关闭窗口、重启等操作
90
+ */
91
+ BEFORE_QUIT_FOR_UPDATE = "before-quit-for-update",
92
+ /**
93
+ * 有可用更新
94
+ */
95
+ UPDATE_AVAILABLE = "update-available",
96
+ /**
97
+ * 开始检查更新
98
+ */
99
+ CHECKING_FOR_UPDATE = "checking-for-update",
100
+ /**
101
+ * 无可用更新
102
+ */
103
+ UPDATE_NOT_AVAILABLE = "update-not-available",
104
+ /**
105
+ * 错误
106
+ */
107
+ ERROR = "error"
108
+ }
109
+ export declare enum FileName {
110
+ TARGET_REPLACEMENT_ASAR = "latest.asar"
111
+ }
@@ -119,4 +119,3 @@ var FileName;
119
119
  (function (FileName) {
120
120
  FileName["TARGET_REPLACEMENT_ASAR"] = "latest.asar";
121
121
  })(FileName = exports.FileName || (exports.FileName = {}));
122
- //# sourceMappingURL=constants.js.map
@@ -0,0 +1,91 @@
1
+ import { UpdateType, InstallResultType, DownloadProgressStatus } from '../constants';
2
+
3
+ export interface ILogger {
4
+ info(message: string, ...args: any[]): void;
5
+ warn(message: string, ...args: any[]): void;
6
+ error(message: string | Error, ...args: any[]): void;
7
+ }
8
+
9
+ export interface IUpdateInfo {
10
+ /** 最新版本 */
11
+ version: string;
12
+ /** 下载信息 */
13
+ files: [
14
+ {
15
+ /** 下载地址 */
16
+ url: string;
17
+ /** 下载签名 */
18
+ signature: string;
19
+ },
20
+ ];
21
+ /** 更新类型 */
22
+ updateType: UpdateType;
23
+ }
24
+
25
+ export interface IInstallResult {
26
+ /**
27
+ * 是否安装成功
28
+ */
29
+ success: boolean;
30
+ /**
31
+ * 异常类型
32
+ */
33
+ type?: InstallResultType;
34
+ /**
35
+ * 错误消息
36
+ */
37
+ message?: any;
38
+
39
+ /**
40
+ * 异常
41
+ */
42
+ error?: Error;
43
+ }
44
+
45
+ export interface IAppUpdatorOptions {
46
+ logger?: ILogger;
47
+ verify?: any;
48
+ updateInfoFormatter?: (res: object) => object;
49
+ dmgTitleFormatter?: (res: object, updateInfo: IUpdateInfo) => string;
50
+ ifNeedUpdate: (res: object) => boolean;
51
+ url: string;
52
+ autoDownload?: boolean;
53
+ productName?: string;
54
+ getWindowsHelperExeDir?: () => string;
55
+ }
56
+
57
+ interface IProgressHandleArg {
58
+ status: DownloadProgressStatus;
59
+ [key: string]: any;
60
+ }
61
+
62
+ export interface IDownloadFileOptions {
63
+ logger: ILogger;
64
+ url: string;
65
+ signature: string;
66
+ targetDir: string;
67
+ progressHandle: (progress: IProgressHandleArg) => void;
68
+ }
69
+
70
+ export interface IAvailableUpdate {
71
+ /** 资源根路径 */
72
+ resourcePath: string;
73
+ /** 下载目标路径 */
74
+ downloadTargetDir: string;
75
+ /** 最新 asar 路径 */
76
+ latestAsarPath: string;
77
+ }
78
+
79
+ export interface IAppAdapter {
80
+ readonly name: string;
81
+
82
+ readonly userDataPath: string;
83
+
84
+ readonly exePath: string;
85
+
86
+ quit(): void;
87
+
88
+ exit(code: number): void;
89
+
90
+ relaunch(code?: number): void;
91
+ }
@@ -0,0 +1,3 @@
1
+ declare module 'sudo-prompt-alt';
2
+ declare module 'rimraf-alt';
3
+ declare module 'graceful-updater-windows-helper';
@@ -0,0 +1,12 @@
1
+ import { IAppAdapter } from "./common/types";
2
+ export declare class ElectronAppAdapter implements IAppAdapter {
3
+ private readonly app;
4
+ constructor(app?: Electron.App);
5
+ get name(): string;
6
+ get isPackaged(): boolean;
7
+ get userDataPath(): string;
8
+ get exePath(): string;
9
+ exit(code: number): void;
10
+ relaunch(code: number): void;
11
+ quit(): void;
12
+ }
@@ -30,4 +30,3 @@ class ElectronAppAdapter {
30
30
  }
31
31
  }
32
32
  exports.ElectronAppAdapter = ElectronAppAdapter;
33
- //# sourceMappingURL=elelctron-app-adapter.js.map
@@ -0,0 +1,3 @@
1
+ export { UpdateType, EventType, ExecuteType, DownloadProgressStatus, StateType } from "./common/constants";
2
+ export { MacUpdator } from "./mac-updator";
3
+ export { WindowsUpdator } from "./windows-updator";
package/build/index.js CHANGED
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const constants_1 = require("./common/constants");
4
- const mac_updator_1 = require("./mac-updator");
5
- const windows_updator_1 = require("./windows-updator");
6
- exports.default = {
7
- UpdateType: constants_1.UpdateType,
8
- EventType: constants_1.EventType,
9
- ExecuteType: constants_1.ExecuteType,
10
- StateType: constants_1.StateType,
11
- MacUpdator: mac_updator_1.MacUpdator,
12
- WindowsUpdator: windows_updator_1.WindowsUpdator,
13
- DownloadProgressStatus: constants_1.DownloadProgressStatus,
14
- };
15
- //# sourceMappingURL=index.js.map
3
+ exports.WindowsUpdator = exports.MacUpdator = exports.StateType = exports.DownloadProgressStatus = exports.ExecuteType = exports.EventType = exports.UpdateType = void 0;
4
+ var constants_1 = require("./common/constants");
5
+ Object.defineProperty(exports, "UpdateType", { enumerable: true, get: function () { return constants_1.UpdateType; } });
6
+ Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return constants_1.EventType; } });
7
+ Object.defineProperty(exports, "ExecuteType", { enumerable: true, get: function () { return constants_1.ExecuteType; } });
8
+ Object.defineProperty(exports, "DownloadProgressStatus", { enumerable: true, get: function () { return constants_1.DownloadProgressStatus; } });
9
+ Object.defineProperty(exports, "StateType", { enumerable: true, get: function () { return constants_1.StateType; } });
10
+ var mac_updator_1 = require("./mac-updator");
11
+ Object.defineProperty(exports, "MacUpdator", { enumerable: true, get: function () { return mac_updator_1.MacUpdator; } });
12
+ var windows_updator_1 = require("./windows-updator");
13
+ Object.defineProperty(exports, "WindowsUpdator", { enumerable: true, get: function () { return windows_updator_1.WindowsUpdator; } });
@@ -0,0 +1,13 @@
1
+ import { AppUpdator } from "./app-updator";
2
+ import { IInstallResult, IUpdateInfo, IAvailableUpdate } from "./common/types";
3
+ export declare class MacUpdator extends AppUpdator {
4
+ protected doGetAvailableUpdateInfo(updateInfo: IUpdateInfo): IAvailableUpdate;
5
+ protected doPreCheckForPackage(): Promise<IInstallResult>;
6
+ /**
7
+ * 资源解压
8
+ * @return
9
+ */
10
+ protected doUnzip(): Promise<IInstallResult>;
11
+ protected doQuitAndInstallAsar(): Promise<IInstallResult>;
12
+ protected doQuitAndInstallPackage(): Promise<IInstallResult>;
13
+ }
@@ -115,4 +115,3 @@ class MacUpdator extends app_updator_1.AppUpdator {
115
115
  }
116
116
  }
117
117
  exports.MacUpdator = MacUpdator;
118
- //# sourceMappingURL=mac-updator.js.map
@@ -0,0 +1,11 @@
1
+ import { IDownloadFileOptions } from "../common/types";
2
+ /**
3
+ * 文件下载
4
+ * @param updator 更新实例
5
+ * @param url 下载地址
6
+ * @param signature 下载签名
7
+ * @param targeDir 下载目录
8
+ * @param progressHandle 下载状态回调
9
+ * @return
10
+ */
11
+ export declare const downloadFile: ({ logger, url, signature, targetDir, progressHandle }: IDownloadFileOptions) => Promise<unknown>;
@@ -75,4 +75,3 @@ const downloadFile = async ({ logger, url, signature, targetDir, progressHandle
75
75
  });
76
76
  };
77
77
  exports.downloadFile = downloadFile;
78
- //# sourceMappingURL=download-file.js.map
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import sudoPrompt from 'sudo-prompt-alt';
4
+ import { exec } from 'child_process';
5
+ import { rename, exists, readdir, existsSync, createWriteStream } from 'original-fs';
6
+ import { IUpdateInfo, IAppUpdatorOptions } from "../common/types";
7
+ export declare const renameAsync: typeof rename.__promisify__;
8
+ export declare const existsAsync: typeof exists.__promisify__;
9
+ export declare const readdirAsync: typeof readdir.__promisify__;
10
+ export declare const rimrafAsync: Function;
11
+ export declare const execAsync: typeof exec.__promisify__;
12
+ export declare const isWin: boolean;
13
+ export declare const isMac: boolean;
14
+ export { createWriteStream, existsSync, sudoPrompt };
15
+ export declare const getMacOSAppPath: () => string;
16
+ export declare const sleep: (ms: number) => Promise<unknown>;
17
+ export declare const waitUntil: (handle: () => boolean, options?: {
18
+ retryTime: number;
19
+ ms: number;
20
+ }) => Promise<any>;
21
+ export declare const spawnAsync: (command: string, options: any) => Promise<unknown>;
22
+ export declare const cleanOldArchive: (resourcePath: string) => Promise<void[] | undefined>;
23
+ export declare const existFile: (path: string) => Promise<boolean>;
24
+ export declare const requestUpdateInfo: (options: IAppUpdatorOptions) => Promise<IUpdateInfo>;
25
+ export declare const getExecuteFile: (helperExeFileDir: string, file: string) => string;
@@ -119,4 +119,3 @@ const getExecuteFile = (helperExeFileDir, file) => {
119
119
  return path_1.default.join(helperExeFileDir, file);
120
120
  };
121
121
  exports.getExecuteFile = getExecuteFile;
122
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import { IInstallResult, IAppUpdatorOptions, IUpdateInfo, ILogger, IAvailableUpdate } from "../common/types";
2
+ declare const _default: (updatorOptions: IAppUpdatorOptions, logger: ILogger, availableUpdate: IAvailableUpdate, updateInfo: IUpdateInfo, preCheck?: boolean) => Promise<IInstallResult>;
3
+ export default _default;
@@ -152,4 +152,3 @@ exports.default = async (updatorOptions, logger, availableUpdate, updateInfo, pr
152
152
  success: true,
153
153
  };
154
154
  };
155
- //# sourceMappingURL=install-macos-dmg.js.map
@@ -0,0 +1,3 @@
1
+ import { ILogger } from "../common/types";
2
+ declare function sudoPromptExec(logger: ILogger, shell: string): Promise<unknown>;
3
+ export { sudoPromptExec };
@@ -20,4 +20,3 @@ function sudoPromptExec(logger, shell) {
20
20
  });
21
21
  }
22
22
  exports.sudoPromptExec = sudoPromptExec;
23
- //# sourceMappingURL=sudo-prompt-exec.js.map
@@ -0,0 +1,9 @@
1
+ import { IInstallResult, IUpdateInfo, IAvailableUpdate } from "./common/types";
2
+ import { AppUpdator } from "./app-updator";
3
+ export declare class WindowsUpdator extends AppUpdator {
4
+ protected doGetAvailableUpdateInfo(updateInfo: IUpdateInfo): IAvailableUpdate;
5
+ protected doPreCheckForPackage(): Promise<IInstallResult>;
6
+ protected doUnzip(): Promise<IInstallResult>;
7
+ protected doQuitAndInstallPackage(): Promise<IInstallResult>;
8
+ protected doQuitAndInstallAsar(): Promise<IInstallResult>;
9
+ }
@@ -99,4 +99,3 @@ class WindowsUpdator extends app_updator_1.AppUpdator {
99
99
  }
100
100
  }
101
101
  exports.WindowsUpdator = WindowsUpdator;
102
- //# sourceMappingURL=windows-updator.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graceful-updater",
3
- "version": "1.2.0",
3
+ "version": "34.0.2",
4
4
  "description": "graceful-updater is a software updator management solution for Electron applications, It is convenient to complete full software update and dynamic update.",
5
5
  "scripts": {
6
6
  "build": "sh ./build.sh",
@@ -11,13 +11,15 @@
11
11
  "dev": "ttsc -p tsconfig.json -watch"
12
12
  },
13
13
  "main": "./build",
14
+ "types": "./build/index.d.ts",
14
15
  "keywords": [
15
16
  "electron",
16
17
  "updator",
17
18
  "auto-updator"
18
19
  ],
19
20
  "files": [
20
- "build/**/*.js"
21
+ "build/**/*.js",
22
+ "build/**/*.d.ts"
21
23
  ],
22
24
  "repository": {
23
25
  "type": "git",
@@ -46,8 +48,8 @@
46
48
  "cross-env": "^7.0.3",
47
49
  "detect-port": "1",
48
50
  "egg-bin": "^5.9.0",
49
- "electron": "18",
50
- "electron-windows": "18",
51
+ "electron": "34",
52
+ "electron-windows": "34",
51
53
  "eslint": "^7.32.0",
52
54
  "eslint-config-egg": "^12.1.0",
53
55
  "eslint-plugin-no-only-tests": "^3.1.0",
@@ -70,4 +72,4 @@
70
72
  }
71
73
  },
72
74
  "license": "MIT"
73
- }
75
+ }