Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
"test": "vitest run"
},
"dependencies": {
"@midscene/android": "workspace:*",
"@midscene/android-playground": "workspace:*",
"@midscene/computer": "workspace:*",
"@midscene/computer-playground": "workspace:*",
"@midscene/core": "workspace:*",
"@midscene/harmony": "workspace:*",
"@midscene/ios": "workspace:*",
"@midscene/playground": "workspace:*",
"@midscene/playground-app": "workspace:*",
"@midscene/shared": "workspace:*",
Expand Down
5 changes: 5 additions & 0 deletions apps/studio/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ export default defineConfig({
},
externals: [
'electron',
'@midscene/android',
'@midscene/android-playground',
'@midscene/computer',
'@midscene/computer-playground',
'@midscene/harmony',
'@midscene/ios',
'@midscene/playground',
],
sourceMap: true,
Expand Down
24 changes: 16 additions & 8 deletions apps/studio/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
shell,
} from 'electron';
import type { TitleBarOverlay } from 'electron';
import { createAndroidPlaygroundRuntimeService } from './playground/android-runtime';
import { runConnectivityTest } from './playground/connectivity-test';
import { discoverAllDevices } from './playground/device-discovery';
import { createMultiPlatformRuntimeService } from './playground/multi-platform-runtime';

/**
* Main process owns native shell concerns only.
Expand All @@ -22,7 +23,7 @@ import { runConnectivityTest } from './playground/connectivity-test';

let mainWindow: BrowserWindow | null = null;
let cachedAppIcon: NativeImage | null = null;
const androidPlaygroundRuntime = createAndroidPlaygroundRuntimeService();
const playgroundRuntime = createMultiPlatformRuntimeService();

const getRendererEntryPath = () =>
path.join(__dirname, '../renderer/index.html');
Expand Down Expand Up @@ -134,11 +135,18 @@ const registerIpcHandlers = () => {
ipcMain.handle(IPC_CHANNELS.closeWindow, () => {
mainWindow?.close();
});
ipcMain.handle(IPC_CHANNELS.getAndroidPlaygroundBootstrap, () =>
androidPlaygroundRuntime.getBootstrap(),
// Multi-platform playground — a single server for Android, iOS,
// HarmonyOS, and Computer. Legacy channel names (getAndroidPlayground*)
// are aliased to the same strings in IPC_CHANNELS, so the old
// renderer code keeps working transparently.
ipcMain.handle(IPC_CHANNELS.getPlaygroundBootstrap, () =>
playgroundRuntime.getBootstrap(),
);
ipcMain.handle(IPC_CHANNELS.restartAndroidPlayground, async () =>
androidPlaygroundRuntime.restart(),
ipcMain.handle(IPC_CHANNELS.restartPlayground, async () =>
playgroundRuntime.restart(),
);
ipcMain.handle(IPC_CHANNELS.discoverDevices, async () =>
discoverAllDevices(),
);
ipcMain.handle(IPC_CHANNELS.runConnectivityTest, async (_event, request) =>
runConnectivityTest(request),
Expand All @@ -151,7 +159,7 @@ app.whenReady().then(() => {
}

registerIpcHandlers();
void androidPlaygroundRuntime.start();
void playgroundRuntime.start();
createMainWindow();

app.on('activate', () => {
Expand All @@ -168,5 +176,5 @@ app.on('window-all-closed', () => {
});

app.on('before-quit', () => {
void androidPlaygroundRuntime.close();
void playgroundRuntime.close();
});
127 changes: 0 additions & 127 deletions apps/studio/src/main/playground/android-runtime.ts

This file was deleted.

82 changes: 82 additions & 0 deletions apps/studio/src/main/playground/device-discovery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { getDebug } from '@midscene/shared/logger';
import type { DiscoveredDevice } from '@shared/electron-contract';

const debugLog = getDebug('studio:device-discovery', { console: true });

/**
* Scan all platforms for connected devices. Each platform's scan is
* independent — a failure on one platform (e.g. `hdc` not installed)
* does not prevent others from returning results.
*
* iOS is intentionally omitted: device discovery requires WebDriverAgent
* to be running, which is a manual step. iOS devices show up after the
* user creates a session via the setup form.
*/
export async function discoverAllDevices(): Promise<DiscoveredDevice[]> {
const scans = await Promise.allSettled([
scanAndroidDevices(),
scanHarmonyDevices(),
scanComputerDisplays(),
]);

const results: DiscoveredDevice[] = [];
for (const scan of scans) {
if (scan.status === 'fulfilled') {
results.push(...scan.value);
} else {
debugLog('platform scan rejected:', scan.reason);
}
}

return results;
}

async function scanAndroidDevices(): Promise<DiscoveredDevice[]> {
try {
const { getConnectedDevicesWithDetails } = await import(
'@midscene/android'
);
const devices = await getConnectedDevicesWithDetails();
return devices.map((device) => ({
platformId: 'android',
id: device.udid,
label: (device as { label?: string }).label || device.udid,
description: `ADB: ${device.udid}`,
}));
} catch (err) {
debugLog('android scan failed:', err);
return [];
}
}

async function scanHarmonyDevices(): Promise<DiscoveredDevice[]> {
try {
const { getConnectedDevices } = await import('@midscene/harmony');
const devices = await getConnectedDevices();
return devices.map((device) => ({
platformId: 'harmony',
id: device.deviceId,
label: device.deviceId,
description: `HDC: ${device.deviceId}`,
}));
} catch (err) {
debugLog('harmony scan failed:', err);
return [];
}
}

async function scanComputerDisplays(): Promise<DiscoveredDevice[]> {
try {
const { getConnectedDisplays } = await import('@midscene/computer');
const displays = await getConnectedDisplays();
return displays.map((display) => ({
platformId: 'computer',
id: String(display.id),
label: display.name || `Display ${display.id}`,
description: display.primary ? 'Primary display' : undefined,
}));
} catch (err) {
debugLog('computer scan failed:', err);
return [];
}
}
Loading
Loading