Skip to content
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
2 changes: 1 addition & 1 deletion harmony/pushy/src/main/ets/PushyTurboModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class PushyTurboModule extends UITurboModule {
const currentVersionInfo = currentVersion
? this.context.getKv(`hash_${currentVersion}`)
: '';
const isFirstTime = this.context.isFirstTime();
const isFirstTime = this.context.consumeFirstLoadMarker();
const rolledBackVersion = this.context.rolledBackVersion();
const uuid = this.context.getKv('uuid');
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
Expand Down
42 changes: 35 additions & 7 deletions harmony/pushy/src/main/ets/UpdateContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class UpdateContext {
private preferences!: preferences.Preferences;
private static DEBUG: boolean = false;
private static isUsingBundleUrl: boolean = false;
private static ignoreRollback: boolean = false;

constructor(context: common.UIAbilityContext) {
this.context = context;
Expand Down Expand Up @@ -72,9 +73,8 @@ export class UpdateContext {

public getBuildTime(): string {
try {
const content = this.context.resourceManager.getRawFileContentSync(
'meta.json',
);
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>;
Expand Down Expand Up @@ -182,6 +182,8 @@ export class UpdateContext {
clearExisting?: boolean;
removeStaleHash?: boolean;
cleanUp?: boolean;
markFirstLoadMarker?: boolean;
clearFirstLoadMarker?: boolean;
} = {},
): void {
if (options.clearExisting) {
Expand All @@ -191,6 +193,12 @@ export class UpdateContext {
if (options.removeStaleHash && state.staleVersionToDelete) {
this.preferences.deleteSync(`hash_${state.staleVersionToDelete}`);
}
if (options.markFirstLoadMarker) {
this.preferences.putSync('firstLoadMarked', 'true');
}
if (options.clearFirstLoadMarker) {
this.preferences.deleteSync('firstLoadMarked');
}
this.flushPreferences('persist state');
if (options.cleanUp) {
this.cleanUp();
Expand All @@ -203,6 +211,7 @@ export class UpdateContext {
options: {
removeStaleHash?: boolean;
cleanUp?: boolean;
clearFirstLoadMarker?: boolean;
} = {},
): StateCoreResult {
const nextState = NativePatchCore.runStateCore(
Expand Down Expand Up @@ -245,6 +254,7 @@ export class UpdateContext {
return;
}

UpdateContext.ignoreRollback = false;
this.cleanUp();
this.persistState(nextState, { clearExisting: true });
}
Expand Down Expand Up @@ -278,7 +288,10 @@ export class UpdateContext {
}

public clearFirstTime(): void {
this.runStateOperation(STATE_OP_CLEAR_FIRST_TIME, '', { cleanUp: true });
this.runStateOperation(STATE_OP_CLEAR_FIRST_TIME, '', {
cleanUp: true,
clearFirstLoadMarker: true,
});
}

public clearRollbackMark(): void {
Expand Down Expand Up @@ -361,23 +374,38 @@ export class UpdateContext {
}

this.runStateOperation(STATE_OP_SWITCH_VERSION, hash);
UpdateContext.ignoreRollback = false;
} catch (e) {
console.error('Failed to switch version:', e);
throw e;
}
}

public consumeFirstLoadMarker(): boolean {
const marked = this.readString('firstLoadMarked') === 'true';
if (marked) {
this.preferences.deleteSync('firstLoadMarked');
this.flushPreferences('clear first load marker');
}
return marked;
}

public getBundleUrl() {
UpdateContext.isUsingBundleUrl = true;
const launchState = NativePatchCore.runStateCore(
STATE_OP_RESOLVE_LAUNCH,
this.getStateSnapshot(),
'',
false,
false,
UpdateContext.ignoreRollback,
true,
);
if (launchState.didRollback || launchState.consumedFirstTime) {
this.persistState(launchState);
this.persistState(launchState, {
markFirstLoadMarker: launchState.consumedFirstTime,
});
}
if (launchState.consumedFirstTime) {
UpdateContext.ignoreRollback = true;
}

let version = launchState.loadVersion || '';
Expand Down