@sellerartifact/electron-app-updater 0.0.2 → 0.0.4

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 CHANGED
@@ -1,42 +1,6 @@
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
- }
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,101 +44,97 @@ function __webpack_require__(moduleId) {
80
44
  };
81
45
  })();
82
46
  /************************************************************************/ 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
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
- // 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
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
+ const nowVersion = currentVersion;
75
+ const remoteVersion = data.version;
76
+ console.log(currentVersion, remoteVersion);
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
- else obj[key] = value;
110
- return obj;
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, this.buildJSFileName);
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
- 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
- electron.dialog.showMessageBox({
129
- type: 'info',
130
- title: '软件升级',
131
- message: `发现新版本,v${remoteVersion}, 正在下载`,
132
- buttons: [
133
- '是的'
134
- ]
135
- });
136
- const configPath = this.getConfigPath();
137
- external_fs_default().writeFileSync(configPath, JSON.stringify({
138
- version: remoteVersion
139
- }));
140
- const writePath = external_path_default().join(this.buildPath, 'build.js');
141
- const buildResponse = await external_axios_default().get(url);
142
- external_fs_default().writeFileSync(writePath, buildResponse.data);
143
- setTimeout(()=>{
144
- electron.app.relaunch(); // 重启
145
- electron.app.exit(0);
146
- }, 1200);
147
- }
148
- async getNowVersion() {
149
- const configPath = this.getConfigPath();
150
- try {
151
- const res = external_fs_default().readFileSync(configPath).toString();
152
- const data = JSON.parse(res);
153
- return data.version;
154
- } catch (e) {
155
- return 0;
156
- }
157
- }
158
- getConfigPath() {
159
- const configPath = external_path_default().join(this.buildPath, this.configJSONFileName);
160
- return configPath;
161
- }
162
- getBuildJSPath() {
163
- const configPath = external_path_default().join(this.buildPath, this.buildJSFileName);
164
- return configPath;
165
- }
166
- constructor({ checkVersionUrl, configJSONFileName, buildJSFileName }){
167
- _define_property(this, "checkVersionUrl", void 0);
168
- _define_property(this, "configJSONFileName", void 0);
169
- _define_property(this, "buildJSFileName", void 0);
170
- _define_property(this, "buildPath", void 0);
171
- this.checkVersionUrl = checkVersionUrl;
172
- this.configJSONFileName = configJSONFileName || 'config.json';
173
- this.buildJSFileName = buildJSFileName || 'build.js';
174
- 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;
175
113
  }
176
114
  }
177
- })();
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
+ }
178
138
  var __webpack_export_target__ = exports;
179
139
  for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
180
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
- constructor({ checkVersionUrl, configJSONFileName, buildJSFileName, }: {
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,
@@ -59,9 +16,9 @@ class ElectronAppUpdater {
59
16
  const currentVersion = await this.getNowVersion();
60
17
  const response = await __WEBPACK_EXTERNAL_MODULE_axios__["default"].get(this.checkVersionUrl);
61
18
  const data = response.data.result;
62
- console.log(currentVersion, data);
63
- const nowVersion = Number(currentVersion);
64
- const remoteVersion = Number(data.version);
19
+ const nowVersion = currentVersion;
20
+ const remoteVersion = data.version;
21
+ console.log(currentVersion, remoteVersion);
65
22
  if (remoteVersion != nowVersion) {
66
23
  console.log('need update');
67
24
  await this.changeVersion(remoteVersion, data.url);
@@ -70,7 +27,7 @@ class ElectronAppUpdater {
70
27
  return true;
71
28
  }
72
29
  async changeVersion(remoteVersion, url) {
73
- electron.dialog.showMessageBox({
30
+ this.dialog.showMessageBox({
74
31
  type: 'info',
75
32
  title: '软件升级',
76
33
  message: `发现新版本,v${remoteVersion}, 正在下载`,
@@ -79,21 +36,21 @@ class ElectronAppUpdater {
79
36
  ]
80
37
  });
81
38
  const configPath = this.getConfigPath();
82
- external_fs_["default"].writeFileSync(configPath, JSON.stringify({
39
+ __WEBPACK_EXTERNAL_MODULE_fs__["default"].writeFileSync(configPath, JSON.stringify({
83
40
  version: remoteVersion
84
41
  }));
85
- const writePath = external_path_["default"].join(this.buildPath, 'build.js');
42
+ const writePath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(this.buildPath, this.buildJSFileName);
86
43
  const buildResponse = await __WEBPACK_EXTERNAL_MODULE_axios__["default"].get(url);
87
- external_fs_["default"].writeFileSync(writePath, buildResponse.data);
44
+ __WEBPACK_EXTERNAL_MODULE_fs__["default"].writeFileSync(writePath, buildResponse.data);
88
45
  setTimeout(()=>{
89
- electron.app.relaunch(); // 重启
90
- electron.app.exit(0);
46
+ this.app.relaunch(); // 重启
47
+ this.app.exit(0);
91
48
  }, 1200);
92
49
  }
93
50
  async getNowVersion() {
94
51
  const configPath = this.getConfigPath();
95
52
  try {
96
- const res = external_fs_["default"].readFileSync(configPath).toString();
53
+ const res = __WEBPACK_EXTERNAL_MODULE_fs__["default"].readFileSync(configPath).toString();
97
54
  const data = JSON.parse(res);
98
55
  return data.version;
99
56
  } catch (e) {
@@ -101,22 +58,26 @@ class ElectronAppUpdater {
101
58
  }
102
59
  }
103
60
  getConfigPath() {
104
- const configPath = external_path_["default"].join(this.buildPath, this.configJSONFileName);
61
+ const configPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(this.buildPath, this.configJSONFileName);
105
62
  return configPath;
106
63
  }
107
64
  getBuildJSPath() {
108
- const configPath = external_path_["default"].join(this.buildPath, this.buildJSFileName);
65
+ const configPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(this.buildPath, this.buildJSFileName);
109
66
  return configPath;
110
67
  }
111
- constructor({ checkVersionUrl, configJSONFileName, buildJSFileName }){
68
+ constructor({ checkVersionUrl, configJSONFileName, buildJSFileName, app, dialog }){
112
69
  _define_property(this, "checkVersionUrl", void 0);
113
70
  _define_property(this, "configJSONFileName", void 0);
114
71
  _define_property(this, "buildJSFileName", void 0);
115
72
  _define_property(this, "buildPath", void 0);
73
+ _define_property(this, "app", void 0);
74
+ _define_property(this, "dialog", void 0);
116
75
  this.checkVersionUrl = checkVersionUrl;
117
76
  this.configJSONFileName = configJSONFileName || 'config.json';
118
77
  this.buildJSFileName = buildJSFileName || 'build.js';
119
- this.buildPath = external_path_["default"].join(__dirname, '/');
78
+ this.buildPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(__dirname, '/');
79
+ this.app = app;
80
+ this.dialog = dialog;
120
81
  }
121
82
  }
122
83
  export { ElectronAppUpdater };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sellerartifact/electron-app-updater",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
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
  },