@sellerartifact/electron-app-updater 0.0.1
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/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/index.cjs +184 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +124 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 invalid w
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Rslib Project
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
Install the dependencies:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Get Started
|
|
12
|
+
|
|
13
|
+
Build the library:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Build the library in watch mode:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm dev
|
|
23
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
var __webpack_modules__ = {
|
|
2
|
+
"./node_modules/.store/electron@33.2.0/node_modules/electron/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
3
|
+
const fs = __webpack_require__("fs");
|
|
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
|
+
}
|
|
40
|
+
/************************************************************************/ // webpack/runtime/compat_get_default_export
|
|
41
|
+
(()=>{
|
|
42
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
43
|
+
__webpack_require__.n = function(module) {
|
|
44
|
+
var getter = module && module.__esModule ? function() {
|
|
45
|
+
return module['default'];
|
|
46
|
+
} : function() {
|
|
47
|
+
return module;
|
|
48
|
+
};
|
|
49
|
+
__webpack_require__.d(getter, {
|
|
50
|
+
a: getter
|
|
51
|
+
});
|
|
52
|
+
return getter;
|
|
53
|
+
};
|
|
54
|
+
})();
|
|
55
|
+
// webpack/runtime/define_property_getters
|
|
56
|
+
(()=>{
|
|
57
|
+
__webpack_require__.d = function(exports1, definition) {
|
|
58
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: definition[key]
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
// webpack/runtime/has_own_property
|
|
65
|
+
(()=>{
|
|
66
|
+
__webpack_require__.o = function(obj, prop) {
|
|
67
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
68
|
+
};
|
|
69
|
+
})();
|
|
70
|
+
// webpack/runtime/make_namespace_object
|
|
71
|
+
(()=>{
|
|
72
|
+
// define __esModule on exports
|
|
73
|
+
__webpack_require__.r = function(exports1) {
|
|
74
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
75
|
+
value: 'Module'
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
78
|
+
value: true
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
})();
|
|
82
|
+
/************************************************************************/ var __webpack_exports__ = {};
|
|
83
|
+
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
|
|
84
|
+
(()=>{
|
|
85
|
+
"use strict";
|
|
86
|
+
// ESM COMPAT FLAG
|
|
87
|
+
__webpack_require__.r(__webpack_exports__);
|
|
88
|
+
// EXPORTS
|
|
89
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
90
|
+
ElectronAppUpdater: ()=>/* binding */ ElectronAppUpdater
|
|
91
|
+
});
|
|
92
|
+
// EXTERNAL MODULE: external "path"
|
|
93
|
+
var external_path_ = __webpack_require__("path");
|
|
94
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_);
|
|
95
|
+
// EXTERNAL MODULE: external "fs"
|
|
96
|
+
var external_fs_ = __webpack_require__("fs");
|
|
97
|
+
var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_);
|
|
98
|
+
const external_axios_namespaceObject = require("axios");
|
|
99
|
+
var external_axios_default = /*#__PURE__*/ __webpack_require__.n(external_axios_namespaceObject);
|
|
100
|
+
// EXTERNAL MODULE: ./node_modules/.store/electron@33.2.0/node_modules/electron/index.js
|
|
101
|
+
var electron = __webpack_require__("./node_modules/.store/electron@33.2.0/node_modules/electron/index.js");
|
|
102
|
+
function _define_property(obj, key, value) {
|
|
103
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
104
|
+
value: value,
|
|
105
|
+
enumerable: true,
|
|
106
|
+
configurable: true,
|
|
107
|
+
writable: true
|
|
108
|
+
});
|
|
109
|
+
else obj[key] = value;
|
|
110
|
+
return obj;
|
|
111
|
+
}
|
|
112
|
+
class ElectronAppUpdater {
|
|
113
|
+
async checkVersion() {
|
|
114
|
+
const currentVersion = await this.getNowVersion();
|
|
115
|
+
const response = await external_axios_default().get(this.checkVersionUrl);
|
|
116
|
+
const data = response.data.result;
|
|
117
|
+
console.log(currentVersion, data);
|
|
118
|
+
const nowVersion = Number(currentVersion);
|
|
119
|
+
const remoteVersion = Number(data.version);
|
|
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, '/');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
})();
|
|
180
|
+
var __webpack_export_target__ = exports;
|
|
181
|
+
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
|
|
182
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
183
|
+
value: true
|
|
184
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class ElectronAppUpdater {
|
|
2
|
+
checkVersionUrl: string;
|
|
3
|
+
configJSONFileName: string;
|
|
4
|
+
buildJSFileName: string;
|
|
5
|
+
buildPath: string;
|
|
6
|
+
constructor({ checkVersionUrl, configJSONFileName, buildJSFileName, }: {
|
|
7
|
+
checkVersionUrl: string;
|
|
8
|
+
buildJSFileName?: string;
|
|
9
|
+
configJSONFileName?: string;
|
|
10
|
+
});
|
|
11
|
+
checkVersion(): Promise<boolean>;
|
|
12
|
+
changeVersion(remoteVersion: number, url: string): Promise<void>;
|
|
13
|
+
getNowVersion(): Promise<any>;
|
|
14
|
+
getConfigPath(): string;
|
|
15
|
+
getBuildJSPath(): string;
|
|
16
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
|
|
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
|
+
function _define_property(obj, key, value) {
|
|
48
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
49
|
+
value: value,
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true
|
|
53
|
+
});
|
|
54
|
+
else obj[key] = value;
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
class ElectronAppUpdater {
|
|
58
|
+
async checkVersion() {
|
|
59
|
+
const currentVersion = await this.getNowVersion();
|
|
60
|
+
const response = await __WEBPACK_EXTERNAL_MODULE_axios__["default"].get(this.checkVersionUrl);
|
|
61
|
+
const data = response.data.result;
|
|
62
|
+
console.log(currentVersion, data);
|
|
63
|
+
const nowVersion = Number(currentVersion);
|
|
64
|
+
const remoteVersion = Number(data.version);
|
|
65
|
+
if (remoteVersion != nowVersion) {
|
|
66
|
+
console.log('need update');
|
|
67
|
+
await this.changeVersion(remoteVersion, data.url);
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
async changeVersion(remoteVersion, url) {
|
|
73
|
+
if (electron.app.isPackaged) {
|
|
74
|
+
electron.dialog.showMessageBox({
|
|
75
|
+
type: 'info',
|
|
76
|
+
title: '软件升级',
|
|
77
|
+
message: `发现新版本,v${remoteVersion}, 正在下载`,
|
|
78
|
+
buttons: [
|
|
79
|
+
'是的'
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
const configPath = this.getConfigPath();
|
|
83
|
+
external_fs_["default"].writeFileSync(configPath, JSON.stringify({
|
|
84
|
+
version: remoteVersion
|
|
85
|
+
}));
|
|
86
|
+
const writePath = external_path_["default"].join(this.buildPath, 'build.js');
|
|
87
|
+
const buildResponse = await __WEBPACK_EXTERNAL_MODULE_axios__["default"].get(url);
|
|
88
|
+
external_fs_["default"].writeFileSync(writePath, buildResponse.data);
|
|
89
|
+
setTimeout(()=>{
|
|
90
|
+
electron.app.relaunch(); // 重启
|
|
91
|
+
electron.app.exit(0);
|
|
92
|
+
}, 1200);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async getNowVersion() {
|
|
96
|
+
const configPath = this.getConfigPath();
|
|
97
|
+
try {
|
|
98
|
+
const res = external_fs_["default"].readFileSync(configPath).toString();
|
|
99
|
+
const data = JSON.parse(res);
|
|
100
|
+
return data.version;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
getConfigPath() {
|
|
106
|
+
const configPath = external_path_["default"].join(this.buildPath, this.configJSONFileName);
|
|
107
|
+
return configPath;
|
|
108
|
+
}
|
|
109
|
+
getBuildJSPath() {
|
|
110
|
+
const configPath = external_path_["default"].join(this.buildPath, this.buildJSFileName);
|
|
111
|
+
return configPath;
|
|
112
|
+
}
|
|
113
|
+
constructor({ checkVersionUrl, configJSONFileName, buildJSFileName }){
|
|
114
|
+
_define_property(this, "checkVersionUrl", void 0);
|
|
115
|
+
_define_property(this, "configJSONFileName", void 0);
|
|
116
|
+
_define_property(this, "buildJSFileName", void 0);
|
|
117
|
+
_define_property(this, "buildPath", void 0);
|
|
118
|
+
this.checkVersionUrl = checkVersionUrl;
|
|
119
|
+
this.configJSONFileName = configJSONFileName || 'config.json';
|
|
120
|
+
this.buildJSFileName = buildJSFileName || 'build.js';
|
|
121
|
+
this.buildPath = external_path_["default"].join(__dirname, '/');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export { ElectronAppUpdater };
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sellerartifact/electron-app-updater",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rslib build",
|
|
20
|
+
"dev": "rslib build --watch",
|
|
21
|
+
"format": "prettier --write .",
|
|
22
|
+
"prepublishOnly": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@rslib/core": "^0.1.0",
|
|
26
|
+
"@types/node": "^22.8.1",
|
|
27
|
+
"electron": "^33.2.0",
|
|
28
|
+
"prettier": "^3.3.3",
|
|
29
|
+
"typescript": "^5.6.3"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"axios": "^1.7.7"
|
|
33
|
+
}
|
|
34
|
+
}
|