@lynx-js/devtool-connector 0.1.0 → 0.1.1
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/index.d.ts +1 -0
- package/dist/index.js +18 -3
- package/dist/transport/android.d.ts +1 -1
- package/dist/transport/index.js +32 -2
- package/dist/types.d.ts +3 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class Connector {
|
|
|
17
17
|
constructor(transports: Transport[]);
|
|
18
18
|
listClients(): Promise<Client[]>;
|
|
19
19
|
listDevices(): Promise<Device[]>;
|
|
20
|
+
close(): Promise<void>;
|
|
20
21
|
listAvailableApps(deviceId: string): Promise<App[]>;
|
|
21
22
|
openApp(deviceId: string, packageName: string, options?: OpenAppOptions): Promise<void>;
|
|
22
23
|
sendMessage<T, R>(clientId: string, message: T): Promise<R>;
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,12 @@ function isInitializeResponse(response) {
|
|
|
11
11
|
function isListSessionResponse(response) {
|
|
12
12
|
return 'Customized' === response.event && 'SessionList' === response.data.type;
|
|
13
13
|
}
|
|
14
|
+
function isGetGlobalSwitchResponse(response) {
|
|
15
|
+
return 'Customized' === response.event && 'GetGlobalSwitch' === response.data.type;
|
|
16
|
+
}
|
|
17
|
+
function isSetGlobalSwitchResponse(response) {
|
|
18
|
+
return 'Customized' === response.event && 'SetGlobalSwitch' === response.data.type;
|
|
19
|
+
}
|
|
14
20
|
function isCustomizedResponseWithType(response, type) {
|
|
15
21
|
return 'Customized' === response.event && response.data.type === type;
|
|
16
22
|
}
|
|
@@ -340,6 +346,9 @@ class Connector {
|
|
|
340
346
|
const results = await Promise.allSettled(this.#transports.map((t)=>t.listDevices()));
|
|
341
347
|
return results.filter((result)=>'fulfilled' === result.status).flatMap(({ value })=>value);
|
|
342
348
|
}
|
|
349
|
+
async close() {
|
|
350
|
+
await Promise.allSettled(this.#transports.map((t)=>t.close()));
|
|
351
|
+
}
|
|
343
352
|
async listAvailableApps(deviceId) {
|
|
344
353
|
const transport = await this.#findTransportWithDeviceId(deviceId);
|
|
345
354
|
return await transport.listAvailableApps(deviceId);
|
|
@@ -433,7 +442,9 @@ class Connector {
|
|
|
433
442
|
input: [
|
|
434
443
|
new GlobalSwitchRequestTransformStream('GetGlobalSwitch', options.port)
|
|
435
444
|
],
|
|
436
|
-
output: [
|
|
445
|
+
output: [
|
|
446
|
+
new FilterTransformStream(isGetGlobalSwitchResponse)
|
|
447
|
+
]
|
|
437
448
|
});
|
|
438
449
|
if ('object' == typeof message) return message?.global_value === 'true' || message?.global_value === true;
|
|
439
450
|
return 'true' === message || true === message;
|
|
@@ -447,7 +458,9 @@ class Connector {
|
|
|
447
458
|
input: [
|
|
448
459
|
new GlobalSwitchRequestTransformStream('SetGlobalSwitch', options.port)
|
|
449
460
|
],
|
|
450
|
-
output: [
|
|
461
|
+
output: [
|
|
462
|
+
new FilterTransformStream(isSetGlobalSwitchResponse)
|
|
463
|
+
]
|
|
451
464
|
});
|
|
452
465
|
}
|
|
453
466
|
async sendStream(clientId, inputStream, { signal }) {
|
|
@@ -583,7 +596,9 @@ class Connector {
|
|
|
583
596
|
input: [
|
|
584
597
|
new GlobalSwitchRequestTransformStream('SetGlobalSwitch', port)
|
|
585
598
|
],
|
|
586
|
-
output: [
|
|
599
|
+
output: [
|
|
600
|
+
new FilterTransformStream(isSetGlobalSwitchResponse)
|
|
601
|
+
]
|
|
587
602
|
});
|
|
588
603
|
} catch (err) {
|
|
589
604
|
src_debug(`listClientsForDevice ${deviceId}:${port} enable_devtool failed %O`, err);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SocketConnectOpts } from 'node:net';
|
|
2
|
-
import type { App, Connection, Device, OpenAppOptions, Transport, TransportConnectOptions } from './transport.
|
|
2
|
+
import type { App, Connection, Device, OpenAppOptions, Transport, TransportConnectOptions } from './transport.js';
|
|
3
3
|
export declare class AndroidTransport implements Transport {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(spec?: SocketConnectOpts);
|
package/dist/transport/index.js
CHANGED
|
@@ -11019,6 +11019,37 @@ class AndroidTransport {
|
|
|
11019
11019
|
]);
|
|
11020
11020
|
debug(`openApp clear data output ${output}`);
|
|
11021
11021
|
}
|
|
11022
|
+
try {
|
|
11023
|
+
const resolveOutput = await adb.subprocess.noneProtocol.spawnWaitText([
|
|
11024
|
+
'cmd',
|
|
11025
|
+
'package',
|
|
11026
|
+
'resolve-activity',
|
|
11027
|
+
'--brief',
|
|
11028
|
+
packageName
|
|
11029
|
+
]);
|
|
11030
|
+
const lines = resolveOutput.split('\n').map((line)=>line.trim());
|
|
11031
|
+
const activityName = lines.find((line)=>line.includes('/'));
|
|
11032
|
+
if (activityName && 'android/com.android.internal.app.ResolverActivity' !== activityName) {
|
|
11033
|
+
debug(`openApp am start: ${activityName}`);
|
|
11034
|
+
const amOutput = await adb.subprocess.noneProtocol.spawnWaitText([
|
|
11035
|
+
'am',
|
|
11036
|
+
'start',
|
|
11037
|
+
'-a',
|
|
11038
|
+
'android.intent.action.MAIN',
|
|
11039
|
+
'-c',
|
|
11040
|
+
'android.intent.category.LAUNCHER',
|
|
11041
|
+
'-f',
|
|
11042
|
+
'0x10200000',
|
|
11043
|
+
'-n',
|
|
11044
|
+
activityName
|
|
11045
|
+
]);
|
|
11046
|
+
debug(`openApp am start output: ${amOutput}`);
|
|
11047
|
+
if (!/^error:/im.exec(amOutput)) return;
|
|
11048
|
+
}
|
|
11049
|
+
} catch (e) {
|
|
11050
|
+
debug("openApp cmd package resolve-activity failed: %o", e);
|
|
11051
|
+
}
|
|
11052
|
+
debug('openApp trying fallback to monkey');
|
|
11022
11053
|
const output = await adb.subprocess.noneProtocol.spawnWaitText([
|
|
11023
11054
|
'monkey',
|
|
11024
11055
|
'-p',
|
|
@@ -11028,8 +11059,7 @@ class AndroidTransport {
|
|
|
11028
11059
|
'1'
|
|
11029
11060
|
]);
|
|
11030
11061
|
debug(`openApp LAUNCHER output ${output}`);
|
|
11031
|
-
if (output.includes('
|
|
11032
|
-
if (output.includes('monkey aborted')) throw new Error(`Failed to open app ${packageName}.`);
|
|
11062
|
+
if (!output.includes('Events injected:')) throw new Error(`Failed to open app ${packageName}: appium-adb style activation and monkey fallback both failed.`);
|
|
11033
11063
|
} catch (e) {
|
|
11034
11064
|
env.error = e;
|
|
11035
11065
|
env.hasError = true;
|
package/dist/types.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ export interface Session {
|
|
|
69
69
|
}
|
|
70
70
|
export type ListSessionRequest = CustomizedEvent<'ListSession', Record<string, never>>;
|
|
71
71
|
export type ListSessionResponse = CustomizedEvent<'SessionList', Session[]>;
|
|
72
|
-
export type GlobalKeys = 'enable_devtool';
|
|
72
|
+
export type GlobalKeys = 'enable_devtool' | 'enable_logbox' | 'enable_debug_mode' | 'enable_launch_record' | 'enable_quickjs_debug' | 'enable_quickjs_cache' | 'enable_v8' | 'enable_dom_tree' | 'enable_long_press_menu' | 'enable_highlight_touch' | 'enable_preview_screen_shot' | 'enable_pixel_copy' | 'enable_fsp_screenshot' | 'enable_perf_metrics';
|
|
73
73
|
export type GetGlobalSwitchRequest = CustomizedEvent<'GetGlobalSwitch', {
|
|
74
74
|
client_id: number;
|
|
75
75
|
session_id: number;
|
|
@@ -109,5 +109,7 @@ export interface CustomizedResponseMessageMap {
|
|
|
109
109
|
export type Response = InitializeResponse | ListSessionResponse | AppResponse | CDPResponse | GetGlobalSwitchResponse | SetGlobalSwitchResponse;
|
|
110
110
|
export declare function isInitializeResponse(response: Response): response is InitializeResponse;
|
|
111
111
|
export declare function isListSessionResponse(response: Response): response is ListSessionResponse;
|
|
112
|
+
export declare function isGetGlobalSwitchResponse(response: Response): response is GetGlobalSwitchResponse;
|
|
113
|
+
export declare function isSetGlobalSwitchResponse(response: Response): response is SetGlobalSwitchResponse;
|
|
112
114
|
export declare function isCustomizedResponseWithType<T extends keyof CustomizedResponseMap>(response: Response, type: T): response is CustomizedResponseMap[T];
|
|
113
115
|
export {};
|