@ebowwa/ios-devices 1.0.0 → 1.0.2
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/device-ctl.d.ts.map +1 -1
- package/dist/index.js +37 -30
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
- package/src/device-ctl.ts +44 -29
package/package.json
CHANGED
package/src/device-ctl.ts
CHANGED
|
@@ -50,24 +50,30 @@ export class DeviceCtl {
|
|
|
50
50
|
return this.parseDevicesFromText(result.stdout);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
// JSON structure is { result: { devices: [...] } }
|
|
54
|
+
const data = result.json as { result?: { devices?: Array<Record<string, unknown>> } };
|
|
55
|
+
const devices = data.result?.devices || [];
|
|
56
|
+
return devices.map((d) => this.parseDeviceFromJson(d));
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
private parseDeviceFromJson(device: Record<string, unknown>): IOSDevice {
|
|
60
|
+
const hardware = (device.hardwareProperties as Record<string, unknown>) || {};
|
|
61
|
+
const deviceProps = (device.deviceProperties as Record<string, unknown>) || {};
|
|
62
|
+
const connectionProps = (device.connectionProperties as Record<string, unknown>) || {};
|
|
63
|
+
|
|
58
64
|
return {
|
|
59
|
-
identifier: device.
|
|
60
|
-
name:
|
|
61
|
-
model:
|
|
62
|
-
modelCode:
|
|
63
|
-
productType:
|
|
64
|
-
osVersion:
|
|
65
|
-
osBuildVersion:
|
|
66
|
-
architecture:
|
|
67
|
-
platform: this.detectPlatform(
|
|
68
|
-
connectionType: this.detectConnectionType(
|
|
69
|
-
isTrusted:
|
|
70
|
-
isAvailable:
|
|
65
|
+
identifier: device.identifier as string || hardware.udid as string,
|
|
66
|
+
name: deviceProps.name as string || 'Unknown',
|
|
67
|
+
model: hardware.marketingName as string || '',
|
|
68
|
+
modelCode: hardware.hardwareModel as string || '',
|
|
69
|
+
productType: hardware.productType as string || '',
|
|
70
|
+
osVersion: deviceProps.osVersionNumber as string || '',
|
|
71
|
+
osBuildVersion: deviceProps.osBuildUpdate as string || '',
|
|
72
|
+
architecture: 'arm64e',
|
|
73
|
+
platform: this.detectPlatform(hardware.productType as string),
|
|
74
|
+
connectionType: this.detectConnectionType(connectionProps),
|
|
75
|
+
isTrusted: connectionProps.pairingState === 'paired',
|
|
76
|
+
isAvailable: connectionProps.tunnelState === 'connected' || connectionProps.pairingState === 'paired',
|
|
71
77
|
};
|
|
72
78
|
}
|
|
73
79
|
|
|
@@ -76,22 +82,32 @@ export class DeviceCtl {
|
|
|
76
82
|
const devices: IOSDevice[] = [];
|
|
77
83
|
|
|
78
84
|
for (const line of lines) {
|
|
79
|
-
// Parse format: "
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
// Parse table format: "Name Hostname Identifier State Model"
|
|
86
|
+
// Columns are separated by multiple spaces
|
|
87
|
+
const parts = line.split(/\s{2,}/).filter(p => p.trim());
|
|
88
|
+
if (parts.length >= 4 && parts[0] !== 'Name' && !parts[0].startsWith('-')) {
|
|
89
|
+
const name = parts[0].trim();
|
|
90
|
+
const identifier = parts[2].trim();
|
|
91
|
+
const state = parts[3].trim().toLowerCase();
|
|
92
|
+
const model = parts.length > 4 ? parts[4].trim() : '';
|
|
93
|
+
|
|
94
|
+
// Extract model code from parentheses if present, e.g., "iPhone 11 (iPhone12,1)"
|
|
95
|
+
const modelMatch = model.match(/\(([^)]+)\)/);
|
|
96
|
+
const modelCode = modelMatch ? modelMatch[1] : '';
|
|
97
|
+
|
|
82
98
|
devices.push({
|
|
83
|
-
identifier
|
|
84
|
-
name
|
|
85
|
-
model: '',
|
|
86
|
-
modelCode
|
|
87
|
-
productType:
|
|
88
|
-
osVersion:
|
|
99
|
+
identifier,
|
|
100
|
+
name,
|
|
101
|
+
model: model.replace(/\s*\([^)]+\)/, '').trim(),
|
|
102
|
+
modelCode,
|
|
103
|
+
productType: modelCode || model,
|
|
104
|
+
osVersion: '',
|
|
89
105
|
osBuildVersion: '',
|
|
90
106
|
architecture: 'arm64e',
|
|
91
|
-
platform:
|
|
107
|
+
platform: this.detectPlatform(model),
|
|
92
108
|
connectionType: 'USB',
|
|
93
109
|
isTrusted: true,
|
|
94
|
-
isAvailable:
|
|
110
|
+
isAvailable: state === 'connected',
|
|
95
111
|
});
|
|
96
112
|
}
|
|
97
113
|
}
|
|
@@ -108,10 +124,9 @@ export class DeviceCtl {
|
|
|
108
124
|
return 'iOS';
|
|
109
125
|
}
|
|
110
126
|
|
|
111
|
-
private detectConnectionType(
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
if (device.wirelessEnabled === true) return 'Wireless';
|
|
127
|
+
private detectConnectionType(connectionProps: Record<string, unknown>): 'USB' | 'Network' | 'Wireless' {
|
|
128
|
+
const tunnelState = connectionProps.tunnelState as string;
|
|
129
|
+
if (tunnelState === 'connected') return 'Network';
|
|
115
130
|
return 'USB';
|
|
116
131
|
}
|
|
117
132
|
|