Skip to content

Commit

Permalink
Fix for error message when reloading iOS application during build (#25)
Browse files Browse the repository at this point in the history
Description: 
This is a primitive fix of a problem with reloading on iOS during build.

Before: 
When reloading when subprocess running `xcodebuild` was active the
information about that process being killed would leak and cause change
in `ProjectState.status` to `buildError` despite the fact that new build
was up and running.

After: this change prevents unwanted change in status, when it is caused
by previous session

Fixes: #8

---------

Co-authored-by: Filip Andrzej Kaminski <[email protected]>
  • Loading branch information
filip131311 and Filip Andrzej Kaminski authored Mar 25, 2024
1 parent 53624d1 commit a09c849
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/vscode-extension/src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {
extensionContext.workspaceState.update(LAST_SELECTED_DEVICE_KEY, deviceInfo.id);

this.reloadingMetro = false;
this.deviceSession?.dispose();
const prevSession = this.deviceSession;
this.deviceSession = undefined;
prevSession?.dispose();

this.updateProjectState({
selectedDevice: deviceInfo,
Expand All @@ -331,6 +332,8 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {
previewURL: undefined,
});

let newDeviceSession;

try {
const device = await this.deviceManager.getDevice(deviceInfo);
Logger.debug("Selected device is ready");
Expand All @@ -340,7 +343,7 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {
// wait for metro/devtools to start before we continue
await Promise.all([this.metro.ready(), this.devtools.ready()]);
Logger.debug("Metro & devtools ready");
const newDeviceSession = new DeviceSession(
newDeviceSession = new DeviceSession(
device,
this.devtools,
this.metro,
Expand Down Expand Up @@ -370,7 +373,10 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {
});
} catch (e) {
Logger.error("Couldn't start device session", e);
if (this.projectState.selectedDevice === deviceInfo) {
if (
this.projectState.selectedDevice === deviceInfo &&
this.deviceSession === newDeviceSession
) {
this.updateProjectState({
status: "buildError",
});
Expand Down

0 comments on commit a09c849

Please sign in to comment.