@mobilenext/mobile-mcp 0.0.16 → 0.0.17
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/iphone-simulator.js +61 -25
- package/package.json +1 -1
package/lib/iphone-simulator.js
CHANGED
|
@@ -39,38 +39,74 @@ class Simctl {
|
|
|
39
39
|
async terminateApp(packageName) {
|
|
40
40
|
this.simctl("terminate", this.simulatorUuid, packageName);
|
|
41
41
|
}
|
|
42
|
-
parseIOSAppData(inputText) {
|
|
42
|
+
static parseIOSAppData(inputText) {
|
|
43
43
|
const result = [];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
44
|
+
let ParseState;
|
|
45
|
+
(function (ParseState) {
|
|
46
|
+
ParseState[ParseState["LOOKING_FOR_APP"] = 0] = "LOOKING_FOR_APP";
|
|
47
|
+
ParseState[ParseState["IN_APP"] = 1] = "IN_APP";
|
|
48
|
+
ParseState[ParseState["IN_PROPERTY"] = 2] = "IN_PROPERTY";
|
|
49
|
+
})(ParseState || (ParseState = {}));
|
|
50
|
+
let state = ParseState.LOOKING_FOR_APP;
|
|
51
|
+
let currentApp = {};
|
|
52
|
+
let appIdentifier = "";
|
|
53
|
+
const lines = inputText.split("\n");
|
|
54
|
+
for (let line of lines) {
|
|
55
|
+
line = line.trim();
|
|
56
|
+
if (line === "") {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
switch (state) {
|
|
60
|
+
case ParseState.LOOKING_FOR_APP:
|
|
61
|
+
// look for app identifier pattern: "com.example.app" = {
|
|
62
|
+
const appMatch = line.match(/^"?([^"=]+)"?\s*=\s*\{/);
|
|
63
|
+
if (appMatch) {
|
|
64
|
+
appIdentifier = appMatch[1].trim();
|
|
65
|
+
currentApp = {
|
|
66
|
+
CFBundleIdentifier: appIdentifier,
|
|
67
|
+
};
|
|
68
|
+
state = ParseState.IN_APP;
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
case ParseState.IN_APP:
|
|
72
|
+
if (line === "};") {
|
|
73
|
+
result.push(currentApp);
|
|
74
|
+
currentApp = {};
|
|
75
|
+
state = ParseState.LOOKING_FOR_APP;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// look for property: PropertyName = Value;
|
|
79
|
+
const propertyMatch = line.match(/^([^=]+)\s*=\s*(.+?);\s*$/);
|
|
80
|
+
if (propertyMatch) {
|
|
81
|
+
const propName = propertyMatch[1].trim();
|
|
82
|
+
let propValue = propertyMatch[2].trim();
|
|
83
|
+
// remove quotes if present (they're optional)
|
|
84
|
+
if (propValue.startsWith('"') && propValue.endsWith('"')) {
|
|
85
|
+
propValue = propValue.substring(1, propValue.length - 1);
|
|
86
|
+
}
|
|
87
|
+
// add property to current app
|
|
88
|
+
currentApp[propName] = propValue;
|
|
89
|
+
}
|
|
90
|
+
else if (line.endsWith("{")) {
|
|
91
|
+
// nested property like GroupContainers = {
|
|
92
|
+
state = ParseState.IN_PROPERTY;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
case ParseState.IN_PROPERTY:
|
|
97
|
+
if (line === "};") {
|
|
98
|
+
// end of nested property
|
|
99
|
+
state = ParseState.IN_APP;
|
|
100
|
+
}
|
|
101
|
+
// skip content of nested properties, we don't care of those right now
|
|
102
|
+
break;
|
|
66
103
|
}
|
|
67
|
-
result.push(appInfo);
|
|
68
104
|
}
|
|
69
105
|
return result;
|
|
70
106
|
}
|
|
71
107
|
async listApps() {
|
|
72
108
|
const text = this.simctl("listapps", this.simulatorUuid).toString();
|
|
73
|
-
const apps =
|
|
109
|
+
const apps = Simctl.parseIOSAppData(text);
|
|
74
110
|
return apps.map(app => ({
|
|
75
111
|
packageName: app.CFBundleIdentifier,
|
|
76
112
|
appName: app.CFBundleDisplayName,
|