diff --git a/packages/vscode-extension/src/project/deviceSession.ts b/packages/vscode-extension/src/project/deviceSession.ts index 81e4c7199..67ec94c82 100644 --- a/packages/vscode-extension/src/project/deviceSession.ts +++ b/packages/vscode-extension/src/project/deviceSession.ts @@ -17,7 +17,8 @@ import { throttle } from "../utilities/throttle"; import { DependencyManager } from "../dependency/DependencyManager"; import { getTelemetryReporter } from "../utilities/telemetry"; -type StartOptions = { cleanBuild: boolean }; +type PreviewReadyCallback = (previewURL: string) => void; +type StartOptions = { cleanBuild: boolean; previewReadyCallback: PreviewReadyCallback }; export type AppEvent = { navigationChanged: { displayName: string; id: string }; @@ -104,7 +105,7 @@ export class DeviceSession implements Disposable { throw new Error("Not implemented " + type); } - private async launchApp() { + private async launchApp(previewReadyCallback?: PreviewReadyCallback) { const launchRequestTime = Date.now(); getTelemetryReporter().sendTelemetryEvent("app:launch:requested", { platform: this.device.platform, @@ -141,7 +142,10 @@ export class DeviceSession implements Disposable { await Promise.all([ this.metro.ready(), - this.device.startPreview().then((url) => (previewURL = url)), + this.device.startPreview().then((url) => { + previewURL = url; + previewReadyCallback && previewReadyCallback(url); + }), waitForAppReady, ]); Logger.debug("App and preview ready, moving on..."); @@ -203,14 +207,17 @@ export class DeviceSession implements Disposable { Logger.debug("Metro & devtools ready"); } - public async start(deviceSettings: DeviceSettings, { cleanBuild }: StartOptions) { + public async start( + deviceSettings: DeviceSettings, + { cleanBuild, previewReadyCallback }: StartOptions + ) { this.deviceSettings = deviceSettings; await this.waitForMetroReady(); // TODO(jgonet): Build and boot simultaneously, with predictable state change updates await this.bootDevice(deviceSettings); await this.buildApp({ clean: cleanBuild }); await this.installApp({ reinstall: false }); - const previewUrl = await this.launchApp(); + const previewUrl = await this.launchApp(previewReadyCallback); Logger.debug("Device session started"); return previewUrl; } diff --git a/packages/vscode-extension/src/project/project.ts b/packages/vscode-extension/src/project/project.ts index 3353661d5..847925929 100644 --- a/packages/vscode-extension/src/project/project.ts +++ b/packages/vscode-extension/src/project/project.ts @@ -597,6 +597,9 @@ export class Project const previewURL = await newDeviceSession.start(this.deviceSettings, { cleanBuild: forceCleanBuild, + previewReadyCallback: (url) => { + this.updateProjectStateForDevice(deviceInfo, { previewURL: url }); + }, }); this.updateProjectStateForDevice(this.projectState.selectedDevice!, { previewURL,