create-droid 1.0.5 → 1.0.6
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/package.json +1 -1
- package/templates/base/scripts/adb.js +77 -10
package/package.json
CHANGED
|
@@ -39,6 +39,31 @@ function runCommand(args, inherit = true) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
async function getMdnsServices() {
|
|
43
|
+
const output = runCommand(['mdns', 'services'], false);
|
|
44
|
+
if (!output) return [];
|
|
45
|
+
|
|
46
|
+
// Output format usually:
|
|
47
|
+
// List of discovered mdns services
|
|
48
|
+
// <name> <type> <ip>:<port>
|
|
49
|
+
// myphone _adb-tls-connect._tcp. 192.168.1.5:38291
|
|
50
|
+
|
|
51
|
+
const lines = output.split('\n');
|
|
52
|
+
const services = [];
|
|
53
|
+
|
|
54
|
+
for (const line of lines) {
|
|
55
|
+
if (!line.includes('_adb-tls-connect') && !line.includes('_adb._tcp')) continue;
|
|
56
|
+
|
|
57
|
+
const parts = line.trim().split(/\s+/);
|
|
58
|
+
if (parts.length >= 3) {
|
|
59
|
+
const ipPort = parts[parts.length - 1]; // last part is ip:port
|
|
60
|
+
const name = parts[0];
|
|
61
|
+
services.push({ name, ipPort });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return services;
|
|
65
|
+
}
|
|
66
|
+
|
|
42
67
|
function clearScreen() {
|
|
43
68
|
process.stdout.write('\x1Bc');
|
|
44
69
|
}
|
|
@@ -85,7 +110,6 @@ async function showMenu() {
|
|
|
85
110
|
case '5':
|
|
86
111
|
console.log('Starting Logcat (Ctrl+C to stop)...');
|
|
87
112
|
await runCommand(['logcat']);
|
|
88
|
-
// Logcat blocks, so we won't return easily loop unless killed
|
|
89
113
|
break;
|
|
90
114
|
case '6':
|
|
91
115
|
await runCommand(['kill-server']);
|
|
@@ -103,12 +127,31 @@ async function showMenu() {
|
|
|
103
127
|
}
|
|
104
128
|
|
|
105
129
|
async function handleConnect() {
|
|
130
|
+
console.log('\nScanning for devices via mDNS...');
|
|
131
|
+
const services = await getMdnsServices();
|
|
132
|
+
|
|
133
|
+
if (services.length > 0) {
|
|
134
|
+
console.log('\nDiscovered Devices:');
|
|
135
|
+
services.forEach((s, i) => console.log(`${i + 1}. ${s.name} (${s.ipPort})`));
|
|
136
|
+
console.log(`${services.length + 1}. Enter manually`);
|
|
137
|
+
} else {
|
|
138
|
+
console.log('No mDNS devices found.');
|
|
139
|
+
}
|
|
140
|
+
|
|
106
141
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
107
|
-
rl.question('
|
|
142
|
+
rl.question('\nSelect device number or enter IP:Port: ', async (answer) => {
|
|
108
143
|
rl.close();
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
144
|
+
|
|
145
|
+
let target = answer.trim();
|
|
146
|
+
const idx = parseInt(target) - 1;
|
|
147
|
+
|
|
148
|
+
if (!isNaN(idx) && idx >= 0 && idx < services.length) {
|
|
149
|
+
target = services[idx].ipPort;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (target) {
|
|
153
|
+
console.log(`Connecting to ${target}...`);
|
|
154
|
+
await runCommand(['connect', target]);
|
|
112
155
|
}
|
|
113
156
|
await pause();
|
|
114
157
|
showMenu();
|
|
@@ -116,13 +159,37 @@ async function handleConnect() {
|
|
|
116
159
|
}
|
|
117
160
|
|
|
118
161
|
async function handlePair() {
|
|
162
|
+
console.log('\nScanning for devices via mDNS...');
|
|
163
|
+
const services = await getMdnsServices();
|
|
164
|
+
|
|
165
|
+
if (services.length > 0) {
|
|
166
|
+
console.log('\nDiscovered Devices:');
|
|
167
|
+
services.forEach((s, i) => console.log(`${i + 1}. ${s.name} (${s.ipPort})`));
|
|
168
|
+
console.log(`${services.length + 1}. Enter manually`);
|
|
169
|
+
} else {
|
|
170
|
+
console.log('No mDNS devices found.');
|
|
171
|
+
}
|
|
172
|
+
|
|
119
173
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
120
|
-
rl.question('
|
|
121
|
-
|
|
174
|
+
rl.question('\nSelect device number or enter IP:Port: ', (answer) => {
|
|
175
|
+
let target = answer.trim();
|
|
176
|
+
const idx = parseInt(target) - 1;
|
|
177
|
+
|
|
178
|
+
if (!isNaN(idx) && idx >= 0 && idx < services.length) {
|
|
179
|
+
target = services[idx].ipPort;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!target) {
|
|
183
|
+
rl.close();
|
|
184
|
+
showMenu();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
rl.question(`Enter Pairing Code for ${target}: `, async (code) => {
|
|
122
189
|
rl.close();
|
|
123
|
-
if (
|
|
124
|
-
console.log(`Pairing with ${
|
|
125
|
-
await runCommand(['pair',
|
|
190
|
+
if (code) {
|
|
191
|
+
console.log(`Pairing with ${target}...`);
|
|
192
|
+
await runCommand(['pair', target, code]);
|
|
126
193
|
}
|
|
127
194
|
await pause();
|
|
128
195
|
showMenu();
|