diff --git a/harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets b/harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets index 06c9a172..d15f2407 100644 --- a/harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets +++ b/harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets @@ -9,36 +9,35 @@ import { UpdateContext } from './UpdateContext'; export class PushyFileJSBundleProvider extends JSBundleProvider { private updateContext: UpdateContext; - private path: string = ''; constructor(context: common.UIAbilityContext) { super(); this.updateContext = new UpdateContext(context); - this.path = this.updateContext.getBundleUrl(); } getURL(): string { - return this.path; + return this.updateContext.getBundleUrl(); } async getBundle(): Promise { - if (!this.path) { + const path = this.updateContext.getBundleUrl(); + if (!path) { throw new JSBundleProviderError({ whatHappened: 'No pushy bundle found. using default bundle', howCanItBeFixed: [''], }); } try { - await fs.access(this.path, fs.OpenMode.READ_ONLY); + await fs.access(path, fs.OpenMode.READ_ONLY); return { - filePath: this.path, + filePath: path, }; } catch (error) { throw new JSBundleProviderError({ - whatHappened: `Couldn't load JSBundle from ${this.path}`, + whatHappened: `Couldn't load JSBundle from ${path}`, extraData: error, howCanItBeFixed: [ - `Check if a bundle exists at "${this.path}" on your device.`, + `Check if a bundle exists at "${path}" on your device.`, ], }); } diff --git a/harmony/pushy/src/main/ets/PushyTurboModule.ts b/harmony/pushy/src/main/ets/PushyTurboModule.ts index ee71638a..d4a6049f 100644 --- a/harmony/pushy/src/main/ets/PushyTurboModule.ts +++ b/harmony/pushy/src/main/ets/PushyTurboModule.ts @@ -65,6 +65,17 @@ export class PushyTurboModule extends UITurboModule { await this.mUiCtx.startAbility(want); } + private async reloadBridge(): Promise { + const devToolsController = (this.ctx as Record).devToolsController; + if (devToolsController) { + logger.debug(TAG, 'reloadBridge via devToolsController RELOAD'); + devToolsController.eventEmitter.emit("RELOAD", { reason: 'HotReload2' }); + } else { + logger.debug(TAG, 'reloadBridge via restartAbility'); + await this.restartAbility(); + } + } + getConstants(): Object { logger.debug(TAG, ',call getConstants'); const packageVersion = this.context.getPackageVersion(); @@ -121,7 +132,7 @@ export class PushyTurboModule extends UITurboModule { try { this.context.switchVersion(hash); - await this.restartAbility(); + await this.reloadBridge(); } catch (error) { logger.error(TAG, `reloadUpdate failed: ${getErrorMessage(error)}`); throw Error(`switchVersion failed ${getErrorMessage(error)}`); @@ -131,7 +142,7 @@ export class PushyTurboModule extends UITurboModule { async restartApp(): Promise { logger.debug(TAG, ',call restartApp'); try { - await this.restartAbility(); + await this.reloadBridge(); } catch (error) { logger.error(TAG, `restartApp failed: ${getErrorMessage(error)}`); throw Error(`restartApp failed ${getErrorMessage(error)}`);