Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back ability to reveal preview when stuck on waiting #696

Merged
merged 3 commits into from
Nov 6, 2024
Merged
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
17 changes: 12 additions & 5 deletions packages/vscode-extension/src/project/deviceSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/vscode-extension/src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!, {
Comment on lines +601 to 604
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called twice with previewURL, some explanation why is that could be useful here (I assume that ideally, the second call would just set the status to "running", since the previewURL has been already set at this point but I don't know the codebase).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, couldn't the second one update only "status"? then the previewURL local variable is redundant too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second call doesn't change anything, but relying on the fact this callback gets called every time and it gets called before the method exists is a hidden assumption I'd prefer to avoid for the cost of updating the URL twice

previewURL,
Expand Down