graceful-updater 34.0.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 +3 -3
- package/README.md +3 -3
- package/build/app-updator.d.ts +42 -0
- package/build/app-updator.js +0 -1
- package/build/common/constants.d.ts +111 -0
- package/build/common/constants.js +0 -1
- package/build/common/types/index.d.ts +91 -0
- package/build/common/types/typing.d.ts +3 -0
- package/build/elelctron-app-adapter.d.ts +12 -0
- package/build/elelctron-app-adapter.js +0 -1
- package/build/index.d.ts +3 -0
- package/build/index.js +11 -13
- package/build/mac-updator.d.ts +13 -0
- package/build/mac-updator.js +0 -1
- package/build/utils/download-file.d.ts +11 -0
- package/build/utils/download-file.js +0 -1
- package/build/utils/index.d.ts +25 -0
- package/build/utils/index.js +0 -1
- package/build/utils/install-macos-dmg.d.ts +3 -0
- package/build/utils/install-macos-dmg.js +0 -1
- package/build/utils/sudo-prompt-exec.d.ts +3 -0
- package/build/utils/sudo-prompt-exec.js +0 -1
- package/build/windows-updator.d.ts +9 -0
- package/build/windows-updator.js +0 -1
- package/package.json +5 -3
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/
|
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 `
|
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
@@ -188,11 +188,11 @@ electronUpdator.on(EventType.UPDATE_DOWNLOAD_PROGRESS, (data) => {
|
|
188
188
|
|
189
189
|
## 贡献者
|
190
190
|
|
191
|
-
|[<img src="https://avatars.githubusercontent.com/u/
|
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
|
-
[git-contributor 说明](https://github.com/xudafeng/git-contributor),自动生成时间:`
|
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
|
+
}
|
package/build/app-updator.js
CHANGED
@@ -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
|
+
}
|
@@ -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,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
|
+
}
|
package/build/index.d.ts
ADDED
package/build/index.js
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
exports.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
+
}
|
package/build/mac-updator.js
CHANGED
@@ -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>;
|
@@ -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;
|
package/build/utils/index.js
CHANGED
@@ -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;
|
@@ -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
|
+
}
|
package/build/windows-updator.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "graceful-updater",
|
3
|
-
"version": "34.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",
|
@@ -70,4 +72,4 @@
|
|
70
72
|
}
|
71
73
|
},
|
72
74
|
"license": "MIT"
|
73
|
-
}
|
75
|
+
}
|