react-native-update 10.39.0 → 10.40.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +0 -6
- package/android/jni/Application.mk +1 -1
- package/android/lib/arm64-v8a/librnupdate.so +0 -0
- package/android/lib/armeabi-v7a/librnupdate.so +0 -0
- package/android/lib/x86/librnupdate.so +0 -0
- package/android/lib/x86_64/librnupdate.so +0 -0
- package/android/src/main/java/cn/reactnative/modules/update/BundledResourceCopier.java +314 -0
- package/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +253 -586
- package/android/src/main/java/cn/reactnative/modules/update/NativeUpdateCore.java +1 -9
- package/android/src/main/java/cn/reactnative/modules/update/ReactReloadManager.java +220 -0
- package/android/src/main/java/cn/reactnative/modules/update/SafeZipFile.java +9 -3
- package/android/src/main/java/cn/reactnative/modules/update/UiThreadRunner.java +36 -0
- package/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java +36 -26
- package/android/src/main/java/cn/reactnative/modules/update/UpdateEventEmitter.java +39 -0
- package/android/src/main/java/cn/reactnative/modules/update/UpdateFileUtils.java +74 -0
- package/android/src/main/java/cn/reactnative/modules/update/UpdateModuleImpl.java +143 -260
- package/android/src/main/java/cn/reactnative/modules/update/UpdateModuleSupport.java +63 -0
- package/android/src/main/java/cn/reactnative/modules/update/UpdatePackage.java +1 -5
- package/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java +26 -73
- package/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java +28 -242
- package/harmony/pushy/src/main/cpp/PushyTurboModule.cpp +89 -135
- package/harmony/pushy/src/main/cpp/PushyTurboModule.h +5 -5
- package/harmony/pushy/src/main/ets/DownloadTaskParams.ts +7 -7
- package/harmony/pushy/src/main/ets/PushyPackage.ets +3 -9
- package/harmony/pushy/src/main/ets/PushyPackageCompat.ts +3 -9
- package/harmony/pushy/src/main/ets/PushyPackageFactory.ts +14 -0
- package/harmony/pushy/src/main/ets/PushyTurboModule.ts +124 -24
- package/harmony/pushy/src/main/ets/UpdateContext.ts +92 -70
- package/harmony/pushy.har +0 -0
- package/ios/Expo/ExpoPushyReactDelegateHandler.swift +6 -26
- package/ios/RCTPushy/RCTPushy.mm +315 -259
- package/ios/RCTPushy/RCTPushyDownloader.mm +52 -29
- package/package.json +2 -2
- package/react-native-update.podspec +3 -3
- package/harmony/pushy/src/main/ets/UpdateModuleImpl.ts +0 -123
- package/ios/ImportReact.h +0 -2
- package/ios/RCTPushy/HDiffPatch/HDiffPatch.h +0 -16
- package/ios/RCTPushy/HDiffPatch/HDiffPatch.mm +0 -35
- package/ios/RCTPushy/RCTPushyManager.h +0 -27
- package/ios/RCTPushy/RCTPushyManager.mm +0 -181
- package/ios/RCTPushy.xcodeproj/project.pbxproj +0 -479
- package/package/harmony/pushy.har +0 -0
- package/react-native-update-10.39.0-beta.3.tgz +0 -0
- package/scripts/prune-host-stl.sh +0 -6
|
@@ -1,142 +1,96 @@
|
|
|
1
|
-
|
|
2
1
|
#include "PushyTurboModule.h"
|
|
3
2
|
|
|
4
|
-
using namespace rnoh;
|
|
5
3
|
using namespace facebook;
|
|
4
|
+
using namespace rnoh;
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
jsi::Runtime &rt,
|
|
9
|
-
react::TurboModule & turboModule,
|
|
10
|
-
const jsi::Value* args,
|
|
11
|
-
size_t count)
|
|
12
|
-
{
|
|
13
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"getConstants", args, count));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static jsi::Value _hostFunction_PushyTurboModule_setLocalHashInfo(
|
|
17
|
-
jsi::Runtime &rt,
|
|
18
|
-
react::TurboModule & turboModule,
|
|
19
|
-
const jsi::Value* args,
|
|
20
|
-
size_t count)
|
|
21
|
-
{
|
|
22
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setLocalHashInfo", args, count));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static jsi::Value _hostFunction_PushyTurboModule_getLocalHashInfo(
|
|
26
|
-
jsi::Runtime &rt,
|
|
27
|
-
react::TurboModule & turboModule,
|
|
28
|
-
const jsi::Value* args,
|
|
29
|
-
size_t count)
|
|
30
|
-
{
|
|
31
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"getLocalHashInfo", args, count));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
static jsi::Value _hostFunction_PushyTurboModule_setUuid(
|
|
35
|
-
jsi::Runtime &rt,
|
|
36
|
-
react::TurboModule & turboModule,
|
|
37
|
-
const jsi::Value* args,
|
|
38
|
-
size_t count)
|
|
39
|
-
{
|
|
40
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setUuid", args, count));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static jsi::Value _hostFunction_PushyTurboModule_reloadUpdate(
|
|
44
|
-
jsi::Runtime &rt,
|
|
45
|
-
react::TurboModule & turboModule,
|
|
46
|
-
const jsi::Value* args,
|
|
47
|
-
size_t count)
|
|
48
|
-
{
|
|
49
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"reloadUpdate", args, count));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static jsi::Value _hostFunction_PushyTurboModule_setNeedUpdate(
|
|
53
|
-
jsi::Runtime &rt,
|
|
54
|
-
react::TurboModule & turboModule,
|
|
55
|
-
const jsi::Value* args,
|
|
56
|
-
size_t count)
|
|
57
|
-
{
|
|
58
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setNeedUpdate", args, count));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
static jsi::Value _hostFunction_PushyTurboModule_markSuccess(
|
|
62
|
-
jsi::Runtime &rt,
|
|
63
|
-
react::TurboModule & turboModule,
|
|
64
|
-
const jsi::Value* args,
|
|
65
|
-
size_t count)
|
|
66
|
-
{
|
|
67
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"markSuccess", args, count));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPpk(
|
|
71
|
-
jsi::Runtime &rt,
|
|
72
|
-
react::TurboModule & turboModule,
|
|
73
|
-
const jsi::Value* args,
|
|
74
|
-
size_t count)
|
|
75
|
-
{
|
|
76
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadPatchFromPpk", args, count));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPackage(
|
|
80
|
-
jsi::Runtime &rt,
|
|
81
|
-
react::TurboModule & turboModule,
|
|
82
|
-
const jsi::Value* args,
|
|
83
|
-
size_t count)
|
|
84
|
-
{
|
|
85
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadPatchFromPackage", args, count));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static jsi::Value _hostFunction_PushyTurboModule_downloadFullUpdate(
|
|
89
|
-
jsi::Runtime &rt,
|
|
90
|
-
react::TurboModule & turboModule,
|
|
91
|
-
const jsi::Value* args,
|
|
92
|
-
size_t count)
|
|
93
|
-
{
|
|
94
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadFullUpdate", args, count));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
static jsi::Value _hostFunction_PushyTurboModule_downloadAndInstallApk(
|
|
98
|
-
jsi::Runtime &rt,
|
|
99
|
-
react::TurboModule & turboModule,
|
|
100
|
-
const jsi::Value* args,
|
|
101
|
-
size_t count)
|
|
102
|
-
{
|
|
103
|
-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadAndInstallApk", args, count));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
6
|
+
namespace {
|
|
107
7
|
|
|
108
|
-
|
|
8
|
+
jsi::Value CallSync(
|
|
109
9
|
jsi::Runtime &rt,
|
|
110
|
-
react::TurboModule &
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
10
|
+
react::TurboModule &turboModule,
|
|
11
|
+
const char *methodName,
|
|
12
|
+
const jsi::Value *args,
|
|
13
|
+
size_t count) {
|
|
14
|
+
return jsi::Value(
|
|
15
|
+
static_cast<ArkTSTurboModule &>(turboModule).call(
|
|
16
|
+
rt, methodName, args, count));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
jsi::Value CallAsync(
|
|
118
20
|
jsi::Runtime &rt,
|
|
119
|
-
react::TurboModule &
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
21
|
+
react::TurboModule &turboModule,
|
|
22
|
+
const char *methodName,
|
|
23
|
+
const jsi::Value *args,
|
|
24
|
+
size_t count) {
|
|
25
|
+
return jsi::Value(
|
|
26
|
+
static_cast<ArkTSTurboModule &>(turboModule).callAsync(
|
|
27
|
+
rt, methodName, args, count));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#define PUSHY_SYNC_METHOD(method_name) \
|
|
31
|
+
static jsi::Value HostFunction_##method_name( \
|
|
32
|
+
jsi::Runtime &rt, \
|
|
33
|
+
react::TurboModule &turboModule, \
|
|
34
|
+
const jsi::Value *args, \
|
|
35
|
+
size_t count) { \
|
|
36
|
+
return CallSync(rt, turboModule, #method_name, args, count); \
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#define PUSHY_ASYNC_METHOD(method_name) \
|
|
40
|
+
static jsi::Value HostFunction_##method_name( \
|
|
41
|
+
jsi::Runtime &rt, \
|
|
42
|
+
react::TurboModule &turboModule, \
|
|
43
|
+
const jsi::Value *args, \
|
|
44
|
+
size_t count) { \
|
|
45
|
+
return CallAsync(rt, turboModule, #method_name, args, count); \
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
PUSHY_SYNC_METHOD(getConstants)
|
|
49
|
+
PUSHY_SYNC_METHOD(setLocalHashInfo)
|
|
50
|
+
PUSHY_SYNC_METHOD(getLocalHashInfo)
|
|
51
|
+
PUSHY_SYNC_METHOD(setUuid)
|
|
52
|
+
PUSHY_SYNC_METHOD(setNeedUpdate)
|
|
53
|
+
PUSHY_SYNC_METHOD(markSuccess)
|
|
54
|
+
PUSHY_SYNC_METHOD(addListener)
|
|
55
|
+
PUSHY_SYNC_METHOD(removeListeners)
|
|
56
|
+
|
|
57
|
+
PUSHY_ASYNC_METHOD(reloadUpdate)
|
|
58
|
+
PUSHY_ASYNC_METHOD(restartApp)
|
|
59
|
+
PUSHY_ASYNC_METHOD(downloadPatchFromPpk)
|
|
60
|
+
PUSHY_ASYNC_METHOD(downloadPatchFromPackage)
|
|
61
|
+
PUSHY_ASYNC_METHOD(downloadFullUpdate)
|
|
62
|
+
PUSHY_ASYNC_METHOD(downloadAndInstallApk)
|
|
63
|
+
|
|
64
|
+
#undef PUSHY_SYNC_METHOD
|
|
65
|
+
#undef PUSHY_ASYNC_METHOD
|
|
66
|
+
|
|
67
|
+
} // namespace
|
|
68
|
+
|
|
69
|
+
PushyTurboModule::PushyTurboModule(
|
|
70
|
+
const ArkTSTurboModule::Context ctx,
|
|
71
|
+
const std::string name)
|
|
72
|
+
: ArkTSTurboModule(ctx, name) {
|
|
73
|
+
const auto registerMethod =
|
|
74
|
+
[this](const std::string &methodName,
|
|
75
|
+
size_t argCount,
|
|
76
|
+
auto hostFunction) {
|
|
77
|
+
methodMap_[methodName] = MethodMetadata{argCount, hostFunction};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
registerMethod("getConstants", 0, HostFunction_getConstants);
|
|
81
|
+
registerMethod("setLocalHashInfo", 2, HostFunction_setLocalHashInfo);
|
|
82
|
+
registerMethod("getLocalHashInfo", 1, HostFunction_getLocalHashInfo);
|
|
83
|
+
registerMethod("setUuid", 1, HostFunction_setUuid);
|
|
84
|
+
registerMethod("reloadUpdate", 1, HostFunction_reloadUpdate);
|
|
85
|
+
registerMethod("restartApp", 0, HostFunction_restartApp);
|
|
86
|
+
registerMethod("setNeedUpdate", 1, HostFunction_setNeedUpdate);
|
|
87
|
+
registerMethod("markSuccess", 0, HostFunction_markSuccess);
|
|
88
|
+
registerMethod("downloadPatchFromPpk", 1, HostFunction_downloadPatchFromPpk);
|
|
89
|
+
registerMethod(
|
|
90
|
+
"downloadPatchFromPackage", 1, HostFunction_downloadPatchFromPackage);
|
|
91
|
+
registerMethod("downloadFullUpdate", 1, HostFunction_downloadFullUpdate);
|
|
92
|
+
registerMethod(
|
|
93
|
+
"downloadAndInstallApk", 1, HostFunction_downloadAndInstallApk);
|
|
94
|
+
registerMethod("addListener", 1, HostFunction_addListener);
|
|
95
|
+
registerMethod("removeListeners", 1, HostFunction_removeListeners);
|
|
96
|
+
}
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
#ifndef
|
|
26
|
-
#define
|
|
25
|
+
#ifndef PUSHY_TURBOMODULE_H
|
|
26
|
+
#define PUSHY_TURBOMODULE_H
|
|
27
27
|
|
|
28
28
|
#include <ReactCommon/TurboModule.h>
|
|
29
29
|
#include "RNOH/ArkTSTurboModule.h"
|
|
30
30
|
|
|
31
31
|
namespace rnoh {
|
|
32
32
|
class JSI_EXPORT PushyTurboModule : public ArkTSTurboModule {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
public:
|
|
34
|
+
PushyTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
35
35
|
};
|
|
36
36
|
} // namespace rnoh
|
|
37
37
|
|
|
38
|
-
#endif
|
|
38
|
+
#endif
|
|
@@ -9,11 +9,11 @@ export class DownloadTaskParams {
|
|
|
9
9
|
static readonly TASK_TYPE_PATCH_FROM_PPK: number = 3; // 从PPK补丁
|
|
10
10
|
static readonly TASK_TYPE_PLAIN_DOWNLOAD: number = 4; // 普通下载
|
|
11
11
|
|
|
12
|
-
type: number; // 任务类型
|
|
13
|
-
url: string; // 下载URL
|
|
14
|
-
hash: string; // 文件哈希值
|
|
15
|
-
originHash: string; // 原始文件哈希值
|
|
16
|
-
targetFile: string; // 目标文件路径
|
|
17
|
-
unzipDirectory: string; // 解压目录路径
|
|
18
|
-
originDirectory: string; // 原始文件目录路径
|
|
12
|
+
type: number = DownloadTaskParams.TASK_TYPE_CLEANUP; // 任务类型
|
|
13
|
+
url: string = ''; // 下载URL
|
|
14
|
+
hash: string = ''; // 文件哈希值
|
|
15
|
+
originHash: string = ''; // 原始文件哈希值
|
|
16
|
+
targetFile: string = ''; // 目标文件路径
|
|
17
|
+
unzipDirectory: string = ''; // 解压目录路径
|
|
18
|
+
originDirectory: string = ''; // 原始文件目录路径
|
|
19
19
|
}
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RNOHPackage,
|
|
3
|
-
UITurboModule,
|
|
4
|
-
UITurboModuleContext,
|
|
5
3
|
} from '@rnoh/react-native-openharmony';
|
|
6
|
-
import {
|
|
4
|
+
import { createPushyTurboModuleFactoryMap } from './PushyPackageFactory';
|
|
7
5
|
|
|
8
6
|
export class PushyPackage extends RNOHPackage {
|
|
9
|
-
override getUITurboModuleFactoryByNameMap()
|
|
10
|
-
|
|
11
|
-
(ctx: UITurboModuleContext) => UITurboModule | null
|
|
12
|
-
> {
|
|
13
|
-
return new Map<string, (ctx: UITurboModuleContext) => UITurboModule>()
|
|
14
|
-
.set(PushyTurboModule.NAME, (ctx) => new PushyTurboModule(ctx));
|
|
7
|
+
override getUITurboModuleFactoryByNameMap() {
|
|
8
|
+
return createPushyTurboModuleFactoryMap();
|
|
15
9
|
}
|
|
16
10
|
}
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RNPackage,
|
|
3
|
-
UITurboModule,
|
|
4
|
-
UITurboModuleContext,
|
|
5
3
|
} from '@rnoh/react-native-openharmony/ts';
|
|
6
|
-
import {
|
|
4
|
+
import { createPushyTurboModuleFactoryMap } from './PushyPackageFactory';
|
|
7
5
|
|
|
8
6
|
export class PushyPackage extends RNPackage {
|
|
9
|
-
override getUITurboModuleFactoryByNameMap()
|
|
10
|
-
|
|
11
|
-
(ctx: UITurboModuleContext) => UITurboModule | null
|
|
12
|
-
> {
|
|
13
|
-
return new Map<string, (ctx: UITurboModuleContext) => UITurboModule>()
|
|
14
|
-
.set(PushyTurboModule.NAME, (ctx) => new PushyTurboModule(ctx));
|
|
7
|
+
override getUITurboModuleFactoryByNameMap() {
|
|
8
|
+
return createPushyTurboModuleFactoryMap();
|
|
15
9
|
}
|
|
16
10
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UITurboModule,
|
|
3
|
+
UITurboModuleContext,
|
|
4
|
+
} from '@rnoh/react-native-openharmony/ts';
|
|
5
|
+
import { PushyTurboModule } from './PushyTurboModule';
|
|
6
|
+
|
|
7
|
+
export function createPushyTurboModuleFactoryMap(): Map<
|
|
8
|
+
string,
|
|
9
|
+
(ctx: UITurboModuleContext) => UITurboModule | null
|
|
10
|
+
> {
|
|
11
|
+
return new Map<string, (ctx: UITurboModuleContext) => UITurboModule | null>([
|
|
12
|
+
[PushyTurboModule.NAME, (ctx) => new PushyTurboModule(ctx)],
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
import common from '@ohos.app.ability.common';
|
|
6
6
|
import { bundleManager } from '@kit.AbilityKit';
|
|
7
7
|
import logger from './Logger';
|
|
8
|
-
import { UpdateModuleImpl } from './UpdateModuleImpl';
|
|
9
8
|
import { UpdateContext } from './UpdateContext';
|
|
10
9
|
import { EventHub } from './EventHub';
|
|
11
10
|
import { util } from '@kit.ArkTS';
|
|
@@ -26,29 +25,78 @@ export class PushyTurboModule extends UITurboModule {
|
|
|
26
25
|
EventHub.getInstance().setRNInstance(ctx.rnInstance);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
private getBundleFlags(): bundleManager.BundleFlag {
|
|
29
|
+
return bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private getErrorMessage(error: any): string {
|
|
33
|
+
if (error && typeof error === 'object' && 'message' in error) {
|
|
34
|
+
return String(error.message);
|
|
35
|
+
}
|
|
36
|
+
return String(error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private getPackageVersion(): string {
|
|
35
40
|
try {
|
|
36
|
-
const bundleInfo = bundleManager.getBundleInfoForSelfSync(
|
|
37
|
-
|
|
41
|
+
const bundleInfo = bundleManager.getBundleInfoForSelfSync(
|
|
42
|
+
this.getBundleFlags(),
|
|
43
|
+
);
|
|
44
|
+
return bundleInfo?.versionName || 'Unknown';
|
|
38
45
|
} catch (error) {
|
|
39
46
|
console.error('Failed to get bundle info:', error);
|
|
47
|
+
return '';
|
|
40
48
|
}
|
|
41
|
-
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private getBuildTime(): string {
|
|
42
52
|
try {
|
|
43
|
-
const
|
|
44
|
-
|
|
53
|
+
const content = this.mUiCtx.resourceManager.getRawFileContentSync(
|
|
54
|
+
'meta.json',
|
|
55
|
+
);
|
|
45
56
|
const metaData = JSON.parse(
|
|
46
57
|
new util.TextDecoder().decodeToString(content),
|
|
47
|
-
)
|
|
58
|
+
) as Record<string, string | number | boolean | null | undefined>;
|
|
48
59
|
if (metaData.pushy_build_time) {
|
|
49
|
-
|
|
60
|
+
return String(metaData.pushy_build_time);
|
|
50
61
|
}
|
|
51
62
|
} catch {}
|
|
63
|
+
return '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private requireHash(hash: string, methodName: string): string {
|
|
67
|
+
if (!hash) {
|
|
68
|
+
throw Error(`${methodName}: empty hash`);
|
|
69
|
+
}
|
|
70
|
+
return hash;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private validateHashInfo(info: string): void {
|
|
74
|
+
try {
|
|
75
|
+
const parsed = JSON.parse(info);
|
|
76
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
77
|
+
throw Error('invalid json string');
|
|
78
|
+
}
|
|
79
|
+
} catch {
|
|
80
|
+
throw Error('invalid json string');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private async restartAbility(): Promise<void> {
|
|
85
|
+
const bundleInfo = await bundleManager.getBundleInfoForSelf(
|
|
86
|
+
this.getBundleFlags(),
|
|
87
|
+
);
|
|
88
|
+
const want = {
|
|
89
|
+
bundleName: bundleInfo.name,
|
|
90
|
+
abilityName: this.mUiCtx.abilityInfo?.name,
|
|
91
|
+
};
|
|
92
|
+
await this.mUiCtx.terminateSelf();
|
|
93
|
+
await this.mUiCtx.startAbility(want);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getConstants(): Object {
|
|
97
|
+
logger.debug(TAG, ',call getConstants');
|
|
98
|
+
const packageVersion = this.getPackageVersion();
|
|
99
|
+
const buildTime = this.getBuildTime();
|
|
52
100
|
this.context.syncStateWithBinaryVersion(packageVersion, buildTime);
|
|
53
101
|
|
|
54
102
|
const currentVersion = this.context.getCurrentVersion();
|
|
@@ -65,7 +113,7 @@ export class PushyTurboModule extends UITurboModule {
|
|
|
65
113
|
}
|
|
66
114
|
|
|
67
115
|
return {
|
|
68
|
-
downloadRootDir: `${
|
|
116
|
+
downloadRootDir: `${this.mUiCtx.filesDir}/_update`,
|
|
69
117
|
currentVersionInfo,
|
|
70
118
|
packageVersion,
|
|
71
119
|
currentVersion,
|
|
@@ -79,31 +127,67 @@ export class PushyTurboModule extends UITurboModule {
|
|
|
79
127
|
|
|
80
128
|
setLocalHashInfo(hash: string, info: string): boolean {
|
|
81
129
|
logger.debug(TAG, ',call setLocalHashInfo');
|
|
82
|
-
|
|
130
|
+
this.validateHashInfo(info);
|
|
131
|
+
this.context.setKv(`hash_${hash}`, info);
|
|
132
|
+
return true;
|
|
83
133
|
}
|
|
84
134
|
|
|
85
135
|
getLocalHashInfo(hash: string): string {
|
|
86
|
-
|
|
136
|
+
const value = this.context.getKv(`hash_${hash}`);
|
|
137
|
+
this.validateHashInfo(value);
|
|
138
|
+
return value;
|
|
87
139
|
}
|
|
88
140
|
|
|
89
141
|
async setUuid(uuid: string): Promise<void> {
|
|
90
142
|
logger.debug(TAG, ',call setUuid');
|
|
91
|
-
|
|
143
|
+
this.context.setKv('uuid', uuid);
|
|
92
144
|
}
|
|
93
145
|
|
|
94
146
|
async reloadUpdate(options: { hash: string }): Promise<void> {
|
|
95
147
|
logger.debug(TAG, ',call reloadUpdate');
|
|
96
|
-
|
|
148
|
+
const hash = this.requireHash(options.hash, 'reloadUpdate');
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
this.context.switchVersion(hash);
|
|
152
|
+
await this.restartAbility();
|
|
153
|
+
} catch (error) {
|
|
154
|
+
logger.error(TAG, `reloadUpdate failed: ${this.getErrorMessage(error)}`);
|
|
155
|
+
throw Error(`switchVersion failed ${this.getErrorMessage(error)}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async restartApp(): Promise<void> {
|
|
160
|
+
logger.debug(TAG, ',call restartApp');
|
|
161
|
+
try {
|
|
162
|
+
await this.restartAbility();
|
|
163
|
+
} catch (error) {
|
|
164
|
+
logger.error(TAG, `restartApp failed: ${this.getErrorMessage(error)}`);
|
|
165
|
+
throw Error(`restartApp failed ${this.getErrorMessage(error)}`);
|
|
166
|
+
}
|
|
97
167
|
}
|
|
98
168
|
|
|
99
169
|
async setNeedUpdate(options: { hash: string }): Promise<boolean> {
|
|
100
170
|
logger.debug(TAG, ',call setNeedUpdate');
|
|
101
|
-
|
|
171
|
+
const hash = this.requireHash(options.hash, 'setNeedUpdate');
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
this.context.switchVersion(hash);
|
|
175
|
+
return true;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
logger.error(TAG, `setNeedUpdate failed: ${this.getErrorMessage(error)}`);
|
|
178
|
+
throw Error(`switchVersionLater failed: ${this.getErrorMessage(error)}`);
|
|
179
|
+
}
|
|
102
180
|
}
|
|
103
181
|
|
|
104
182
|
async markSuccess(): Promise<boolean> {
|
|
105
183
|
logger.debug(TAG, ',call markSuccess');
|
|
106
|
-
|
|
184
|
+
try {
|
|
185
|
+
this.context.markSuccess();
|
|
186
|
+
return true;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
logger.error(TAG, `markSuccess failed: ${this.getErrorMessage(error)}`);
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
107
191
|
}
|
|
108
192
|
|
|
109
193
|
async downloadPatchFromPpk(options: {
|
|
@@ -112,7 +196,11 @@ export class PushyTurboModule extends UITurboModule {
|
|
|
112
196
|
originHash: string;
|
|
113
197
|
}): Promise<void> {
|
|
114
198
|
logger.debug(TAG, ',call downloadPatchFromPpk');
|
|
115
|
-
return
|
|
199
|
+
return this.context.downloadPatchFromPpk(
|
|
200
|
+
options.updateUrl,
|
|
201
|
+
options.hash,
|
|
202
|
+
options.originHash,
|
|
203
|
+
);
|
|
116
204
|
}
|
|
117
205
|
|
|
118
206
|
async downloadPatchFromPackage(options: {
|
|
@@ -120,7 +208,10 @@ export class PushyTurboModule extends UITurboModule {
|
|
|
120
208
|
hash: string;
|
|
121
209
|
}): Promise<void> {
|
|
122
210
|
logger.debug(TAG, ',call downloadPatchFromPackage');
|
|
123
|
-
return
|
|
211
|
+
return this.context.downloadPatchFromPackage(
|
|
212
|
+
options.updateUrl,
|
|
213
|
+
options.hash,
|
|
214
|
+
);
|
|
124
215
|
}
|
|
125
216
|
|
|
126
217
|
async downloadFullUpdate(options: {
|
|
@@ -128,7 +219,16 @@ export class PushyTurboModule extends UITurboModule {
|
|
|
128
219
|
hash: string;
|
|
129
220
|
}): Promise<void> {
|
|
130
221
|
logger.debug(TAG, ',call downloadFullUpdate');
|
|
131
|
-
return
|
|
222
|
+
return this.context.downloadFullUpdate(options.updateUrl, options.hash);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async downloadAndInstallApk(_options: {
|
|
226
|
+
url: string;
|
|
227
|
+
target: string;
|
|
228
|
+
hash: string;
|
|
229
|
+
}): Promise<void> {
|
|
230
|
+
logger.debug(TAG, ',call downloadAndInstallApk');
|
|
231
|
+
throw Error('downloadAndInstallApk is only supported on Android');
|
|
132
232
|
}
|
|
133
233
|
|
|
134
234
|
addListener(_eventName: string): void {
|