hunter-open-sdk 2.0.0-beta.14 → 2.0.0-beta.16
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/lib/abilities/activate/worker.js +8 -2
- package/lib/abilities/erase/worker.js +8 -2
- package/lib/abilities/getGeneralReport/worker.js +8 -2
- package/lib/abilities/getSaaSReport/worker.js +9 -2
- package/lib/abilities/reboot/index.js +54 -0
- package/lib/abilities/reboot/worker.js +30 -0
- package/lib/abilities/shutdown/index.js +54 -0
- package/lib/abilities/shutdown/worker.js +30 -0
- package/lib/abilities/skip/worker.js +8 -2
- package/lib/index.js +5 -1
- package/lib/resources/dll/{libinspectionkit_x64_0.2.1.dll → libinspectionkit_x64_0.3.0.dll} +0 -0
- package/lib/resources/mac/{libinspectionkit_amd64_0.2.1.dylib → libinspectionkit_amd64_0.3.0.dylib} +0 -0
- package/lib/resources/mac/{libinspectionkit_arm64_0.2.1.dylib → libinspectionkit_arm64_0.3.0.dylib} +0 -0
- package/lib/resources/version.online +1 -1
- package/lib/utils/utils.global.js +82 -3
- package/lib/utils/utils.initDll.js +1 -1
- package/lib/utils/utils.path.js +8 -11
- package/lib/utils/utils.process.js +12 -0
- package/lib/utils/utils.worker.js +32 -0
- package/package.json +1 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const {
|
|
4
|
+
initWorkerNodePath
|
|
5
|
+
} = require("../../utils/utils.worker");
|
|
6
|
+
initWorkerNodePath();
|
|
7
|
+
const {
|
|
8
|
+
activateCallKit
|
|
9
|
+
} = require("../../utils/utils.global");
|
|
4
10
|
function onMainMessage(event) {
|
|
5
11
|
const {
|
|
6
12
|
type,
|
|
@@ -15,7 +21,7 @@ function onMainMessage(event) {
|
|
|
15
21
|
message: '【activate】方法缺少必要参数'
|
|
16
22
|
};
|
|
17
23
|
}
|
|
18
|
-
const res =
|
|
24
|
+
const res = activateCallKit(params);
|
|
19
25
|
postMessage(res);
|
|
20
26
|
break;
|
|
21
27
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const {
|
|
4
|
+
initWorkerNodePath
|
|
5
|
+
} = require("../../utils/utils.worker");
|
|
6
|
+
initWorkerNodePath();
|
|
7
|
+
const {
|
|
8
|
+
eraseCallKit
|
|
9
|
+
} = require("../../utils/utils.global");
|
|
4
10
|
function onMainMessage(event) {
|
|
5
11
|
const {
|
|
6
12
|
type,
|
|
@@ -15,7 +21,7 @@ function onMainMessage(event) {
|
|
|
15
21
|
message: '【erase】方法缺少必要参数'
|
|
16
22
|
};
|
|
17
23
|
}
|
|
18
|
-
const res =
|
|
24
|
+
const res = eraseCallKit(params);
|
|
19
25
|
postMessage(res);
|
|
20
26
|
break;
|
|
21
27
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const {
|
|
4
|
+
initWorkerNodePath
|
|
5
|
+
} = require("../../utils/utils.worker");
|
|
6
|
+
initWorkerNodePath();
|
|
7
|
+
const {
|
|
8
|
+
getGeneralReportCallKit
|
|
9
|
+
} = require("../../utils/utils.global");
|
|
4
10
|
const MAX_RETRY_COUNT = 3;
|
|
5
11
|
const RETRY_INTERVAL = 300;
|
|
6
12
|
|
|
@@ -19,7 +25,7 @@ function onMainMessage(event, retryCount = 0) {
|
|
|
19
25
|
message: '【getGeneralReport】方法缺少必要参数'
|
|
20
26
|
};
|
|
21
27
|
}
|
|
22
|
-
const reportRes =
|
|
28
|
+
const reportRes = getGeneralReportCallKit(params);
|
|
23
29
|
console.log(`第${retryCount + 1}次获取报告:`, reportRes);
|
|
24
30
|
const {
|
|
25
31
|
data: {
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const {
|
|
4
|
+
initWorkerNodePath
|
|
5
|
+
} = require("../../utils/utils.worker");
|
|
6
|
+
initWorkerNodePath();
|
|
7
|
+
const {
|
|
8
|
+
getSaaSReportCallKit
|
|
9
|
+
} = require("../../utils/utils.global");
|
|
10
|
+
|
|
4
11
|
// 处理主进程消息
|
|
5
12
|
function onMainMessage(event) {
|
|
6
13
|
const {
|
|
@@ -9,7 +16,7 @@ function onMainMessage(event) {
|
|
|
9
16
|
} = event.data;
|
|
10
17
|
switch (type) {
|
|
11
18
|
case 'getSaaSReport':
|
|
12
|
-
const reportRes =
|
|
19
|
+
const reportRes = getSaaSReportCallKit(params);
|
|
13
20
|
postMessage(reportRes);
|
|
14
21
|
break;
|
|
15
22
|
default:
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.reboot = reboot;
|
|
7
|
+
var _webWorker = _interopRequireDefault(require("web-worker"));
|
|
8
|
+
var _url = _interopRequireDefault(require("url"));
|
|
9
|
+
var _utils = require("../../utils/utils.path");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
class Reboot {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.initWorker();
|
|
14
|
+
this.initWorkerListener();
|
|
15
|
+
}
|
|
16
|
+
worker = null;
|
|
17
|
+
callback = null;
|
|
18
|
+
exec(params, callback) {
|
|
19
|
+
this.callback = callback;
|
|
20
|
+
this.worker && this.worker.postMessage({
|
|
21
|
+
type: 'reboot',
|
|
22
|
+
params
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
initWorkerListener() {
|
|
26
|
+
this.worker && this.worker.addEventListener('message', event => {
|
|
27
|
+
const {
|
|
28
|
+
type,
|
|
29
|
+
data
|
|
30
|
+
} = event.data;
|
|
31
|
+
switch (type) {
|
|
32
|
+
case 'rebootSuccess':
|
|
33
|
+
this.callback(data);
|
|
34
|
+
break;
|
|
35
|
+
case 'rebootFail':
|
|
36
|
+
this.callback(data);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
this.callback = null;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
initWorker() {
|
|
43
|
+
if (!this.worker) {
|
|
44
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils.getCurrentEnvPath)(__dirname, './worker.js'));
|
|
45
|
+
this.worker = new _webWorker.default(workerPath, {
|
|
46
|
+
type: "module"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const entity = new Reboot();
|
|
52
|
+
function reboot(paramStr, callback) {
|
|
53
|
+
entity.exec(paramStr, callback);
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
initWorkerNodePath
|
|
5
|
+
} = require("../../utils/utils.worker");
|
|
6
|
+
initWorkerNodePath();
|
|
7
|
+
const {
|
|
8
|
+
rebootCallKit
|
|
9
|
+
} = require("../../utils/utils.global");
|
|
10
|
+
function onMainMessage(event) {
|
|
11
|
+
const {
|
|
12
|
+
type,
|
|
13
|
+
params
|
|
14
|
+
} = event.data;
|
|
15
|
+
switch (type) {
|
|
16
|
+
case 'reboot':
|
|
17
|
+
{
|
|
18
|
+
if (!params) {
|
|
19
|
+
return {
|
|
20
|
+
code: -1,
|
|
21
|
+
message: '【reboot】方法缺少必要参数'
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const res = rebootCallKit(params);
|
|
25
|
+
postMessage(res);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
addEventListener('message', onMainMessage);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.shutdown = shutdown;
|
|
7
|
+
var _webWorker = _interopRequireDefault(require("web-worker"));
|
|
8
|
+
var _url = _interopRequireDefault(require("url"));
|
|
9
|
+
var _utils = require("../../utils/utils.path");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
class Shutdown {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.initWorker();
|
|
14
|
+
this.initWorkerListener();
|
|
15
|
+
}
|
|
16
|
+
worker = null;
|
|
17
|
+
callback = null;
|
|
18
|
+
exec(params, callback) {
|
|
19
|
+
this.callback = callback;
|
|
20
|
+
this.worker && this.worker.postMessage({
|
|
21
|
+
type: 'shutdown',
|
|
22
|
+
params
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
initWorkerListener() {
|
|
26
|
+
this.worker && this.worker.addEventListener('message', event => {
|
|
27
|
+
const {
|
|
28
|
+
type,
|
|
29
|
+
data
|
|
30
|
+
} = event.data;
|
|
31
|
+
switch (type) {
|
|
32
|
+
case 'shutdownSuccess':
|
|
33
|
+
this.callback(data);
|
|
34
|
+
break;
|
|
35
|
+
case 'shutdownFail':
|
|
36
|
+
this.callback(data);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
this.callback = null;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
initWorker() {
|
|
43
|
+
if (!this.worker) {
|
|
44
|
+
const workerPath = new _url.default.URL('file://' + (0, _utils.getCurrentEnvPath)(__dirname, './worker.js'));
|
|
45
|
+
this.worker = new _webWorker.default(workerPath, {
|
|
46
|
+
type: "module"
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const entity = new Shutdown();
|
|
52
|
+
function shutdown(paramStr, callback) {
|
|
53
|
+
entity.exec(paramStr, callback);
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
initWorkerNodePath
|
|
5
|
+
} = require("../../utils/utils.worker");
|
|
6
|
+
initWorkerNodePath();
|
|
7
|
+
const {
|
|
8
|
+
shutdownCallKit
|
|
9
|
+
} = require("../../utils/utils.global");
|
|
10
|
+
function onMainMessage(event) {
|
|
11
|
+
const {
|
|
12
|
+
type,
|
|
13
|
+
params
|
|
14
|
+
} = event.data;
|
|
15
|
+
switch (type) {
|
|
16
|
+
case 'shutdown':
|
|
17
|
+
{
|
|
18
|
+
if (!params) {
|
|
19
|
+
return {
|
|
20
|
+
code: -1,
|
|
21
|
+
message: '【shutdown】方法缺少必要参数'
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const res = shutdownCallKit(params);
|
|
25
|
+
postMessage(res);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
addEventListener('message', onMainMessage);
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const {
|
|
4
|
+
initWorkerNodePath
|
|
5
|
+
} = require("../../utils/utils.worker");
|
|
6
|
+
initWorkerNodePath();
|
|
7
|
+
const {
|
|
8
|
+
skipCallKit
|
|
9
|
+
} = require("../../utils/utils.global");
|
|
4
10
|
function onMainMessage(event) {
|
|
5
11
|
const {
|
|
6
12
|
type,
|
|
@@ -15,7 +21,7 @@ function onMainMessage(event) {
|
|
|
15
21
|
message: '【skip】方法缺少必要参数'
|
|
16
22
|
};
|
|
17
23
|
}
|
|
18
|
-
const res =
|
|
24
|
+
const res = skipCallKit(params);
|
|
19
25
|
postMessage(res);
|
|
20
26
|
break;
|
|
21
27
|
}
|
package/lib/index.js
CHANGED
|
@@ -11,6 +11,8 @@ var _getGeneralReport = require("./abilities/getGeneralReport");
|
|
|
11
11
|
var _erase = require("./abilities/erase");
|
|
12
12
|
var _activate = require("./abilities/activate");
|
|
13
13
|
var _skip = require("./abilities/skip");
|
|
14
|
+
var _reboot = require("./abilities/reboot");
|
|
15
|
+
var _shutdown = require("./abilities/shutdown");
|
|
14
16
|
const Sentry = require('@sentry/browser');
|
|
15
17
|
Sentry.init({
|
|
16
18
|
dsn: 'https://8a5296c59083430fbac0756f56ddbf5d@sentry.zhuanzhuan.com/2300',
|
|
@@ -27,5 +29,7 @@ var _default = exports.default = {
|
|
|
27
29
|
getGeneralReport: _getGeneralReport.getGeneralReport,
|
|
28
30
|
erase: _erase.erase,
|
|
29
31
|
activate: _activate.activate,
|
|
30
|
-
skip: _skip.skip
|
|
32
|
+
skip: _skip.skip,
|
|
33
|
+
reboot: _reboot.reboot,
|
|
34
|
+
shutdown: _shutdown.shutdown
|
|
31
35
|
};
|
|
Binary file
|
package/lib/resources/mac/{libinspectionkit_amd64_0.2.1.dylib → libinspectionkit_amd64_0.3.0.dylib}
RENAMED
|
Binary file
|
package/lib/resources/mac/{libinspectionkit_arm64_0.2.1.dylib → libinspectionkit_arm64_0.3.0.dylib}
RENAMED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.3.0
|
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.skipCallKit = exports.setGlobalProperty = exports.hasGlobalProperty = exports.getSaaSReportCallKit = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.getGeneralReportCallKit = exports.eraseCallKit = exports.deleteGlobalProperty = exports.callHunterInspectionKit = exports.activateCallKit = void 0;
|
|
6
|
+
exports.skipCallKit = exports.shutdownCallKit = exports.setGlobalProperty = exports.rebootCallKit = exports.hasGlobalProperty = exports.getSaaSReportCallKit = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.getGeneralReportCallKit = exports.eraseCallKit = exports.deleteGlobalProperty = exports.callHunterInspectionKit = exports.activateCallKit = void 0;
|
|
7
7
|
var _utils = require("../utils/utils.initDll");
|
|
8
|
+
var Sentry = _interopRequireWildcard(require("@sentry/browser"));
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
8
11
|
/**
|
|
9
12
|
* 全局对象兼容性处理工具
|
|
10
13
|
* 兼容Electron主进程(global)和渲染进程(window)环境
|
|
11
14
|
*/
|
|
12
|
-
|
|
15
|
+
|
|
13
16
|
/**
|
|
14
17
|
* 获取全局对象
|
|
15
18
|
* @returns {Object} 全局对象
|
|
@@ -315,4 +318,80 @@ const skipCallKit = paramStr => {
|
|
|
315
318
|
}
|
|
316
319
|
};
|
|
317
320
|
};
|
|
318
|
-
exports.skipCallKit = skipCallKit;
|
|
321
|
+
exports.skipCallKit = skipCallKit;
|
|
322
|
+
const rebootCallKit = paramStr => {
|
|
323
|
+
const res = callHunterInspectionKit('InspectionKit', paramStr, 'reboot', paramStr);
|
|
324
|
+
if (res) {
|
|
325
|
+
const resObj = JSON.parse(res);
|
|
326
|
+
const {
|
|
327
|
+
Code,
|
|
328
|
+
Data,
|
|
329
|
+
Message
|
|
330
|
+
} = resObj;
|
|
331
|
+
if (Code == 0) {
|
|
332
|
+
return {
|
|
333
|
+
type: 'rebootSuccess',
|
|
334
|
+
data: {
|
|
335
|
+
code: 0,
|
|
336
|
+
data: Data,
|
|
337
|
+
message: '重启设备成功'
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
type: 'rebootFail',
|
|
343
|
+
data: {
|
|
344
|
+
code: -1,
|
|
345
|
+
data: {},
|
|
346
|
+
message: Message || '重启设备失败'
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
type: 'rebootFail',
|
|
352
|
+
data: {
|
|
353
|
+
code: -1,
|
|
354
|
+
data: {},
|
|
355
|
+
message: '重启设备失败'
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
exports.rebootCallKit = rebootCallKit;
|
|
360
|
+
const shutdownCallKit = paramStr => {
|
|
361
|
+
const res = callHunterInspectionKit('InspectionKit', paramStr, 'shutdown', paramStr);
|
|
362
|
+
if (res) {
|
|
363
|
+
const resObj = JSON.parse(res);
|
|
364
|
+
const {
|
|
365
|
+
Code,
|
|
366
|
+
Data,
|
|
367
|
+
Message
|
|
368
|
+
} = resObj;
|
|
369
|
+
if (Code == 0) {
|
|
370
|
+
return {
|
|
371
|
+
type: 'shutdownSuccess',
|
|
372
|
+
data: {
|
|
373
|
+
code: 0,
|
|
374
|
+
data: Data,
|
|
375
|
+
message: '关闭设备成功'
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
type: 'shutdownFail',
|
|
381
|
+
data: {
|
|
382
|
+
code: -1,
|
|
383
|
+
data: {},
|
|
384
|
+
message: Message || '关闭设备失败'
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
type: 'shutdownFail',
|
|
390
|
+
data: {
|
|
391
|
+
code: -1,
|
|
392
|
+
data: {},
|
|
393
|
+
message: '关闭设备失败'
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
exports.shutdownCallKit = shutdownCallKit;
|
|
@@ -22,7 +22,7 @@ const initHunterInspectionKit = () => {
|
|
|
22
22
|
|
|
23
23
|
// 读取本地sdk的version
|
|
24
24
|
const versionPath = _path.default.resolve(__dirname, '../resources/version.online');
|
|
25
|
-
const version = _fs.default.readFileSync(versionPath, 'utf-8');
|
|
25
|
+
const version = _fs.default.readFileSync(versionPath, 'utf-8').trim();
|
|
26
26
|
if ((0, _utils.isMac)()) {
|
|
27
27
|
if ((0, _utils.isArm64)()) {
|
|
28
28
|
dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_arm64_${version}.dylib`);
|
package/lib/utils/utils.path.js
CHANGED
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getCurrentEnvPath = getCurrentEnvPath;
|
|
7
|
-
exports.
|
|
7
|
+
exports.getCurrentNodePath = getCurrentNodePath;
|
|
8
|
+
exports.getPathWithCWD = getPathWithCWD;
|
|
8
9
|
var _path = _interopRequireDefault(require("path"));
|
|
9
10
|
var _process = _interopRequireDefault(require("process"));
|
|
10
11
|
var _utils = require("./utils.env");
|
|
@@ -21,14 +22,10 @@ function getCurrentEnvPath(dirPath, filePath = '') {
|
|
|
21
22
|
}
|
|
22
23
|
return _path.default.resolve(fixPath, filePath);
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} else {
|
|
31
|
-
return '这是在 Electron 的渲染进程中';
|
|
32
|
-
}
|
|
33
|
-
}
|
|
25
|
+
function getPathWithCWD(dirPath) {
|
|
26
|
+
const cwd = _process.default.cwd();
|
|
27
|
+
return _path.default.join(cwd, dirPath);
|
|
28
|
+
}
|
|
29
|
+
function getCurrentNodePath() {
|
|
30
|
+
return _process.default.env.NODE_PATH || '';
|
|
34
31
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getCurrentProcess = getCurrentProcess;
|
|
6
7
|
exports.getProccessType = getProccessType;
|
|
7
8
|
exports.isInMainProcess = isInMainProcess;
|
|
8
9
|
exports.isInRenderProcess = isInRenderProcess;
|
|
@@ -20,4 +21,15 @@ function isInMainProcess() {
|
|
|
20
21
|
// eslint-disable-next-line no-unused-vars
|
|
21
22
|
function isInRenderProcess() {
|
|
22
23
|
return getProccessType() === 'renderer';
|
|
24
|
+
}
|
|
25
|
+
function getCurrentProcess() {
|
|
26
|
+
if (typeof process === 'undefined' || process.type === undefined) {
|
|
27
|
+
return '这是在浏览器环境中';
|
|
28
|
+
} else {
|
|
29
|
+
if (process.type === 'browser') {
|
|
30
|
+
return '这是在 Node.js 环境中';
|
|
31
|
+
} else {
|
|
32
|
+
return '这是在 Electron 的渲染进程中';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
23
35
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAsarNodePath = getAsarNodePath;
|
|
7
|
+
exports.initWorkerNodePath = initWorkerNodePath;
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const _module = require('module');
|
|
10
|
+
const {
|
|
11
|
+
getPathWithCWD,
|
|
12
|
+
getCurrentNodePath
|
|
13
|
+
} = require("./utils.path");
|
|
14
|
+
function getAsarNodePath() {
|
|
15
|
+
const asarRoot = getPathWithCWD('app.asar');
|
|
16
|
+
const unpackedRoot = asarRoot.replace('app.asar', 'app.asar.unpacked');
|
|
17
|
+
const nodeModulesPaths = [path.join(asarRoot, 'node_modules'), path.join(unpackedRoot, 'node_modules')];
|
|
18
|
+
return nodeModulesPaths.join(path.delimiter);
|
|
19
|
+
}
|
|
20
|
+
function initWorkerNodePath() {
|
|
21
|
+
const currentNodePath = getCurrentNodePath();
|
|
22
|
+
if (currentNodePath.includes('app.asar') && currentNodePath.includes('app.asar.unpacked')) {
|
|
23
|
+
console.log('Has process.env.NODE_PATH =>', process.env.NODE_PATH);
|
|
24
|
+
_module.Module._initPaths();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const asarNodePath = getAsarNodePath();
|
|
28
|
+
const nodePathArr = [currentNodePath, asarNodePath];
|
|
29
|
+
process.env.NODE_PATH = nodePathArr.filter(Boolean).join(path.delimiter);
|
|
30
|
+
console.log('Set process.env.NODE_PATH =>', process.env.NODE_PATH);
|
|
31
|
+
_module.Module._initPaths();
|
|
32
|
+
}
|