diff --git a/packages/main/deviceDetector/adapters/linuxAdapter.ts b/packages/main/deviceDetector/adapters/linuxAdapter.ts index 4c3b4c49..250f751f 100644 --- a/packages/main/deviceDetector/adapters/linuxAdapter.ts +++ b/packages/main/deviceDetector/adapters/linuxAdapter.ts @@ -1,7 +1,10 @@ import { Singleton } from '@common/function/singletonDecorator' +import { $ } from '@main/utils/shell' import type { Device, Emulator, EmulatorAdapter } from '@type/device' import psList from 'ps-list' +import { defaultAdbPath, getDeviceUuid, parseAdbDevice } from '../utils' + @Singleton class LinuxEmulator implements EmulatorAdapter { protected async getBluestack(): Promise {} @@ -13,7 +16,14 @@ class LinuxEmulator implements EmulatorAdapter { protected async getLd(): Promise {} async getAdbDevices(): Promise { - return [] + const { stdout } = await $`${defaultAdbPath} devices` + const devices = parseAdbDevice(stdout) + return Promise.all( + devices.map(async d => { + const uuid = await getDeviceUuid(d.address, defaultAdbPath) + return { ...d, uuid: uuid || '' } + }) + ) } async getEmulators(): Promise { diff --git a/packages/main/deviceDetector/adapters/macAdapter.ts b/packages/main/deviceDetector/adapters/macAdapter.ts index be84a0cc..5bd2d4b4 100644 --- a/packages/main/deviceDetector/adapters/macAdapter.ts +++ b/packages/main/deviceDetector/adapters/macAdapter.ts @@ -1,7 +1,10 @@ import { Singleton } from '@common/function/singletonDecorator' +import { $ } from '@main/utils/shell' import type { Device, Emulator, EmulatorAdapter } from '@type/device' import psList from 'ps-list' +import { defaultAdbPath, getDeviceUuid, parseAdbDevice } from '../utils' + @Singleton class MacEmulator implements EmulatorAdapter { protected async getBluestack(): Promise {} @@ -13,7 +16,14 @@ class MacEmulator implements EmulatorAdapter { protected async getLd(): Promise {} async getAdbDevices(): Promise { - return [] + const { stdout } = await $`${defaultAdbPath} devices` + const devices = parseAdbDevice(stdout) + return Promise.all( + devices.map(async d => { + const uuid = await getDeviceUuid(d.address, defaultAdbPath) + return { ...d, uuid: uuid || '' } + }) + ) } async getEmulators(): Promise { diff --git a/packages/main/deviceDetector/adapters/winAdapter.ts b/packages/main/deviceDetector/adapters/winAdapter.ts index c45f218b..6aaddba9 100644 --- a/packages/main/deviceDetector/adapters/winAdapter.ts +++ b/packages/main/deviceDetector/adapters/winAdapter.ts @@ -1,6 +1,6 @@ /* eslint-disable vue/max-len */ import { Singleton } from '@common/function/singletonDecorator' -import { defaultAdbPath, getDeviceUuid } from '@main/deviceDetector/utils' +import { defaultAdbPath, getDeviceUuid, parseAdbDevice } from '@main/deviceDetector/utils' import logger from '@main/utils/logger' import { $ } from '@main/utils/shell' import type { Device, Emulator, EmulatorAdapter } from '@type/device' @@ -370,8 +370,14 @@ class WindowsAdapter implements EmulatorAdapter { } async getAdbDevices(): Promise { - const emulators: Device[] = [] - return emulators + const { stdout } = await $`${defaultAdbPath} devices` + const devices = parseAdbDevice(stdout) + return Promise.all( + devices.map(async d => { + const uuid = await getDeviceUuid(d.address, defaultAdbPath) + return { ...d, uuid: uuid || '' } + }) + ) } async getEmulators(): Promise { diff --git a/packages/main/deviceDetector/utils.ts b/packages/main/deviceDetector/utils.ts index bfbd2f1f..aaa9b78e 100644 --- a/packages/main/deviceDetector/utils.ts +++ b/packages/main/deviceDetector/utils.ts @@ -2,6 +2,7 @@ import { getComponentBaseDir } from '@main/componentManager/utils/path' import logger from '@main/utils/logger' import { getPlatform } from '@main/utils/os' import { $, $$ } from '@main/utils/shell' +import type { Device } from '@type/device' import { app } from 'electron' import fs from 'fs' import _ from 'lodash' @@ -38,3 +39,27 @@ export async function getDeviceUuid( } return false } + +export function parseAdbDevice(stdout: string): Device[] { + const lines = stdout.trim().split('\n') + lines.shift() + + if (lines.length === 0) { + return [] + } + + const connected = lines + .map(line => { + const [address, status] = line.split('\t') + return { address, status } + }) + .filter(({ status }) => status === 'device') + + return connected.map(({ address }) => ({ + uuid: '', + address, + status: 'available', + adbPath: defaultAdbPath, + config: 'General', + })) +}