hunter-open-sdk 0.0.3 → 0.0.5

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/README.md CHANGED
@@ -1,4 +1,2 @@
1
- # hunter-coruscant@0.0.1
2
-
3
1
  采货侠SaaS版本桌面端sdk
4
2
 
@@ -22,7 +22,7 @@ var options = {
22
22
  name: 'Electron'
23
23
  };
24
24
  var msiStr = 'AppleMobileDeviceService';
25
- var reddirPath = 'C:/Program Files (x86)/Common Files/Apple/Apple Application Support';
25
+ // const reddirPath = 'C:/Program Files (x86)/Common Files/Apple/Apple Application Support'
26
26
  var cmdStr = process.platform === 'win32' ? 'tasklist' : 'ps aux';
27
27
  var CACHE_PATH = (0, _utils.isDev)() ? path.join(process.cwd(), './cache') : path.join(process.resourcesPath, './cache');
28
28
  var filePath = path.join(CACHE_PATH, './iTunesOL_Lite_64_12.10.0.7.zip');
@@ -31,7 +31,7 @@ var checkProcess = function checkProcess() {
31
31
  return new Promise(function (resolve, reject) {
32
32
  exec(cmdStr, function (err, stdout, stderr) {
33
33
  // console.log('stdout>>>', stdout)
34
- // console.log('stderr>>>', stderr)
34
+ console.log('stderr>>>', stderr);
35
35
  if (err) {
36
36
  return reject(err);
37
37
  }
@@ -50,13 +50,14 @@ var checkProcess = function checkProcess() {
50
50
  });
51
51
  });
52
52
  };
53
- var checkFs = function checkFs(paths) {
54
- return new Promise(function (resolve) {
55
- fs.readdir(paths, function (err) {
56
- resolve(err ? false : true);
57
- });
58
- });
59
- };
53
+ // const checkFs = (paths) => {
54
+ // return new Promise((resolve) => {
55
+ // fs.readdir(paths, function(err) {
56
+ // resolve(err ? false : true)
57
+ // })
58
+ // })
59
+ // }
60
+
60
61
  var checkCache = function checkCache() {
61
62
  return new Promise(function (resolve) {
62
63
  fs.readFile(filePath, function (err) {
@@ -114,7 +115,7 @@ var installDriver = function installDriver() {
114
115
  // 解压文件
115
116
  var uncopressingFile = function uncopressingFile(filePath) {
116
117
  return new Promise(function (resolve) {
117
- compressing.zip.uncompress(filePath, CACHE_PATH).then(function (res) {
118
+ compressing.zip.uncompress(filePath, CACHE_PATH).then(function () {
118
119
  resolve(true);
119
120
  }).catch(function (err) {
120
121
  resolve(false);
@@ -142,28 +143,23 @@ function downloadDriver(mainWindow) {
142
143
  }
143
144
  });
144
145
  // 下载完成
145
- item.on('done', /*#__PURE__*/function () {
146
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(e, start) {
147
- var uncopressing;
148
- return _regenerator.default.wrap(function _callee2$(_context2) {
149
- while (1) switch (_context2.prev = _context2.next) {
150
- case 0:
151
- _context2.next = 2;
152
- return uncopressingFile(filePath);
153
- case 2:
154
- uncopressing = _context2.sent;
155
- if (uncopressing) installDriver();
156
- mainWindow.webContents.send('downloadDriverDone');
157
- case 5:
158
- case "end":
159
- return _context2.stop();
160
- }
161
- }, _callee2);
162
- }));
163
- return function (_x, _x2) {
164
- return _ref2.apply(this, arguments);
165
- };
166
- }());
146
+ item.on('done', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
147
+ var uncopressing;
148
+ return _regenerator.default.wrap(function _callee2$(_context2) {
149
+ while (1) switch (_context2.prev = _context2.next) {
150
+ case 0:
151
+ _context2.next = 2;
152
+ return uncopressingFile(filePath);
153
+ case 2:
154
+ uncopressing = _context2.sent;
155
+ if (uncopressing) installDriver();
156
+ mainWindow.webContents.send('downloadDriverDone');
157
+ case 5:
158
+ case "end":
159
+ return _context2.stop();
160
+ }
161
+ }, _callee2);
162
+ })));
167
163
  item.on('error', function () {
168
164
  console.log('驱动下载失败');
169
165
  });
@@ -10,7 +10,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
10
10
  var _usb = require("usb");
11
11
  var GetAndroidSn = function GetAndroidSn(params, callBack) {
12
12
  _usb.usb.on('attach', /*#__PURE__*/function () {
13
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(device, res) {
13
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(device) {
14
14
  var attachDeviceId, customWebUSB, deviceList, currentDevice;
15
15
  return _regenerator.default.wrap(function _callee$(_context) {
16
16
  while (1) switch (_context.prev = _context.next) {
@@ -52,7 +52,7 @@ var GetAndroidSn = function GetAndroidSn(params, callBack) {
52
52
  }
53
53
  }, _callee);
54
54
  }));
55
- return function (_x, _x2) {
55
+ return function (_x) {
56
56
  return _ref.apply(this, arguments);
57
57
  };
58
58
  }());
@@ -82,18 +82,42 @@ var DevicePair = /*#__PURE__*/function () {
82
82
  return _ref.apply(this, arguments);
83
83
  };
84
84
  }();
85
- var updateDll = function updateDll(packageUrl) {
85
+
86
+ // 写入dll文件version
87
+ var writeDllVersion = function writeDllVersion(version) {
88
+ var versionPath = path.resolve(__dirname, '../resources/version.online');
89
+ fs.writeFile(versionPath, version, function (err) {
90
+ if (err) {
91
+ saasCallBack({
92
+ data: {
93
+ eventName: 'type_update_result',
94
+ eventCode: -1 // eventCode 0 更新成功 -1 更新失败
95
+ }
96
+ });
97
+ return;
98
+ }
99
+ console.log('========写入version成功');
100
+ // 写入成功后 重新初始化dll
101
+ (0, _utils2.HunterInspectionKit)();
102
+ saasCallBack({
103
+ data: {
104
+ eventName: 'type_update_result',
105
+ eventCode: 0 // eventCode 0 更新成功 -1 更新失败
106
+ }
107
+ });
108
+ });
109
+ };
110
+
111
+ // 下载更新dll
112
+ var updateDll = function updateDll(packageUrl, targetVersion) {
86
113
  // 若需要更新 则下载完成后 覆盖本地dll文件
87
114
  var dllOutPath;
88
115
  if ((0, _utils.isMac)()) {
89
116
  if ((0, _utils.isArm64)()) {
90
- dllOutPath = path.resolve(__dirname, '../resources/mac/arm64.dylib');
91
- }
92
- if ((0, _utils.isAmd64)()) {
93
- dllOutPath = path.resolve(__dirname, '../resources/mac/amd64.dylib');
117
+ dllOutPath = path.resolve(__dirname, "../resources/mac/libinspectionkit_arm64_".concat(targetVersion, ".dylib"));
94
118
  }
95
119
  } else {
96
- dllOutPath = path.resolve(__dirname, "../resources/dll/x64.dll");
120
+ dllOutPath = path.resolve(__dirname, "../resources/dll/libinspectionkit_x64_".concat(targetVersion, ".dll"));
97
121
  }
98
122
  var dllStream = fs.createWriteStream(dllOutPath);
99
123
  request(packageUrl).pipe(dllStream).on("close", function (err) {
@@ -105,14 +129,8 @@ var updateDll = function updateDll(packageUrl) {
105
129
  }
106
130
  });
107
131
  } else {
108
- // 下载完成后 重新初始化dll
109
- (0, _utils2.HunterInspectionKit)();
110
- saasCallBack({
111
- data: {
112
- eventName: 'type_update_result',
113
- eventCode: 0 // eventCode 0 更新成功 -1 更新失败
114
- }
115
- });
132
+ // 写version文件内容
133
+ writeDllVersion(targetVersion);
116
134
  }
117
135
  });
118
136
  };
@@ -123,6 +141,8 @@ var updateDll = function updateDll(packageUrl) {
123
141
  * @returns
124
142
  */
125
143
  var updateDllFileCheck = function updateDllFileCheck() {
144
+ // mac的amd不支持更新
145
+ if ((0, _utils.isMac)() && (0, _utils.isAmd64)()) return;
126
146
  var updateParams = {
127
147
  cmd: 'hot_update',
128
148
  label: (0, _utils.isWin)() ? 'Windows' : 'Mac',
@@ -135,10 +155,11 @@ var updateDllFileCheck = function updateDllFileCheck() {
135
155
  Data = updateResObj.Data;
136
156
  if (Code == 0) {
137
157
  var isHot = Data.isHot,
138
- url = Data.url;
158
+ url = Data.url,
159
+ targetVersion = Data.targetVersion;
139
160
 
140
161
  // 需要更新 则直接下载
141
- isHot == 1 && updateDll(url);
162
+ isHot == 1 && updateDll(url, targetVersion);
142
163
  saasCallBack({
143
164
  data: {
144
165
  eventName: 'type_need_update',
@@ -0,0 +1 @@
1
+ 0.0.4
@@ -7,6 +7,7 @@ exports.HunterInspectionKit = void 0;
7
7
  var _utils = require("./utils");
8
8
  var ffi = require('ffi-napi');
9
9
  var path = require('path');
10
+ var fs = require('fs');
10
11
 
11
12
  /**
12
13
  * 声明dll函数
@@ -16,15 +17,19 @@ var path = require('path');
16
17
 
17
18
  var HunterInspectionKit = exports.HunterInspectionKit = function HunterInspectionKit() {
18
19
  var dllPath;
20
+
21
+ // 读取本地sdk的version
22
+ var versionPath = path.resolve(__dirname, '../resources/version.online');
23
+ var version = fs.readFileSync(versionPath, 'utf-8');
19
24
  if ((0, _utils.isMac)()) {
20
25
  if ((0, _utils.isArm64)()) {
21
- dllPath = path.resolve(__dirname, '../resources/mac/arm64.dylib');
26
+ dllPath = path.resolve(__dirname, "../resources/mac/libinspectionkit_arm64_".concat(version, ".dylib"));
22
27
  }
23
28
  if ((0, _utils.isAmd64)()) {
24
- dllPath = path.resolve(__dirname, '../resources/mac/amd64.dylib');
29
+ dllPath = path.resolve(__dirname, "../resources/mac/libinspectionkit_amd64_".concat(version, ".dylib"));
25
30
  }
26
31
  } else {
27
- dllPath = path.resolve(__dirname, '../resources/dll/x64.dll');
32
+ dllPath = path.resolve(__dirname, "../resources/dll/libinspectionkit_x64_".concat(version, ".dll"));
28
33
  }
29
34
  if (!(0, _utils.isDev)()) {
30
35
  // 如果是生产模式 则替换app.asar 路径 为了在生产调用dll
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hunter-open-sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "采货侠SaaS版本桌面端sdk",
5
5
  "scripts": {
6
6
  "start": "zz dev",