8000 wip: handle app boot · NativeScript/nativescript-cli@4bedf0d · GitHub
[go: up one dir, main page]

Skip to content

Commit 4bedf0d

Browse files
committed
wip: handle app boot
1 parent 548c005 commit 4bedf0d

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

lib/controllers/run-controller.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from "../common/declarations";
2424
import { IInjector } from "../common/definitions/yok";
2525
import { injector } from "../common/yok";
26+
// import { ISharedEventBus } from "../declarations";
2627

2728
export class RunController extends EventEmitter implements IRunController {
2829
private prepareReadyEventHandler: any = null;
@@ -48,11 +49,17 @@ export class RunController extends EventEmitter implements IRunController {
4849
private $prepareNativePlatformService: IPrepareNativePlatformService,
4950
private $projectChangesService: IProjectChangesService,
5051
protected $projectDataService: IProjectDataService
51-
) {
52+
) // private $sharedEventBus: ISharedEventBus
53+
{
5254
super();
5355
}
56+
currentStartingHash = "";
5457

5558
public async run(runData: IRunData): Promise<void> {
59+
// this.$sharedEventBus.on("lastHashChanged", (v) => {
60+
// this.lastHash = v;
61+
// console.log("lasthashchanged", v);
62+
// });
5663
const { liveSyncInfo, deviceDescriptors } = runData;
5764
const { projectDir } = liveSyncInfo;
5865

@@ -777,13 +784,17 @@ export class RunController extends EventEmitter implements IRunController {
777784
fullSyncAction
778785
);
779786
console.log(`FILESTOSYNC ${filesToSync}`);
780-
// if() {
787+
const startingHash = this.$hmrStatusService.getStartingHash();
781788

782789
if (
783790
!liveSyncResultInfo.didRecover &&
784791
isInHMRMode &&
785-
filesToSync.some((file) => file.includes("hot-update"))
792+
filesToSync.some((file) => file.includes("hot-update")) &&
793+
(!startingHash ||
794+
this.currentStartingHash === startingHash ||
795+
startingHash === data.hmrData.hash)
786796
) {
797+
this.currentStartingHash = startingHash;
787798
console.time("hmrStatus");
788799

789800
const status = await this.$hmrStatusService.getHmrStatus(

lib/definitions/hmr-status-service.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ interface IHmrStatusService {
22
watchHmrStatus(deviceId: string, operationHash: string): void;
33
getHmrStatus(deviceId: string, operationHash: string): Promise<number>;
44
attachToHmrStatusEvent(): void;
5+
getStartingHash(): string;
56
}

lib/services/hmr-status-service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class HmrStatusService implements IHmrStatusService {
1212
public static STARTED_MESSAGE = "Checking for updates to the bundle with";
1313
public static SUCCESS_MESSAGE = "Successfully applied update with";
1414
public static FAILED_MESSAGE = "Cannot apply update with";
15+
private startingBundleHash: string;
1516
private hashOperationStatuses: IDictionary<any> = {};
1617
private intervals: IDictionary<any> = {};
1718

@@ -44,7 +45,7 @@ export class HmrStatusService implements IHmrStatusService {
4445
if (status || retryCount === 0) {
4546
clearInterval(this.intervals[key]);
4647
this.intervals[key] = null;
47-
resolve(status);
48+
resolve(status ?? HmrConstants.HMR_ERROR_STATUS);
4849
} else {
4950
retryCount--;
5051
}
@@ -85,6 +86,9 @@ export class HmrStatusService implements IHmrStatusService {
8586
regex: /\[HMR]\[(.+)]\s*(\w+)\s*\|/,
8687
handler: (matches: RegExpMatchArray, deviceId: string) => {
8788
const [hash, status] = matches.slice(1);
89+
if (status.trim() === "boot") {
90+
this.startingBundleHash = hash;
91+
}
8892
const mappedStatus = statusStringMap[status.trim()];
8993
if (mappedStatus) {
9094
this.setData(deviceId, hash, statusStringMap[status]);
@@ -94,6 +98,10 @@ export class HmrStatusService implements IHmrStatusService {
9498
});
9599
}
96100

101+
public getStartingHash() {
102+
return this.startingBundleHash;
103+
}
104+
97105
private handleAppCrash(matches: RegExpMatchArray, deviceId: string): void {
98106
for (const operationId in this.hashOperationStatuses) {
99107
const operation = this.hashOperationStatuses[operationId];

lib/services/webpack/webpack-compiler-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class WebpackCompilerService
6666
private $mobileHelper: Mobile.IMobileHelper,
6767
private $cleanupService: ICleanupService,
6868
private $packageManager: IPackageManager,
69-
private $packageInstallationManager: IPackageInstallationManager // private $sharedEventBus: ISharedEventBus
69+
private $packageInstallationManager: IPackageInstallationManager
7070
) {
7171
super();
7272
}
@@ -543,6 +543,7 @@ export class WebpackCompilerService
543543
}
544544
}
545545

546+
lastEmittedHash = "";
546547
private handleHMRMessage(
547548
message: IWebpackMessage,
548549
platformData: IPlatformData,

0 commit comments

Comments
 (0)
0