diff --git a/desktop/flipper-plugin/src/plugin/DevicePlugin.tsx b/desktop/flipper-plugin/src/plugin/DevicePlugin.tsx index 17c82b807..984b56388 100644 --- a/desktop/flipper-plugin/src/plugin/DevicePlugin.tsx +++ b/desktop/flipper-plugin/src/plugin/DevicePlugin.tsx @@ -42,6 +42,7 @@ export interface Device { readonly serial: string; readonly deviceType: DeviceType; onLogEntry(cb: DeviceLogListener): () => void; + executeShell(command: string): Promise; } export type DevicePluginPredicate = (device: Device) => boolean; @@ -69,6 +70,7 @@ export interface RealFlipperDevice { deviceType: DeviceType; addLogListener(callback: DeviceLogListener): Symbol; removeLogListener(id: Symbol): void; + executeShell(command: string): Promise; } export class SandyDevicePluginInstance extends BasePluginInstance { diff --git a/desktop/flipper-plugin/src/plugin/PluginBase.tsx b/desktop/flipper-plugin/src/plugin/PluginBase.tsx index 778f7511f..b0b5887b7 100644 --- a/desktop/flipper-plugin/src/plugin/PluginBase.tsx +++ b/desktop/flipper-plugin/src/plugin/PluginBase.tsx @@ -216,6 +216,9 @@ export abstract class BasePluginInstance { realDevice.removeLogListener(handle); }; }, + executeShell(command: string): Promise { + return realDevice.executeShell(command); + }, }; } diff --git a/desktop/flipper-plugin/src/test-utils/test-utils.tsx b/desktop/flipper-plugin/src/test-utils/test-utils.tsx index 3ea699e1f..6397d3d68 100644 --- a/desktop/flipper-plugin/src/test-utils/test-utils.tsx +++ b/desktop/flipper-plugin/src/test-utils/test-utils.tsx @@ -506,6 +506,7 @@ function createMockDevice(options?: StartPluginOptions): RealFlipperDevice & { addLogEntry(entry: DeviceLogEntry) { logListeners.forEach((f) => f?.(entry)); }, + executeShell: jest.fn(), }; } diff --git a/desktop/plugins/public/cpu/index.tsx b/desktop/plugins/public/cpu/index.tsx index 73a99b1ca..9b8bab519 100644 --- a/desktop/plugins/public/cpu/index.tsx +++ b/desktop/plugins/public/cpu/index.tsx @@ -74,18 +74,7 @@ function formatFrequency(freq: number) { export function devicePlugin(client: PluginClient<{}, {}>) { const device = client.device; - const executeShell = async (command: string) => { - // TODO: fix - return new Promise((resolve, reject) => { - (device.realDevice as any).adb - .shell(device.serial, command) - .then(adb.util.readAll) - .then(function (output: {toString: () => {trim: () => string}}) { - resolve(output.toString().trim()); - }) - .catch((e: unknown) => reject(e)); - }); - }; + const executeShell = async (command: string) => device.executeShell(command); let intervalID: NodeJS.Timer | null = null; const cpuState = createState({