hunter-open-sdk 2.0.0-beta.2 → 2.0.0-beta.20
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/index.js +48 -0
- package/lib/abilities/activate/worker.js +19 -0
- package/lib/abilities/erase/index.js +48 -0
- package/lib/abilities/erase/worker.js +19 -0
- package/lib/abilities/eventManager/index.js +338 -0
- package/lib/abilities/getAndroidSn/index.js +165 -0
- package/lib/abilities/getGeneralReport/index.js +64 -0
- package/lib/abilities/getGeneralReport/worker.js +38 -0
- package/lib/abilities/getSaaSReport/index.js +48 -0
- package/lib/abilities/getSaaSReport/worker.js +21 -0
- package/lib/abilities/installApp/index.js +48 -0
- package/lib/abilities/installApp/worker.js +19 -0
- package/lib/abilities/reboot/index.js +48 -0
- package/lib/abilities/reboot/worker.js +19 -0
- package/lib/abilities/shutdown/index.js +48 -0
- package/lib/abilities/shutdown/worker.js +19 -0
- package/lib/abilities/skip/index.js +48 -0
- package/lib/abilities/skip/worker.js +19 -0
- package/lib/events/driver/command.js +8 -9
- package/lib/events/driver/service.js +24 -35
- package/lib/events/driver/winDriver.js +121 -188
- package/lib/helper/deviceHelper.js +19 -37
- package/lib/index.js +24 -12
- package/lib/resources/dll/{libinspectionkit_x64_0.1.0.dll → libinspectionkit_x64_0.4.1.dll} +0 -0
- package/lib/resources/mac/{libinspectionkit_arm64_0.1.0.dylib → libinspectionkit_amd64_0.4.1.dylib} +0 -0
- package/lib/resources/mac/libinspectionkit_arm64_0.4.1.dylib +0 -0
- package/lib/resources/version.online +1 -1
- package/lib/utils/utils.ability.js +9 -0
- package/lib/utils/utils.command.js +8 -9
- package/lib/utils/utils.common.js +26 -0
- package/lib/utils/{utils.js → utils.env.js} +19 -18
- package/lib/utils/utils.global.js +70 -89
- package/lib/utils/utils.initDll.js +16 -14
- package/lib/utils/utils.path.js +21 -6
- package/lib/utils/utils.process.js +35 -0
- package/lib/utils/utils.sn.js +31 -47
- package/lib/utils/utils.worker.js +32 -0
- package/package.json +7 -8
- package/lib/getAndroidSn/index.js +0 -228
- package/lib/getGeneralReport/index.js +0 -76
- package/lib/getGeneralReport/worker.js +0 -20
- package/lib/getSaaSReport/index.js +0 -76
- package/lib/getSaaSReport/worker.js +0 -20
- package/lib/registerEvent/index.js +0 -427
- package/lib/resources/mac/libinspectionkit_amd64_0.1.0.dylib +0 -0
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.isWin = exports.isProd = exports.isMac = exports.isLinux = exports.isDev = exports.isArm64 = exports.isAmd64 = void 0;
|
|
7
|
+
const isMac = () => {
|
|
8
8
|
return process.platform === 'darwin';
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
exports.isMac = isMac;
|
|
11
|
+
const isWin = () => {
|
|
11
12
|
return process.platform === 'win32';
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
+
exports.isWin = isWin;
|
|
15
|
+
const isLinux = () => {
|
|
14
16
|
return process.platform === 'linux';
|
|
15
17
|
};
|
|
16
|
-
|
|
18
|
+
exports.isLinux = isLinux;
|
|
19
|
+
const isDev = () => {
|
|
17
20
|
// 检查 NODE_ENV 是否为 development
|
|
18
21
|
if (process.env.NODE_ENV === 'development') {
|
|
19
22
|
return true;
|
|
@@ -30,24 +33,22 @@ var isDev = exports.isDev = function isDev() {
|
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
// 检查是否在 Electron 主进程中,且没有打包
|
|
33
|
-
if (process.type === 'browser' && !process.resourcesPath.includes('app.asar')) {
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
+
// if (process.type === 'browser' && !process.resourcesPath.includes('app.asar')) {
|
|
37
|
+
// return true
|
|
38
|
+
// }
|
|
39
|
+
|
|
36
40
|
return false;
|
|
37
41
|
};
|
|
38
|
-
|
|
42
|
+
exports.isDev = isDev;
|
|
43
|
+
const isProd = () => {
|
|
39
44
|
return process.env.NODE_ENV === 'production';
|
|
40
45
|
};
|
|
41
|
-
|
|
46
|
+
exports.isProd = isProd;
|
|
47
|
+
const isArm64 = () => {
|
|
42
48
|
return process.arch === 'arm64';
|
|
43
49
|
};
|
|
44
|
-
|
|
50
|
+
exports.isArm64 = isArm64;
|
|
51
|
+
const isAmd64 = () => {
|
|
45
52
|
return process.arch === 'x64';
|
|
46
53
|
};
|
|
47
|
-
|
|
48
|
-
return new Promise(function (resolve) {
|
|
49
|
-
setTimeout(function () {
|
|
50
|
-
resolve();
|
|
51
|
-
}, 2000);
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
+
exports.isAmd64 = isAmd64;
|
|
@@ -3,18 +3,22 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.abilityCallKit = abilityCallKit;
|
|
7
|
+
exports.setGlobalProperty = exports.hasGlobalProperty = exports.getHunterInspectionKit = exports.getGlobalProperty = exports.getGlobalObject = exports.deleteGlobalProperty = exports.callHunterInspectionKit = void 0;
|
|
7
8
|
var _utils = require("../utils/utils.initDll");
|
|
9
|
+
var Sentry = _interopRequireWildcard(require("@sentry/browser"));
|
|
10
|
+
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); }
|
|
11
|
+
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
12
|
/**
|
|
9
13
|
* 全局对象兼容性处理工具
|
|
10
14
|
* 兼容Electron主进程(global)和渲染进程(window)环境
|
|
11
15
|
*/
|
|
12
|
-
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
18
|
* 获取全局对象
|
|
15
19
|
* @returns {Object} 全局对象
|
|
16
20
|
*/
|
|
17
|
-
|
|
21
|
+
const getGlobalObject = () => {
|
|
18
22
|
if (typeof global !== 'undefined') {
|
|
19
23
|
return global;
|
|
20
24
|
}
|
|
@@ -30,8 +34,9 @@ var getGlobalObject = exports.getGlobalObject = function getGlobalObject() {
|
|
|
30
34
|
* @param {string} key 属性名
|
|
31
35
|
* @param {any} value 属性值
|
|
32
36
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
exports.getGlobalObject = getGlobalObject;
|
|
38
|
+
const setGlobalProperty = (key, value) => {
|
|
39
|
+
const globalObj = getGlobalObject();
|
|
35
40
|
globalObj[key] = value;
|
|
36
41
|
};
|
|
37
42
|
|
|
@@ -41,9 +46,9 @@ var setGlobalProperty = exports.setGlobalProperty = function setGlobalProperty(k
|
|
|
41
46
|
* @param {any} defaultValue 默认值
|
|
42
47
|
* @returns {any} 属性值
|
|
43
48
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
exports.setGlobalProperty = setGlobalProperty;
|
|
50
|
+
const getGlobalProperty = (key, defaultValue = undefined) => {
|
|
51
|
+
const globalObj = getGlobalObject();
|
|
47
52
|
return globalObj[key] !== undefined ? globalObj[key] : defaultValue;
|
|
48
53
|
};
|
|
49
54
|
|
|
@@ -52,8 +57,9 @@ var getGlobalProperty = exports.getGlobalProperty = function getGlobalProperty(k
|
|
|
52
57
|
* @param {string} key 属性名
|
|
53
58
|
* @returns {boolean} 是否存在
|
|
54
59
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
exports.getGlobalProperty = getGlobalProperty;
|
|
61
|
+
const hasGlobalProperty = key => {
|
|
62
|
+
const globalObj = getGlobalObject();
|
|
57
63
|
return key in globalObj;
|
|
58
64
|
};
|
|
59
65
|
|
|
@@ -61,8 +67,9 @@ var hasGlobalProperty = exports.hasGlobalProperty = function hasGlobalProperty(k
|
|
|
61
67
|
* 删除全局属性
|
|
62
68
|
* @param {string} key 属性名
|
|
63
69
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
exports.hasGlobalProperty = hasGlobalProperty;
|
|
71
|
+
const deleteGlobalProperty = key => {
|
|
72
|
+
const globalObj = getGlobalObject();
|
|
66
73
|
delete globalObj[key];
|
|
67
74
|
};
|
|
68
75
|
|
|
@@ -70,8 +77,9 @@ var deleteGlobalProperty = exports.deleteGlobalProperty = function deleteGlobalP
|
|
|
70
77
|
* 安全地获取HunterInspectionKit对象
|
|
71
78
|
* @returns {Object|null} HunterInspectionKit对象,如果不存在则返回null
|
|
72
79
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
exports.deleteGlobalProperty = deleteGlobalProperty;
|
|
81
|
+
const getHunterInspectionKit = willInit => {
|
|
82
|
+
const kit = getGlobalProperty('HunterInspectionKit');
|
|
75
83
|
if (!kit) {
|
|
76
84
|
!willInit && console.warn('HunterInspectionKit未初始化,请先调用 initHunterInspectionKit() 函数');
|
|
77
85
|
return null;
|
|
@@ -85,110 +93,83 @@ var getHunterInspectionKit = exports.getHunterInspectionKit = function getHunter
|
|
|
85
93
|
* @param {...any} args 参数
|
|
86
94
|
* @returns {any|null} 方法返回值,如果调用失败则返回null
|
|
87
95
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
exports.getHunterInspectionKit = getHunterInspectionKit;
|
|
97
|
+
const callHunterInspectionKit = (methodName, ...args) => {
|
|
98
|
+
let kit = getHunterInspectionKit(true);
|
|
90
99
|
if (!kit) {
|
|
91
100
|
(0, _utils.initHunterInspectionKit)();
|
|
92
101
|
kit = getHunterInspectionKit(false);
|
|
93
102
|
}
|
|
94
103
|
if (!kit || typeof kit[methodName] !== 'function') {
|
|
95
|
-
console.error(
|
|
96
|
-
Sentry.captureException(
|
|
104
|
+
console.error(`HunterInspectionKit.${methodName}方法不存在或未初始化`);
|
|
105
|
+
Sentry.captureException(`HunterInspectionKit.${methodName}方法不存在或未初始化`);
|
|
97
106
|
return null;
|
|
98
107
|
}
|
|
99
108
|
try {
|
|
100
|
-
|
|
101
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
102
|
-
args[_key - 1] = arguments[_key];
|
|
103
|
-
}
|
|
104
|
-
return (_kit = kit)[methodName].apply(_kit, args);
|
|
109
|
+
return kit[methodName](...args);
|
|
105
110
|
} catch (error) {
|
|
106
|
-
console.error(
|
|
107
|
-
Sentry.captureException(
|
|
111
|
+
console.error(`调用HunterInspectionKit.${methodName}失败:`, error);
|
|
112
|
+
Sentry.captureException(`调用HunterInspectionKit.${methodName}失败:`, error);
|
|
108
113
|
return null;
|
|
109
114
|
}
|
|
110
115
|
};
|
|
111
116
|
|
|
112
117
|
/**
|
|
113
|
-
*
|
|
114
|
-
* @param {
|
|
115
|
-
* @
|
|
118
|
+
* 调用HunterInspectionKit的方法
|
|
119
|
+
* @param {string} cmd 方法名
|
|
120
|
+
* @param {Object} payload 参数对象
|
|
121
|
+
* @returns {Object} 执行结果对象
|
|
116
122
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
Message = reportResObj.Message;
|
|
126
|
-
if (Code == 0 && Data) {
|
|
127
|
-
return {
|
|
128
|
-
type: 'getGeneralReportSuccess',
|
|
129
|
-
data: {
|
|
130
|
-
code: 0,
|
|
131
|
-
data: Data,
|
|
132
|
-
message: '获取报告成功'
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
123
|
+
exports.callHunterInspectionKit = callHunterInspectionKit;
|
|
124
|
+
function abilityCallKit(cmd, payload) {
|
|
125
|
+
console.log(`调用【${cmd}】方法,参数:`, payload);
|
|
126
|
+
const {
|
|
127
|
+
biz = "",
|
|
128
|
+
params
|
|
129
|
+
} = payload;
|
|
130
|
+
if (!params) {
|
|
136
131
|
return {
|
|
137
|
-
type: '
|
|
138
|
-
|
|
132
|
+
type: 'fail',
|
|
133
|
+
payload: {
|
|
139
134
|
code: -1,
|
|
140
135
|
data: {},
|
|
141
|
-
message:
|
|
136
|
+
message: `调用【${cmd}】方法缺少必要参数`
|
|
142
137
|
}
|
|
143
138
|
};
|
|
144
139
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
data: {
|
|
148
|
-
code: -1,
|
|
149
|
-
data: {},
|
|
150
|
-
message: '获取报告失败'
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 获取general报告
|
|
157
|
-
* @param {Object} params 参数
|
|
158
|
-
* @returns {Object} 报告结果
|
|
159
|
-
*/
|
|
160
|
-
var getSaaSReportCallKit = exports.getSaaSReportCallKit = function getSaaSReportCallKit(params) {
|
|
161
|
-
var reportRes = callHunterInspectionKit('InspectionKit', params, 'saas_report', params);
|
|
162
|
-
if (reportRes) {
|
|
163
|
-
var reportResObj = JSON.parse(reportRes);
|
|
164
|
-
var Code = reportResObj.Code,
|
|
165
|
-
Data = reportResObj.Data,
|
|
166
|
-
Message = reportResObj.Message;
|
|
167
|
-
if (Code == 0 && Data) {
|
|
168
|
-
return {
|
|
169
|
-
type: 'getSaaSReportSuccess',
|
|
170
|
-
data: {
|
|
171
|
-
code: 0,
|
|
172
|
-
data: Data,
|
|
173
|
-
message: '获取SaaS报告成功'
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
140
|
+
const res = callHunterInspectionKit('InspectionKit', biz, cmd, params);
|
|
141
|
+
if (!res) {
|
|
177
142
|
return {
|
|
178
|
-
type: '
|
|
179
|
-
|
|
143
|
+
type: 'fail',
|
|
144
|
+
payload: {
|
|
180
145
|
code: -1,
|
|
181
146
|
data: {},
|
|
182
|
-
message:
|
|
147
|
+
message: `【${cmd}】方法执行失败`
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const resObj = JSON.parse(res);
|
|
152
|
+
const {
|
|
153
|
+
Code,
|
|
154
|
+
Data,
|
|
155
|
+
Message
|
|
156
|
+
} = resObj;
|
|
157
|
+
if (Code == 0) {
|
|
158
|
+
return {
|
|
159
|
+
type: 'success',
|
|
160
|
+
payload: {
|
|
161
|
+
code: 0,
|
|
162
|
+
data: Data,
|
|
163
|
+
message: `【${cmd}】方法执行成功`
|
|
183
164
|
}
|
|
184
165
|
};
|
|
185
166
|
}
|
|
186
167
|
return {
|
|
187
|
-
type: '
|
|
188
|
-
|
|
168
|
+
type: 'fail',
|
|
169
|
+
payload: {
|
|
189
170
|
code: -1,
|
|
190
171
|
data: {},
|
|
191
|
-
message:
|
|
172
|
+
message: Message || `【${cmd}】方法执行失败`
|
|
192
173
|
}
|
|
193
174
|
};
|
|
194
|
-
}
|
|
175
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,40 +7,43 @@ exports.initHunterInspectionKit = void 0;
|
|
|
8
7
|
var _koffi = _interopRequireDefault(require("koffi"));
|
|
9
8
|
var _path = _interopRequireDefault(require("path"));
|
|
10
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
var _utils = require("./utils");
|
|
10
|
+
var _utils = require("./utils.env");
|
|
12
11
|
var _utils2 = require("./utils.global");
|
|
12
|
+
var _utils3 = require("./utils.path");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
14
|
/**
|
|
14
15
|
* 声明dll函数
|
|
15
16
|
* @param {String} udid 设备id
|
|
16
|
-
* @returns
|
|
17
|
+
* @returns
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const initHunterInspectionKit = () => {
|
|
21
|
+
let dllPath;
|
|
21
22
|
|
|
22
23
|
// 读取本地sdk的version
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const versionPath = _path.default.resolve(__dirname, '../resources/version.online');
|
|
25
|
+
const version = _fs.default.readFileSync(versionPath, 'utf-8').trim();
|
|
25
26
|
if ((0, _utils.isMac)()) {
|
|
26
27
|
if ((0, _utils.isArm64)()) {
|
|
27
|
-
dllPath = _path.default.resolve(__dirname,
|
|
28
|
+
dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_arm64_${version}.dylib`);
|
|
28
29
|
}
|
|
29
30
|
if ((0, _utils.isAmd64)()) {
|
|
30
|
-
dllPath = _path.default.resolve(__dirname,
|
|
31
|
+
dllPath = _path.default.resolve(__dirname, `../resources/mac/libinspectionkit_amd64_${version}.dylib`);
|
|
31
32
|
}
|
|
32
33
|
} else {
|
|
33
|
-
dllPath = _path.default.resolve(__dirname,
|
|
34
|
+
dllPath = _path.default.resolve(__dirname, `../resources/dll/libinspectionkit_x64_${version}.dll`);
|
|
34
35
|
}
|
|
35
36
|
if (!(0, _utils.isDev)()) {
|
|
36
37
|
// 如果是生产模式 则替换app.asar 路径 为了在生产调用dll
|
|
37
|
-
dllPath =
|
|
38
|
+
dllPath = (0, _utils3.getCurrentEnvPath)(dllPath);
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
const dllLib = _koffi.default.load(dllPath);
|
|
41
|
+
const dllKit = {
|
|
41
42
|
InspectionKit: dllLib.func('InspectionKit', 'str', ['str', 'str', 'str']),
|
|
42
43
|
TheForceKit: dllLib.func('TheForceKit', 'str', ['str'])
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
// 挂载到全局对象,兼容主进程和渲染进程
|
|
46
47
|
(0, _utils2.setGlobalProperty)('HunterInspectionKit', dllKit);
|
|
47
|
-
};
|
|
48
|
+
};
|
|
49
|
+
exports.initHunterInspectionKit = initHunterInspectionKit;
|
package/lib/utils/utils.path.js
CHANGED
|
@@ -3,14 +3,29 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
exports.getCurrentEnvPath = getCurrentEnvPath;
|
|
7
|
+
exports.getCurrentNodePath = getCurrentNodePath;
|
|
8
|
+
exports.getPathWithCWD = getPathWithCWD;
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _process = _interopRequireDefault(require("process"));
|
|
11
|
+
var _utils = require("./utils.env");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
13
|
/**
|
|
10
14
|
* 当前环境地址转换
|
|
11
15
|
* @param {*} path
|
|
12
16
|
* @returns
|
|
13
17
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
function getCurrentEnvPath(dirPath, filePath = '') {
|
|
19
|
+
let fixPath = dirPath;
|
|
20
|
+
if (!(0, _utils.isDev)()) {
|
|
21
|
+
fixPath = fixPath.replace('/app.asar/', '/app.asar.unpacked/').replace(/\\app.asar\\/, /\\app.asar.unpacked\\/);
|
|
22
|
+
}
|
|
23
|
+
return _path.default.resolve(fixPath, filePath);
|
|
24
|
+
}
|
|
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 || '';
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getCurrentProcess = getCurrentProcess;
|
|
7
|
+
exports.getProccessType = getProccessType;
|
|
8
|
+
exports.isInMainProcess = isInMainProcess;
|
|
9
|
+
exports.isInRenderProcess = isInRenderProcess;
|
|
10
|
+
// 获取进程类型
|
|
11
|
+
function getProccessType() {
|
|
12
|
+
return process.type;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 是否在主进程
|
|
16
|
+
function isInMainProcess() {
|
|
17
|
+
return getProccessType() === 'browser';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 是否在渲染进程
|
|
21
|
+
// eslint-disable-next-line no-unused-vars
|
|
22
|
+
function isInRenderProcess() {
|
|
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
|
+
}
|
|
35
|
+
}
|
package/lib/utils/utils.sn.js
CHANGED
|
@@ -4,23 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.parseWmicOutput = parseWmicOutput;
|
|
7
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
8
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
7
|
/**
|
|
11
8
|
* 判断设备是否为手机设备
|
|
12
9
|
* @param {Object} device - 设备信息
|
|
13
10
|
* @returns {boolean} 是否为手机设备
|
|
14
11
|
*/
|
|
15
12
|
function isPhoneDevice(device) {
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const name = device.name.toLowerCase();
|
|
14
|
+
const pnpId = device.pnpDeviceId.toLowerCase();
|
|
18
15
|
|
|
19
16
|
// 只支持三星、荣耀、华为的手机设备关键词
|
|
20
|
-
|
|
17
|
+
const phoneKeywords = ['samsung', 'galaxy', 'huawei', 'honor', 'honor magic'];
|
|
21
18
|
|
|
22
19
|
// 只支持三星、荣耀、华为的手机厂商VID
|
|
23
|
-
|
|
20
|
+
const phoneVendors = ['VID_04E8',
|
|
24
21
|
// Samsung
|
|
25
22
|
'VID_12D1',
|
|
26
23
|
// Huawei
|
|
@@ -28,14 +25,10 @@ function isPhoneDevice(device) {
|
|
|
28
25
|
];
|
|
29
26
|
|
|
30
27
|
// 检查名称中是否包含手机关键词
|
|
31
|
-
|
|
32
|
-
return name.includes(keyword);
|
|
33
|
-
});
|
|
28
|
+
const isPhoneByName = phoneKeywords.some(keyword => name.includes(keyword));
|
|
34
29
|
|
|
35
30
|
// 检查PNPDeviceID中是否包含手机厂商VID
|
|
36
|
-
|
|
37
|
-
return pnpId.includes(vendor.toLowerCase());
|
|
38
|
-
});
|
|
31
|
+
const isPhoneByVendor = phoneVendors.some(vendor => pnpId.includes(vendor.toLowerCase()));
|
|
39
32
|
return isPhoneByName || isPhoneByVendor;
|
|
40
33
|
}
|
|
41
34
|
|
|
@@ -46,9 +39,9 @@ function isPhoneDevice(device) {
|
|
|
46
39
|
*/
|
|
47
40
|
function extractSerialNumber(pnpDeviceId) {
|
|
48
41
|
// USB设备ID格式通常为: USB\VID_v(4)&PID_d(4)\序列号
|
|
49
|
-
|
|
42
|
+
const parts = pnpDeviceId.split('\\');
|
|
50
43
|
if (parts.length >= 3) {
|
|
51
|
-
|
|
44
|
+
const serialPart = parts[parts.length - 1];
|
|
52
45
|
|
|
53
46
|
// 验证序列号格式(通常不包含&和#等特殊字符)
|
|
54
47
|
if (serialPart && !serialPart.includes('&') && !serialPart.includes('#')) {
|
|
@@ -65,43 +58,34 @@ function extractSerialNumber(pnpDeviceId) {
|
|
|
65
58
|
* @returns {Array} 手机设备信息数组
|
|
66
59
|
*/
|
|
67
60
|
function parseWmicOutput(output) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (isPhoneDevice(currentDevice)) {
|
|
82
|
-
// 提取序列号
|
|
83
|
-
currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
|
|
84
|
-
devices.push(currentDevice);
|
|
85
|
-
}
|
|
61
|
+
const devices = [];
|
|
62
|
+
const lines = output.split('\r\n');
|
|
63
|
+
let currentDevice = {};
|
|
64
|
+
for (const line of lines) {
|
|
65
|
+
// 跳过空行
|
|
66
|
+
if (!line.trim()) {
|
|
67
|
+
// 如果当前设备有数据,则保存
|
|
68
|
+
if (currentDevice.name && currentDevice.pnpDeviceId) {
|
|
69
|
+
// 检查是否为手机设备
|
|
70
|
+
if (isPhoneDevice(currentDevice)) {
|
|
71
|
+
// 提取序列号
|
|
72
|
+
currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
|
|
73
|
+
devices.push(currentDevice);
|
|
86
74
|
}
|
|
87
|
-
currentDevice = {};
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// 解析Name和PNPDeviceID
|
|
92
|
-
if (line.startsWith('Name=')) {
|
|
93
|
-
currentDevice.name = line.substring(5).trim();
|
|
94
|
-
} else if (line.startsWith('PNPDeviceID=')) {
|
|
95
|
-
currentDevice.pnpDeviceId = line.substring(12).trim();
|
|
96
75
|
}
|
|
76
|
+
currentDevice = {};
|
|
77
|
+
continue;
|
|
97
78
|
}
|
|
98
79
|
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
80
|
+
// 解析Name和PNPDeviceID
|
|
81
|
+
if (line.startsWith('Name=')) {
|
|
82
|
+
currentDevice.name = line.substring(5).trim();
|
|
83
|
+
} else if (line.startsWith('PNPDeviceID=')) {
|
|
84
|
+
currentDevice.pnpDeviceId = line.substring(12).trim();
|
|
85
|
+
}
|
|
104
86
|
}
|
|
87
|
+
|
|
88
|
+
// 处理最后一个设备
|
|
105
89
|
if (currentDevice.name && currentDevice.pnpDeviceId && isPhoneDevice(currentDevice)) {
|
|
106
90
|
currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
|
|
107
91
|
devices.push(currentDevice);
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hunter-open-sdk",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.20",
|
|
4
4
|
"description": "采货侠SaaS版本桌面端sdk",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "zz dev",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"fix": "zz lint --fix",
|
|
12
12
|
"staged": "zz lint --staged",
|
|
13
13
|
"staged-fix": "zz --staged --fix",
|
|
14
|
-
"pub": "
|
|
15
|
-
"pub-beta": "
|
|
14
|
+
"pub": "npm run build && npm publish",
|
|
15
|
+
"pub-beta": "npm run build && npm publish --tag beta",
|
|
16
16
|
"unpub": "zz pub --unpub",
|
|
17
17
|
"doc": "zz doc && zz doc --upload",
|
|
18
18
|
"dev-doc": "zz doc --dev",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@sentry/browser": "^10.10.0",
|
|
30
30
|
"compressing": "2.0.0",
|
|
31
|
-
"core-js": "3.6.5",
|
|
32
31
|
"fs": "^0.0.1-security",
|
|
33
32
|
"fs-extra": "^11.3.0",
|
|
34
33
|
"koffi": "2.14.1",
|
|
@@ -36,10 +35,10 @@
|
|
|
36
35
|
"request": "^2.88.2",
|
|
37
36
|
"sudo-prompt": "^9.2.1",
|
|
38
37
|
"usb": "^2.15.0",
|
|
39
|
-
"usbmux": "^0.1.0"
|
|
38
|
+
"usbmux": "^0.1.0",
|
|
39
|
+
"web-worker": "1.5.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@babel/plugin-transform-runtime": "7.21.0",
|
|
43
42
|
"@commitlint/cli": "8.3.5",
|
|
44
43
|
"@commitlint/config-conventional": "8.3.4",
|
|
45
44
|
"@evilmartians/lefthook": "0.8.0",
|
|
@@ -53,6 +52,7 @@
|
|
|
53
52
|
"commitlint": "17.0.2",
|
|
54
53
|
"father": "4.6.7",
|
|
55
54
|
"lint-staged": "10.0.8",
|
|
55
|
+
"minimatch": "3.0.0",
|
|
56
56
|
"path-to-regexp": "2.4.0",
|
|
57
57
|
"typedoc": "0.23.9",
|
|
58
58
|
"typescript": "4.7.4"
|
|
@@ -63,8 +63,7 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
66
|
-
"lib"
|
|
67
|
-
"es"
|
|
66
|
+
"lib"
|
|
68
67
|
],
|
|
69
68
|
"engines": {
|
|
70
69
|
"node": ">=20.0.0"
|