Skip to content

Commit 8b1914f

Browse files
author
liuqiang
committed
fix: rollback
1 parent d474911 commit 8b1914f

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

harmony/pushy/oh-package-lock.json5

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

harmony/pushy/src/main/ets/UpdateContext.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ export class UpdateContext {
4949

5050
private initPreferences() {
5151
try {
52+
try {
53+
if (typeof preferences.removePreferencesFromCacheSync === 'function') {
54+
preferences.removePreferencesFromCacheSync(this.context, 'update');
55+
}
56+
} catch (e) {
57+
console.error('Failed to remove preferences from cache:', e);
58+
}
5259
this.preferences = preferences.getPreferencesSync(this.context, {
5360
name: 'update',
5461
});
@@ -147,6 +154,10 @@ export class UpdateContext {
147154
flushablePreferences.flushSync();
148155
return;
149156
}
157+
if (typeof this.preferences.flush === 'function') {
158+
this.preferences.flush();
159+
return;
160+
}
150161
throw Error('preferences.flushSync is not available');
151162
} catch (error) {
152163
console.error(`Failed to flush preferences for ${reason}:`, error);
@@ -167,6 +178,7 @@ export class UpdateContext {
167178
}
168179

169180
private getStateSnapshot(): StateCoreResult {
181+
this.initPreferences();
170182
return {
171183
packageVersion: this.readString('packageVersion'),
172184
buildTime: this.readString('buildTime'),
@@ -198,6 +210,7 @@ export class UpdateContext {
198210
clearFirstLoadMarker?: boolean;
199211
} = {},
200212
): void {
213+
this.initPreferences();
201214
if (options.clearExisting) {
202215
this.preferences.clear();
203216
}
@@ -275,11 +288,13 @@ export class UpdateContext {
275288
}
276289

277290
public setKv(key: string, value: string): void {
291+
this.initPreferences();
278292
this.preferences.putSync(key, value);
279293
this.flushPreferences(`set key ${key}`);
280294
}
281295

282296
public getKv(key: string): string {
297+
this.initPreferences();
283298
return this.readString(key);
284299
}
285300

@@ -397,6 +412,7 @@ export class UpdateContext {
397412
}
398413

399414
public consumeFirstLoadMarker(): boolean {
415+
this.initPreferences();
400416
const marked = this.readString('firstLoadMarked') === 'true';
401417
if (marked) {
402418
this.preferences.deleteSync('firstLoadMarked');

src/NativePushy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ export interface Spec extends TurboModule {
1212
isUsingBundleUrl: boolean;
1313
currentVersionInfo: string;
1414
};
15-
// 可选:鸿蒙实现,供 JS 运行时获取无副作用的最新 currentVersion。
16-
// iOS/Android 不实现,JS 侧用可选链回退到 getConstants 启动常量。
17-
getCurrentVersion?: () => string;
15+
// 必选:RNOH 的 TurboModule 绑定按 spec 生成,只绑定必选方法;声明成可选会被跳过,
16+
// 导致 JS 拿不到该方法。iOS/Android native 未实现该方法,RN TurboModule proxy 访问未注册
17+
// 方法返回 undefined,core.ts 的 getCurrentVersion() 用特性检测回退到启动常量,不会 crash。
18+
getCurrentVersion: () => string;
1819
setLocalHashInfo(hash: string, info: string): Promise<void>;
1920
getLocalHashInfo(hash: string): Promise<string>;
2021
setUuid(uuid: string): Promise<void>;

src/core.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ export function getCurrentVersion(): string {
4545
const fn = (
4646
PushyModule as { getCurrentVersion?: () => string }
4747
).getCurrentVersion;
48-
return fn ? fn() : currentVersion;
48+
const result = fn ? fn() : currentVersion;
49+
// 临时诊断:确认 RNOH 是否把 native getCurrentVersion 绑定给了 JS。
50+
// hasFn=function 表示已绑定(走 native),undefined 表示未绑定(回退启动常量)。
51+
console.log('pushy_getcv_diag', JSON.stringify({ hasFn: typeof fn, fb: currentVersion, res: result }));
52+
return result;
4953
}
5054

5155
export function setLocalHashInfo(hash: string, info: Record<string, any>) {

0 commit comments

Comments
 (0)