Skip to content
Merged
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
21 changes: 18 additions & 3 deletions harmony/pushy/src/main/ets/UpdateContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class UpdateContext {
private static DEBUG: boolean = false;
private static isUsingBundleUrl: boolean = false;
private static ignoreRollback: boolean = false;
private static cachedPackageVersion: string = '';
private static cachedBuildTime: string = '';

constructor(context: common.UIAbilityContext) {
this.context = context;
Expand Down Expand Up @@ -60,28 +62,38 @@ export class UpdateContext {
}

public getPackageVersion(): string {
if (UpdateContext.cachedPackageVersion) {
return UpdateContext.cachedPackageVersion;
}
try {
const bundleInfo = bundleManager.getBundleInfoForSelfSync(
this.getBundleFlags(),
);
return bundleInfo?.versionName || 'Unknown';
UpdateContext.cachedPackageVersion = bundleInfo?.versionName || 'Unknown';
return UpdateContext.cachedPackageVersion;
} catch (error) {
console.error('Failed to get bundle info:', error);
return '';
}
}

public getBuildTime(): string {
if (UpdateContext.cachedBuildTime) {
return UpdateContext.cachedBuildTime;
}
try {
const content =
this.context.resourceManager.getRawFileContentSync('meta.json');
const metaData = JSON.parse(
new util.TextDecoder().decodeToString(content),
) as Record<string, string | number | boolean | null | undefined>;
if (metaData.pushy_build_time) {
return String(metaData.pushy_build_time);
UpdateContext.cachedBuildTime = String(metaData.pushy_build_time);
return UpdateContext.cachedBuildTime;
}
} catch {}
} catch (error) {
console.error('Failed to read build time from raw file:', error);
}
return '';
}

Expand Down Expand Up @@ -244,6 +256,9 @@ export class UpdateContext {
packageVersion: string,
buildTime: string,
): void {
if (!packageVersion || !buildTime) {
return;
}
const currentState = this.getStateSnapshot();
const nextState = NativePatchCore.syncStateWithBinaryVersion(
packageVersion,
Expand Down