hunter-open-sdk 2.0.0-beta.20 → 2.0.0-beta.22

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.
@@ -34,15 +34,18 @@ class Activate {
34
34
  }
35
35
  initWorker() {
36
36
  if (!this.worker) {
37
- const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
37
+ const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
38
38
  this.worker = new _webWorker.default(workerPath, {
39
39
  type: 'module'
40
40
  });
41
41
  }
42
42
  }
43
43
  }
44
- const entity = new Activate();
44
+ let entity = null;
45
45
  function activate(params, callback) {
46
+ if (!entity) {
47
+ entity = new Activate();
48
+ }
46
49
  const payload = (0, _utils.parsePayload)(params);
47
50
  entity.exec(payload, callback);
48
51
  }
@@ -34,15 +34,18 @@ class Erase {
34
34
  }
35
35
  initWorker() {
36
36
  if (!this.worker) {
37
- const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
37
+ const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
38
38
  this.worker = new _webWorker.default(workerPath, {
39
39
  type: 'module'
40
40
  });
41
41
  }
42
42
  }
43
43
  }
44
- const entity = new Erase();
44
+ let entity = null;
45
45
  function erase(params, callback) {
46
+ if (!entity) {
47
+ entity = new Erase();
48
+ }
46
49
  const payload = (0, _utils.parsePayload)(params);
47
50
  entity.exec(payload, callback);
48
51
  }
@@ -21,7 +21,7 @@ class WorkerPool {
21
21
  }
22
22
  }
23
23
  _createWorker() {
24
- const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
24
+ const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
25
25
  return new _webWorker.default(workerPath, {
26
26
  type: 'module'
27
27
  });
@@ -53,12 +53,23 @@ class WorkerPool {
53
53
  });
54
54
  }
55
55
  }
56
- let pool = new WorkerPool(DEFAULT_POOL_SIZE);
56
+ let pool = null;
57
57
  function getGeneralReport(params, callback, options = {}) {
58
58
  const cb = typeof callback === 'function' ? callback : _utils3.defaultCallback;
59
59
  const payload = (0, _utils.parsePayload)(params);
60
- if (options?.poolSize != null && options.poolSize !== pool.poolSize) {
61
- pool = new WorkerPool(options.poolSize);
60
+ const {
61
+ useMultiWorker = false,
62
+ poolSize = DEFAULT_POOL_SIZE
63
+ } = options;
64
+ if (!useMultiWorker) {
65
+ if (!pool || pool.poolSize !== 1) {
66
+ pool = new WorkerPool(1);
67
+ }
68
+ } else {
69
+ const targetSize = poolSize;
70
+ if (!pool || pool.poolSize !== targetSize) {
71
+ pool = new WorkerPool(targetSize);
72
+ }
62
73
  }
63
74
  pool.exec(payload, cb);
64
75
  }
@@ -34,15 +34,18 @@ class GetSaaSReport {
34
34
  }
35
35
  initWorker() {
36
36
  if (!this.worker) {
37
- const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
37
+ const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
38
38
  this.worker = new _webWorker.default(workerPath, {
39
39
  type: 'module'
40
40
  });
41
41
  }
42
42
  }
43
43
  }
44
- const entity = new GetSaaSReport();
44
+ let entity = null;
45
45
  function getSaaSReport(params, callback) {
46
+ if (!entity) {
47
+ entity = new GetSaaSReport();
48
+ }
46
49
  const payload = (0, _utils.parsePayload)(params);
47
50
  entity.exec(payload, callback);
48
51
  }
@@ -34,15 +34,18 @@ class InstallApp {
34
34
  }
35
35
  initWorker() {
36
36
  if (!this.worker) {
37
- const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
37
+ const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
38
38
  this.worker = new _webWorker.default(workerPath, {
39
39
  type: 'module'
40
40
  });
41
41
  }
42
42
  }
43
43
  }
44
- const entity = new InstallApp();
44
+ let entity = null;
45
45
  function installApp(params, callback) {
46
+ if (!entity) {
47
+ entity = new InstallApp();
48
+ }
46
49
  const payload = (0, _utils.parsePayload)(params);
47
50
  entity.exec(payload, callback);
48
51
  }
@@ -34,15 +34,18 @@ class Reboot {
34
34
  }
35
35
  initWorker() {
36
36
  if (!this.worker) {
37
- const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
37
+ const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
38
38
  this.worker = new _webWorker.default(workerPath, {
39
39
  type: "module"
40
40
  });
41
41
  }
42
42
  }
43
43
  }
44
- const entity = new Reboot();
44
+ let entity = null;
45
45
  function reboot(params, callback) {
46
+ if (!entity) {
47
+ entity = new Reboot();
48
+ }
46
49
  const payload = (0, _utils.parsePayload)(params);
47
50
  entity.exec(payload, callback);
48
51
  }
@@ -34,15 +34,18 @@ class Shutdown {
34
34
  }
35
35
  initWorker() {
36
36
  if (!this.worker) {
37
- const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
37
+ const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
38
38
  this.worker = new _webWorker.default(workerPath, {
39
39
  type: "module"
40
40
  });
41
41
  }
42
42
  }
43
43
  }
44
- const entity = new Shutdown();
44
+ let entity = null;
45
45
  function shutdown(params, callback) {
46
+ if (!entity) {
47
+ entity = new Shutdown();
48
+ }
46
49
  const payload = (0, _utils.parsePayload)(params);
47
50
  entity.exec(payload, callback);
48
51
  }
@@ -34,15 +34,18 @@ class Skip {
34
34
  }
35
35
  initWorker() {
36
36
  if (!this.worker) {
37
- const workerPath = new _url.default.URL('file://' + (0, _utils2.getCurrentEnvPath)(__dirname, './worker.js'));
37
+ const workerPath = new _url.default.URL('file://' + (0, _utils2.convertPathWithCurrentEnv)(__dirname, './worker.js'));
38
38
  this.worker = new _webWorker.default(workerPath, {
39
39
  type: 'module'
40
40
  });
41
41
  }
42
42
  }
43
43
  }
44
- const entity = new Skip();
44
+ let entity = null;
45
45
  function skip(params, callback) {
46
+ if (!entity) {
47
+ entity = new Skip();
48
+ }
46
49
  const payload = (0, _utils.parsePayload)(params);
47
50
  entity.exec(payload, callback);
48
51
  }
@@ -247,7 +247,7 @@ async function checkHasDriver() {
247
247
  // 仅存在安装包 进行解压安装
248
248
  case 2:
249
249
  const uncopressing = await uncopressingFile(filePath);
250
- if (uncopressing) installDriver();
250
+ if (uncopressing) await installDriver();
251
251
  return true;
252
252
 
253
253
  // state = 0,
package/lib/index.js CHANGED
@@ -15,12 +15,13 @@ var _reboot = require("./abilities/reboot");
15
15
  var _shutdown = require("./abilities/shutdown");
16
16
  var _installApp = require("./abilities/installApp");
17
17
  const Sentry = require('@sentry/browser');
18
+
19
+ // 初始化 Sentry 用于错误捕获
18
20
  Sentry.init({
19
21
  dsn: 'https://8a5296c59083430fbac0756f56ddbf5d@sentry.zhuanzhuan.com/2300',
20
22
  tracesSampleRate: 1.0
21
23
  });
22
24
  console.log('Sentry initialized');
23
- // 初始化
24
25
  var _default = exports.default = {
25
26
  registerEvent: _eventManager.registerEvent,
26
27
  unregisterEvent: _eventManager.unregisterEvent,
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -122,7 +122,7 @@ const callHunterInspectionKit = (methodName, ...args) => {
122
122
  */
123
123
  exports.callHunterInspectionKit = callHunterInspectionKit;
124
124
  function abilityCallKit(cmd, payload) {
125
- console.log(`调用【${cmd}】方法,参数:`, payload);
125
+ console.log(`调用【${cmd}】方法,参数:`, JSON.stringify(payload));
126
126
  const {
127
127
  biz = "",
128
128
  params
@@ -21,21 +21,21 @@ const initHunterInspectionKit = () => {
21
21
  let dllPath;
22
22
 
23
23
  // 读取本地sdk的version
24
- const versionPath = _path.default.resolve(__dirname, '../resources/version.online');
24
+ const versionPath = (0, _utils3.getPathWithLocalResource)('version.online');
25
25
  const version = _fs.default.readFileSync(versionPath, 'utf-8').trim();
26
26
  if ((0, _utils.isMac)()) {
27
27
  if ((0, _utils.isArm64)()) {
28
- dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_arm64_${version}.dylib`);
28
+ dllPath = (0, _utils3.getPathWithLocalResource)(`mac/libinspectionkit_arm64_${version}.dylib`);
29
29
  }
30
30
  if ((0, _utils.isAmd64)()) {
31
- dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_amd64_${version}.dylib`);
31
+ dllPath = (0, _utils3.getPathWithLocalResource)(`mac/libinspectionkit_amd64_${version}.dylib`);
32
32
  }
33
33
  } else {
34
- dllPath = _path.default.resolve(__dirname, `../resources/dll/libinspectionkit_x64_${version}.dll`);
34
+ dllPath = (0, _utils3.getPathWithLocalResource)(`dll/libinspectionkit_x64_${version}.dll`);
35
35
  }
36
36
  if (!(0, _utils.isDev)()) {
37
37
  // 如果是生产模式 则替换app.asar 路径 为了在生产调用dll
38
- dllPath = (0, _utils3.getCurrentEnvPath)(dllPath);
38
+ dllPath = (0, _utils3.convertPathWithCurrentEnv)(dllPath);
39
39
  }
40
40
  const dllLib = _koffi.default.load(dllPath);
41
41
  const dllKit = {
@@ -3,29 +3,63 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getCurrentEnvPath = getCurrentEnvPath;
6
+ exports.convertPathWithCurrentEnv = convertPathWithCurrentEnv;
7
7
  exports.getCurrentNodePath = getCurrentNodePath;
8
8
  exports.getPathWithCWD = getPathWithCWD;
9
+ exports.getPathWithElectornResource = getPathWithElectornResource;
10
+ exports.getPathWithLocalResource = getPathWithLocalResource;
9
11
  var _path = _interopRequireDefault(require("path"));
10
12
  var _process = _interopRequireDefault(require("process"));
11
13
  var _utils = require("./utils.env");
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
  /**
14
16
  * 当前环境地址转换
15
- * @param {*} path
17
+ * @param {*} dirPath 目录路径
18
+ * @param {*} filePath 文件路径,默认为空字符串
16
19
  * @returns
17
20
  */
18
- function getCurrentEnvPath(dirPath, filePath = '') {
21
+ function convertPathWithCurrentEnv(dirPath, filePath = '') {
19
22
  let fixPath = dirPath;
20
23
  if (!(0, _utils.isDev)()) {
21
- fixPath = fixPath.replace('/app.asar/', '/app.asar.unpacked/').replace(/\\app.asar\\/, /\\app.asar.unpacked\\/);
24
+ fixPath = fixPath.replace('/app.asar/', '/app.asar.unpacked/').replace('\\app.asar\\', '\\app.asar.unpacked\\');
22
25
  }
23
- return _path.default.resolve(fixPath, filePath);
26
+ return _path.default.join(fixPath, filePath);
24
27
  }
28
+
29
+ /**
30
+ * 当前项目resources目录地址转换
31
+ * @param {*} dirPath
32
+ * @returns
33
+ */
34
+ function getPathWithLocalResource(dirPath) {
35
+ const resourcesPath = _path.default.join(__dirname, '../resources');
36
+ return _path.default.join(resourcesPath, dirPath);
37
+ }
38
+
39
+ /**
40
+ * Electron资源目录地址转换
41
+ * @param {*} dirPath
42
+ * @returns
43
+ */
44
+ function getPathWithElectornResource(dirPath) {
45
+ console.log('getPathWithElectornResource resourcesPath => ', _process.default.type || 'node', _process.default.resourcesPath);
46
+ return _path.default.join(_process.default.resourcesPath || '', dirPath);
47
+ }
48
+
49
+ /**
50
+ * 当前工作目录地址转换
51
+ * @param {*} dirPath
52
+ * @returns
53
+ */
25
54
  function getPathWithCWD(dirPath) {
26
55
  const cwd = _process.default.cwd();
27
56
  return _path.default.join(cwd, dirPath);
28
57
  }
58
+
59
+ /**
60
+ * 获取当前nodePath环境变量
61
+ * @returns
62
+ */
29
63
  function getCurrentNodePath() {
30
64
  return _process.default.env.NODE_PATH || '';
31
65
  }
@@ -8,12 +8,12 @@ exports.initWorkerNodePath = initWorkerNodePath;
8
8
  const path = require('path');
9
9
  const _module = require('module');
10
10
  const {
11
- getPathWithCWD,
11
+ getPathWithElectornResource,
12
12
  getCurrentNodePath
13
13
  } = require("./utils.path");
14
14
  function getAsarNodePath() {
15
- const asarRoot = getPathWithCWD('app.asar');
16
- const unpackedRoot = asarRoot.replace('app.asar', 'app.asar.unpacked');
15
+ const asarRoot = getPathWithElectornResource('app.asar');
16
+ const unpackedRoot = getPathWithElectornResource('app.asar.unpacked');
17
17
  const nodeModulesPaths = [path.join(asarRoot, 'node_modules'), path.join(unpackedRoot, 'node_modules')];
18
18
  return nodeModulesPaths.join(path.delimiter);
19
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hunter-open-sdk",
3
- "version": "2.0.0-beta.20",
3
+ "version": "2.0.0-beta.22",
4
4
  "description": "采货侠SaaS版本桌面端sdk",
5
5
  "scripts": {
6
6
  "start": "zz dev",
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _utils = require("../../utils/utils.env");
8
- var _command = require("./command");
9
- var _winDriver = require("./winDriver");
10
- const path = require('path');
11
- class Service {
12
- // constructor () {}
13
- setup(mainWindow) {
14
- console.log('Service setup');
15
- if ((0, _utils.isMac)()) {
16
- if ((0, _utils.isDev)()) {
17
- (0, _command.command)(path.join(process.cwd(), './extraResources/ightools'));
18
- }
19
- if ((0, _utils.isProd)()) {
20
- (0, _command.command)('nohup ' + path.join(process.resourcesPath, './extraResources/ightools') + ' > /dev/null 2>&1 & > ' + path.join(process.resourcesPath, './log/ightools.log'));
21
- }
22
- }
23
- if ((0, _utils.isWin)()) {
24
- (0, _winDriver.checkHasDriver)().then(res => {
25
- console.log('------------checkHasDriver', res);
26
- if (res) {
27
- mainWindow.webContents.send('checkDriver', true);
28
- } else {
29
- mainWindow.webContents.send('checkDriver', false);
30
- (0, _winDriver.downloadDriver)(mainWindow);
31
- }
32
- });
33
- }
34
- }
35
- }
36
- var _default = exports.default = Service;