@sellerartifact/electron-app-updater 0.0.1 → 0.0.3
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/dist/index.cjs +89 -131
- package/dist/index.d.ts +5 -1
- package/dist/index.js +29 -70
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const path = __webpack_require__("path");
|
|
5
|
-
const pathFile = path.join(__dirname, 'path.txt');
|
|
6
|
-
function getElectronPath() {
|
|
7
|
-
let executablePath;
|
|
8
|
-
if (fs.existsSync(pathFile)) executablePath = fs.readFileSync(pathFile, 'utf-8');
|
|
9
|
-
if (process.env.ELECTRON_OVERRIDE_DIST_PATH) return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath || 'electron');
|
|
10
|
-
if (executablePath) return path.join(__dirname, 'dist', executablePath);
|
|
11
|
-
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');
|
|
12
|
-
}
|
|
13
|
-
module.exports = getElectronPath();
|
|
14
|
-
},
|
|
15
|
-
fs: function(module) {
|
|
16
|
-
"use strict";
|
|
17
|
-
module.exports = require("fs");
|
|
18
|
-
},
|
|
19
|
-
path: function(module) {
|
|
20
|
-
"use strict";
|
|
21
|
-
module.exports = require("path");
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
/************************************************************************/ // The module cache
|
|
25
|
-
var __webpack_module_cache__ = {};
|
|
26
|
-
// The require function
|
|
27
|
-
function __webpack_require__(moduleId) {
|
|
28
|
-
// Check if module is in cache
|
|
29
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
30
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
31
|
-
// Create a new module (and put it into the cache)
|
|
32
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
33
|
-
exports: {}
|
|
34
|
-
};
|
|
35
|
-
// Execute the module function
|
|
36
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
37
|
-
// Return the exports of the module
|
|
38
|
-
return module.exports;
|
|
39
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
// The require scope
|
|
3
|
+
var __webpack_require__ = {};
|
|
40
4
|
/************************************************************************/ // webpack/runtime/compat_get_default_export
|
|
41
5
|
(()=>{
|
|
42
6
|
// getDefaultExport function for compatibility with non-ESM modules
|
|
@@ -80,103 +44,97 @@ function __webpack_require__(moduleId) {
|
|
|
80
44
|
};
|
|
81
45
|
})();
|
|
82
46
|
/************************************************************************/ var __webpack_exports__ = {};
|
|
83
|
-
//
|
|
84
|
-
(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
47
|
+
// ESM COMPAT FLAG
|
|
48
|
+
__webpack_require__.r(__webpack_exports__);
|
|
49
|
+
// EXPORTS
|
|
50
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
51
|
+
ElectronAppUpdater: ()=>/* binding */ ElectronAppUpdater
|
|
52
|
+
});
|
|
53
|
+
const external_path_namespaceObject = require("path");
|
|
54
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
55
|
+
const external_fs_namespaceObject = require("fs");
|
|
56
|
+
var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
|
|
57
|
+
const external_axios_namespaceObject = require("axios");
|
|
58
|
+
var external_axios_default = /*#__PURE__*/ __webpack_require__.n(external_axios_namespaceObject);
|
|
59
|
+
function _define_property(obj, key, value) {
|
|
60
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
61
|
+
value: value,
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true
|
|
91
65
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
66
|
+
else obj[key] = value;
|
|
67
|
+
return obj;
|
|
68
|
+
}
|
|
69
|
+
class ElectronAppUpdater {
|
|
70
|
+
async checkVersion() {
|
|
71
|
+
const currentVersion = await this.getNowVersion();
|
|
72
|
+
const response = await external_axios_default().get(this.checkVersionUrl);
|
|
73
|
+
const data = response.data.result;
|
|
74
|
+
console.log(currentVersion, data);
|
|
75
|
+
const nowVersion = Number(currentVersion);
|
|
76
|
+
const remoteVersion = Number(data.version);
|
|
77
|
+
if (remoteVersion != nowVersion) {
|
|
78
|
+
console.log('need update');
|
|
79
|
+
await this.changeVersion(remoteVersion, data.url);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
async changeVersion(remoteVersion, url) {
|
|
85
|
+
this.dialog.showMessageBox({
|
|
86
|
+
type: 'info',
|
|
87
|
+
title: '软件升级',
|
|
88
|
+
message: `发现新版本,v${remoteVersion}, 正在下载`,
|
|
89
|
+
buttons: [
|
|
90
|
+
'是的'
|
|
91
|
+
]
|
|
108
92
|
});
|
|
109
|
-
|
|
110
|
-
|
|
93
|
+
const configPath = this.getConfigPath();
|
|
94
|
+
external_fs_default().writeFileSync(configPath, JSON.stringify({
|
|
95
|
+
version: remoteVersion
|
|
96
|
+
}));
|
|
97
|
+
const writePath = external_path_default().join(this.buildPath, 'build.js');
|
|
98
|
+
const buildResponse = await external_axios_default().get(url);
|
|
99
|
+
external_fs_default().writeFileSync(writePath, buildResponse.data);
|
|
100
|
+
setTimeout(()=>{
|
|
101
|
+
this.app.relaunch(); // 重启
|
|
102
|
+
this.app.exit(0);
|
|
103
|
+
}, 1200);
|
|
111
104
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
const data =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (remoteVersion != nowVersion) {
|
|
121
|
-
console.log('need update');
|
|
122
|
-
await this.changeVersion(remoteVersion, data.url);
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
async changeVersion(remoteVersion, url) {
|
|
128
|
-
if (electron.app.isPackaged) {
|
|
129
|
-
electron.dialog.showMessageBox({
|
|
130
|
-
type: 'info',
|
|
131
|
-
title: '软件升级',
|
|
132
|
-
message: `发现新版本,v${remoteVersion}, 正在下载`,
|
|
133
|
-
buttons: [
|
|
134
|
-
'是的'
|
|
135
|
-
]
|
|
136
|
-
});
|
|
137
|
-
const configPath = this.getConfigPath();
|
|
138
|
-
external_fs_default().writeFileSync(configPath, JSON.stringify({
|
|
139
|
-
version: remoteVersion
|
|
140
|
-
}));
|
|
141
|
-
const writePath = external_path_default().join(this.buildPath, 'build.js');
|
|
142
|
-
const buildResponse = await external_axios_default().get(url);
|
|
143
|
-
external_fs_default().writeFileSync(writePath, buildResponse.data);
|
|
144
|
-
setTimeout(()=>{
|
|
145
|
-
electron.app.relaunch(); // 重启
|
|
146
|
-
electron.app.exit(0);
|
|
147
|
-
}, 1200);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
async getNowVersion() {
|
|
151
|
-
const configPath = this.getConfigPath();
|
|
152
|
-
try {
|
|
153
|
-
const res = external_fs_default().readFileSync(configPath).toString();
|
|
154
|
-
const data = JSON.parse(res);
|
|
155
|
-
return data.version;
|
|
156
|
-
} catch (e) {
|
|
157
|
-
return 0;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
getConfigPath() {
|
|
161
|
-
const configPath = external_path_default().join(this.buildPath, this.configJSONFileName);
|
|
162
|
-
return configPath;
|
|
163
|
-
}
|
|
164
|
-
getBuildJSPath() {
|
|
165
|
-
const configPath = external_path_default().join(this.buildPath, this.buildJSFileName);
|
|
166
|
-
return configPath;
|
|
167
|
-
}
|
|
168
|
-
constructor({ checkVersionUrl, configJSONFileName, buildJSFileName }){
|
|
169
|
-
_define_property(this, "checkVersionUrl", void 0);
|
|
170
|
-
_define_property(this, "configJSONFileName", void 0);
|
|
171
|
-
_define_property(this, "buildJSFileName", void 0);
|
|
172
|
-
_define_property(this, "buildPath", void 0);
|
|
173
|
-
this.checkVersionUrl = checkVersionUrl;
|
|
174
|
-
this.configJSONFileName = configJSONFileName || 'config.json';
|
|
175
|
-
this.buildJSFileName = buildJSFileName || 'build.js';
|
|
176
|
-
this.buildPath = external_path_default().join(__dirname, '/');
|
|
105
|
+
async getNowVersion() {
|
|
106
|
+
const configPath = this.getConfigPath();
|
|
107
|
+
try {
|
|
108
|
+
const res = external_fs_default().readFileSync(configPath).toString();
|
|
109
|
+
const data = JSON.parse(res);
|
|
110
|
+
return data.version;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
return 0;
|
|
177
113
|
}
|
|
178
114
|
}
|
|
179
|
-
|
|
115
|
+
getConfigPath() {
|
|
116
|
+
const configPath = external_path_default().join(this.buildPath, this.configJSONFileName);
|
|
117
|
+
return configPath;
|
|
118
|
+
}
|
|
119
|
+
getBuildJSPath() {
|
|
120
|
+
const configPath = external_path_default().join(this.buildPath, this.buildJSFileName);
|
|
121
|
+
return configPath;
|
|
122
|
+
}
|
|
123
|
+
constructor({ checkVersionUrl, configJSONFileName, buildJSFileName, app, dialog }){
|
|
124
|
+
_define_property(this, "checkVersionUrl", void 0);
|
|
125
|
+
_define_property(this, "configJSONFileName", void 0);
|
|
126
|
+
_define_property(this, "buildJSFileName", void 0);
|
|
127
|
+
_define_property(this, "buildPath", void 0);
|
|
128
|
+
_define_property(this, "app", void 0);
|
|
129
|
+
_define_property(this, "dialog", void 0);
|
|
130
|
+
this.checkVersionUrl = checkVersionUrl;
|
|
131
|
+
this.configJSONFileName = configJSONFileName || 'config.json';
|
|
132
|
+
this.buildJSFileName = buildJSFileName || 'build.js';
|
|
133
|
+
this.buildPath = external_path_default().join(__dirname, '/');
|
|
134
|
+
this.app = app;
|
|
135
|
+
this.dialog = dialog;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
180
138
|
var __webpack_export_target__ = exports;
|
|
181
139
|
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
|
|
182
140
|
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,14 @@ export declare class ElectronAppUpdater {
|
|
|
3
3
|
configJSONFileName: string;
|
|
4
4
|
buildJSFileName: string;
|
|
5
5
|
buildPath: string;
|
|
6
|
-
|
|
6
|
+
app: any;
|
|
7
|
+
dialog: any;
|
|
8
|
+
constructor({ checkVersionUrl, configJSONFileName, buildJSFileName, app, dialog, }: {
|
|
7
9
|
checkVersionUrl: string;
|
|
8
10
|
buildJSFileName?: string;
|
|
9
11
|
configJSONFileName?: string;
|
|
12
|
+
app: any;
|
|
13
|
+
dialog: any;
|
|
10
14
|
});
|
|
11
15
|
checkVersion(): Promise<boolean>;
|
|
12
16
|
changeVersion(remoteVersion: number, url: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,49 +1,6 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
|
|
2
1
|
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE_axios__ from "axios";
|
|
4
|
-
var __webpack_modules__ = {
|
|
5
|
-
"./node_modules/.store/electron@33.2.0/node_modules/electron/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
6
|
-
const fs = __webpack_require__("fs");
|
|
7
|
-
const path = __webpack_require__("path");
|
|
8
|
-
const pathFile = path.join(__dirname, 'path.txt');
|
|
9
|
-
function getElectronPath() {
|
|
10
|
-
let executablePath;
|
|
11
|
-
if (fs.existsSync(pathFile)) executablePath = fs.readFileSync(pathFile, 'utf-8');
|
|
12
|
-
if (process.env.ELECTRON_OVERRIDE_DIST_PATH) return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath || 'electron');
|
|
13
|
-
if (executablePath) return path.join(__dirname, 'dist', executablePath);
|
|
14
|
-
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');
|
|
15
|
-
}
|
|
16
|
-
module.exports = getElectronPath();
|
|
17
|
-
},
|
|
18
|
-
fs: function(module) {
|
|
19
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_fs__;
|
|
20
|
-
},
|
|
21
|
-
path: function(module) {
|
|
22
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_path__;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
/************************************************************************/ // The module cache
|
|
26
|
-
var __webpack_module_cache__ = {};
|
|
27
|
-
// The require function
|
|
28
|
-
function __webpack_require__(moduleId) {
|
|
29
|
-
// Check if module is in cache
|
|
30
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
31
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
32
|
-
// Create a new module (and put it into the cache)
|
|
33
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
34
|
-
exports: {}
|
|
35
|
-
};
|
|
36
|
-
// Execute the module function
|
|
37
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
38
|
-
// Return the exports of the module
|
|
39
|
-
return module.exports;
|
|
40
|
-
}
|
|
41
|
-
/************************************************************************/ // EXTERNAL MODULE: external "path"
|
|
42
|
-
var external_path_ = __webpack_require__("path");
|
|
43
|
-
// EXTERNAL MODULE: external "fs"
|
|
44
|
-
var external_fs_ = __webpack_require__("fs");
|
|
45
|
-
// EXTERNAL MODULE: ./node_modules/.store/electron@33.2.0/node_modules/electron/index.js
|
|
46
|
-
var electron = __webpack_require__("./node_modules/.store/electron@33.2.0/node_modules/electron/index.js");
|
|
47
4
|
function _define_property(obj, key, value) {
|
|
48
5
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
49
6
|
value: value,
|
|
@@ -70,32 +27,30 @@ class ElectronAppUpdater {
|
|
|
70
27
|
return true;
|
|
71
28
|
}
|
|
72
29
|
async changeVersion(remoteVersion, url) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}, 1200);
|
|
93
|
-
}
|
|
30
|
+
this.dialog.showMessageBox({
|
|
31
|
+
type: 'info',
|
|
32
|
+
title: '软件升级',
|
|
33
|
+
message: `发现新版本,v${remoteVersion}, 正在下载`,
|
|
34
|
+
buttons: [
|
|
35
|
+
'是的'
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
const configPath = this.getConfigPath();
|
|
39
|
+
__WEBPACK_EXTERNAL_MODULE_fs__["default"].writeFileSync(configPath, JSON.stringify({
|
|
40
|
+
version: remoteVersion
|
|
41
|
+
}));
|
|
42
|
+
const writePath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(this.buildPath, 'build.js');
|
|
43
|
+
const buildResponse = await __WEBPACK_EXTERNAL_MODULE_axios__["default"].get(url);
|
|
44
|
+
__WEBPACK_EXTERNAL_MODULE_fs__["default"].writeFileSync(writePath, buildResponse.data);
|
|
45
|
+
setTimeout(()=>{
|
|
46
|
+
this.app.relaunch(); // 重启
|
|
47
|
+
this.app.exit(0);
|
|
48
|
+
}, 1200);
|
|
94
49
|
}
|
|
95
50
|
async getNowVersion() {
|
|
96
51
|
const configPath = this.getConfigPath();
|
|
97
52
|
try {
|
|
98
|
-
const res =
|
|
53
|
+
const res = __WEBPACK_EXTERNAL_MODULE_fs__["default"].readFileSync(configPath).toString();
|
|
99
54
|
const data = JSON.parse(res);
|
|
100
55
|
return data.version;
|
|
101
56
|
} catch (e) {
|
|
@@ -103,22 +58,26 @@ class ElectronAppUpdater {
|
|
|
103
58
|
}
|
|
104
59
|
}
|
|
105
60
|
getConfigPath() {
|
|
106
|
-
const configPath =
|
|
61
|
+
const configPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(this.buildPath, this.configJSONFileName);
|
|
107
62
|
return configPath;
|
|
108
63
|
}
|
|
109
64
|
getBuildJSPath() {
|
|
110
|
-
const configPath =
|
|
65
|
+
const configPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(this.buildPath, this.buildJSFileName);
|
|
111
66
|
return configPath;
|
|
112
67
|
}
|
|
113
|
-
constructor({ checkVersionUrl, configJSONFileName, buildJSFileName }){
|
|
68
|
+
constructor({ checkVersionUrl, configJSONFileName, buildJSFileName, app, dialog }){
|
|
114
69
|
_define_property(this, "checkVersionUrl", void 0);
|
|
115
70
|
_define_property(this, "configJSONFileName", void 0);
|
|
116
71
|
_define_property(this, "buildJSFileName", void 0);
|
|
117
72
|
_define_property(this, "buildPath", void 0);
|
|
73
|
+
_define_property(this, "app", void 0);
|
|
74
|
+
_define_property(this, "dialog", void 0);
|
|
118
75
|
this.checkVersionUrl = checkVersionUrl;
|
|
119
76
|
this.configJSONFileName = configJSONFileName || 'config.json';
|
|
120
77
|
this.buildJSFileName = buildJSFileName || 'build.js';
|
|
121
|
-
this.buildPath =
|
|
78
|
+
this.buildPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(__dirname, '/');
|
|
79
|
+
this.app = app;
|
|
80
|
+
this.dialog = dialog;
|
|
122
81
|
}
|
|
123
82
|
}
|
|
124
83
|
export { ElectronAppUpdater };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sellerartifact/electron-app-updater",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@rslib/core": "^0.1.0",
|
|
26
26
|
"@types/node": "^22.8.1",
|
|
27
|
-
"electron": "^33.2.0",
|
|
28
27
|
"prettier": "^3.3.3",
|
|
29
28
|
"typescript": "^5.6.3"
|
|
30
29
|
},
|