Skip to content

Commit c2cfaa8

Browse files
committed
fix buildtime
1 parent 2f83e16 commit c2cfaa8

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EventHub } from './EventHub';
66
import { DownloadTaskParams } from './DownloadTaskParams';
77
import Pushy from 'librnupdate.so';
88
import { saveFileToSandbox } from './SaveFile';
9+
import { util } from '@kit.ArkTS';
910

1011
interface ZipEntry {
1112
filename: string;
@@ -255,12 +256,10 @@ export class DownloadTask {
255256

256257
if (fn === '__diff.json') {
257258
foundDiff = true;
258-
let jsonContent = '';
259259
const bufferArray = new Uint8Array(entry.content);
260-
for (let i = 0; i < bufferArray.length; i++) {
261-
jsonContent += String.fromCharCode(bufferArray[i]);
262-
}
263-
const obj = JSON.parse(jsonContent);
260+
const obj = JSON.parse(
261+
new util.TextDecoder().decodeToString(bufferArray),
262+
);
264263

265264
const copies = obj.copies as Record<string, string>;
266265
for (const [to, rawPath] of Object.entries(copies)) {
@@ -345,12 +344,10 @@ export class DownloadTask {
345344
console.error('copy error:', error);
346345
});
347346

348-
let jsonContent = '';
349347
const bufferArray = new Uint8Array(entry.content);
350-
for (let i = 0; i < bufferArray.length; i++) {
351-
jsonContent += String.fromCharCode(bufferArray[i]);
352-
}
353-
const obj = JSON.parse(jsonContent);
348+
const obj = JSON.parse(
349+
new util.TextDecoder().decodeToString(bufferArray),
350+
);
354351

355352
const { copies, deletes } = obj;
356353
for (const [to, from] of Object.entries(copies)) {

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import logger from './Logger';
99
import { UpdateModuleImpl } from './UpdateModuleImpl';
1010
import { UpdateContext } from './UpdateContext';
1111
import { EventHub } from './EventHub';
12+
import { util } from '@kit.ArkTS';
1213

1314
const TAG = 'PushyTurboModule';
1415

@@ -44,7 +45,20 @@ export class PushyTurboModule extends TurboModule {
4445
'',
4546
) as string;
4647
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
47-
const buildTime = preferencesManager.getSync('buildTime', '') as string;
48+
let buildTime = preferencesManager.getSync('buildTime', '') as string;
49+
if (!buildTime) {
50+
try {
51+
const resourceManager = this.mUiCtx.resourceManager;
52+
const content = resourceManager.getRawFileContentSync('metadata.json');
53+
const metaData = JSON.parse(
54+
new util.TextDecoder().decodeToString(content),
55+
);
56+
if (metaData.buildTime) {
57+
buildTime = String(metaData.buildTime);
58+
preferencesManager.putSync('buildTime', buildTime);
59+
}
60+
} catch {}
61+
}
4862
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
4963
let bundleFlags =
5064
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;

0 commit comments

Comments
 (0)