@hot-updater/react-native 0.12.6 → 0.13.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/generated/java/com/hotupdater/NativeHotUpdaterSpec.java +32 -0
- package/android/generated/jni/HotUpdaterSpec-generated.cpp +6 -0
- package/android/generated/jni/react/renderer/components/HotUpdaterSpec/HotUpdaterSpecJSI-generated.cpp +6 -0
- package/android/generated/jni/react/renderer/components/HotUpdaterSpec/HotUpdaterSpecJSI.h +9 -0
- package/android/src/main/java/com/hotupdater/HotUpdater.kt +47 -1
- package/android/src/newarch/HotUpdaterModule.kt +6 -0
- package/android/src/newarch/ReactIntegrationManager.kt +28 -6
- package/android/src/oldarch/HotUpdaterModule.kt +16 -0
- package/android/src/oldarch/ReactIntegrationManager.kt +15 -1
- package/dist/checkForUpdate.d.ts +2 -3
- package/dist/fetchUpdateInfo.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +68 -47
- package/dist/index.mjs +67 -47
- package/dist/native.d.ts +8 -0
- package/dist/runUpdateProcess.d.ts +4 -5
- package/dist/store.d.ts +1 -1
- package/dist/wrap.d.ts +2 -1
- package/ios/HotUpdater/HotUpdater.mm +68 -5
- package/ios/generated/HotUpdaterSpec/HotUpdaterSpec-generated.mm +7 -0
- package/ios/generated/HotUpdaterSpec/HotUpdaterSpec.h +37 -1
- package/ios/generated/HotUpdaterSpecJSI-generated.cpp +6 -0
- package/ios/generated/HotUpdaterSpecJSI.h +9 -0
- package/package.json +5 -5
- package/src/checkForUpdate.ts +14 -22
- package/src/fetchUpdateInfo.ts +22 -0
- package/src/index.ts +7 -1
- package/src/native.ts +21 -1
- package/src/runUpdateProcess.ts +11 -10
- package/src/specs/NativeHotUpdater.ts +3 -0
- package/src/store.ts +4 -4
- package/src/wrap.tsx +19 -4
- package/dist/ensureUpdateInfo.d.ts +0 -2
- package/src/ensureUpdateInfo.ts +0 -36
package/src/native.ts
CHANGED
|
@@ -4,6 +4,7 @@ const NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
|
|
4
4
|
|
|
5
5
|
const HotUpdater = {
|
|
6
6
|
HOT_UPDATER_BUNDLE_ID: NIL_UUID,
|
|
7
|
+
CHANNEL: "production",
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
const LINKING_ERROR =
|
|
@@ -79,6 +80,17 @@ export const reload = () => {
|
|
|
79
80
|
});
|
|
80
81
|
};
|
|
81
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Fetches the minimum bundle id, which represents the initial bundle of the app
|
|
85
|
+
* since it is created at build time.
|
|
86
|
+
*
|
|
87
|
+
* @returns {string} Resolves with the minimum bundle id or null if not available.
|
|
88
|
+
*/
|
|
89
|
+
export const getMinBundleId = (): string => {
|
|
90
|
+
const constants = HotUpdaterNative.getConstants();
|
|
91
|
+
return constants.MIN_BUNDLE_ID;
|
|
92
|
+
};
|
|
93
|
+
|
|
82
94
|
/**
|
|
83
95
|
* Fetches the current bundle version id.
|
|
84
96
|
*
|
|
@@ -86,5 +98,13 @@ export const reload = () => {
|
|
|
86
98
|
* @returns {Promise<string>} Resolves with the current version id or null if not available.
|
|
87
99
|
*/
|
|
88
100
|
export const getBundleId = (): string => {
|
|
89
|
-
|
|
101
|
+
const minBundleId = getMinBundleId();
|
|
102
|
+
|
|
103
|
+
return minBundleId.localeCompare(HotUpdater.HOT_UPDATER_BUNDLE_ID) >= 0
|
|
104
|
+
? minBundleId
|
|
105
|
+
: HotUpdater.HOT_UPDATER_BUNDLE_ID;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const getChannel = (): string => {
|
|
109
|
+
return HotUpdater.CHANNEL;
|
|
90
110
|
};
|
package/src/runUpdateProcess.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { type CheckForUpdateConfig, checkForUpdate } from "./checkForUpdate";
|
|
2
|
-
import { reload, updateBundle } from "./native";
|
|
2
|
+
import { getBundleId, reload, updateBundle } from "./native";
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
| {
|
|
11
|
-
status: "UP_TO_DATE";
|
|
12
|
-
};
|
|
4
|
+
export interface RunUpdateProcessResponse {
|
|
5
|
+
status: "ROLLBACK" | "UPDATE" | "UP_TO_DATE";
|
|
6
|
+
shouldForceUpdate: boolean;
|
|
7
|
+
message: string | null;
|
|
8
|
+
id: string;
|
|
9
|
+
}
|
|
13
10
|
|
|
14
11
|
export interface RunUpdateProcessConfig extends CheckForUpdateConfig {
|
|
15
12
|
/**
|
|
@@ -60,6 +57,9 @@ export const runUpdateProcess = async ({
|
|
|
60
57
|
if (!updateInfo) {
|
|
61
58
|
return {
|
|
62
59
|
status: "UP_TO_DATE",
|
|
60
|
+
shouldForceUpdate: false,
|
|
61
|
+
message: null,
|
|
62
|
+
id: getBundleId(),
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -75,5 +75,6 @@ export const runUpdateProcess = async ({
|
|
|
75
75
|
status: updateInfo.status,
|
|
76
76
|
shouldForceUpdate: updateInfo.shouldForceUpdate,
|
|
77
77
|
id: updateInfo.id,
|
|
78
|
+
message: updateInfo.message,
|
|
78
79
|
};
|
|
79
80
|
};
|
|
@@ -10,6 +10,9 @@ interface Spec extends TurboModule {
|
|
|
10
10
|
// EventEmitter
|
|
11
11
|
addListener(eventName: string): void;
|
|
12
12
|
removeListeners(count: number): void;
|
|
13
|
+
readonly getConstants: () => {
|
|
14
|
+
MIN_BUNDLE_ID: string;
|
|
15
|
+
};
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export default TurboModuleRegistry.get<Spec>("HotUpdater");
|
package/src/store.ts
CHANGED
|
@@ -24,10 +24,10 @@ const createHotUpdaterStore = () => {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const setState = (newState: Partial<HotUpdaterState>) => {
|
|
28
28
|
state = {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
...state,
|
|
30
|
+
...newState,
|
|
31
31
|
};
|
|
32
32
|
emitChange();
|
|
33
33
|
};
|
|
@@ -37,7 +37,7 @@ const createHotUpdaterStore = () => {
|
|
|
37
37
|
return () => listeners.delete(listener);
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
return { getSnapshot,
|
|
40
|
+
return { getSnapshot, setState, subscribe };
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export const hotUpdaterStore = createHotUpdaterStore();
|
package/src/wrap.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { useEffect, useLayoutEffect, useState } from "react";
|
|
3
3
|
import { type CheckForUpdateConfig, checkForUpdate } from "./checkForUpdate";
|
|
4
4
|
import { HotUpdaterError } from "./error";
|
|
5
5
|
import { useEventCallback } from "./hooks/useEventCallback";
|
|
6
|
-
import { reload, updateBundle } from "./native";
|
|
6
|
+
import { getBundleId, reload, updateBundle } from "./native";
|
|
7
7
|
import type { RunUpdateProcessResponse } from "./runUpdateProcess";
|
|
8
8
|
import { useHotUpdaterStore } from "./store";
|
|
9
9
|
|
|
@@ -37,6 +37,7 @@ export interface HotUpdaterConfig extends CheckForUpdateConfig {
|
|
|
37
37
|
fallbackComponent?: React.FC<{
|
|
38
38
|
status: Exclude<UpdateStatus, "UPDATE_PROCESS_COMPLETED">;
|
|
39
39
|
progress: number;
|
|
40
|
+
message: string | null;
|
|
40
41
|
}>;
|
|
41
42
|
onError?: (error: HotUpdaterError) => void;
|
|
42
43
|
onProgress?: (progress: number) => void;
|
|
@@ -62,9 +63,10 @@ export function wrap<P>(
|
|
|
62
63
|
return (WrappedComponent) => {
|
|
63
64
|
const HotUpdaterHOC: React.FC<P> = () => {
|
|
64
65
|
const progress = useHotUpdaterStore((state) => state.progress);
|
|
66
|
+
|
|
67
|
+
const [message, setMessage] = useState<string | null>(null);
|
|
65
68
|
const [updateStatus, setUpdateStatus] =
|
|
66
69
|
useState<UpdateStatus>("CHECK_FOR_UPDATE");
|
|
67
|
-
|
|
68
70
|
const initHotUpdater = useEventCallback(async () => {
|
|
69
71
|
try {
|
|
70
72
|
setUpdateStatus("CHECK_FOR_UPDATE");
|
|
@@ -72,9 +74,14 @@ export function wrap<P>(
|
|
|
72
74
|
source: restConfig.source,
|
|
73
75
|
requestHeaders: restConfig.requestHeaders,
|
|
74
76
|
});
|
|
77
|
+
setMessage(updateInfo?.message ?? null);
|
|
78
|
+
|
|
75
79
|
if (!updateInfo) {
|
|
76
80
|
restConfig.onUpdateProcessCompleted?.({
|
|
77
81
|
status: "UP_TO_DATE",
|
|
82
|
+
shouldForceUpdate: false,
|
|
83
|
+
message: null,
|
|
84
|
+
id: getBundleId(),
|
|
78
85
|
});
|
|
79
86
|
setUpdateStatus("UPDATE_PROCESS_COMPLETED");
|
|
80
87
|
return;
|
|
@@ -86,6 +93,7 @@ export function wrap<P>(
|
|
|
86
93
|
id: updateInfo.id,
|
|
87
94
|
status: updateInfo.status,
|
|
88
95
|
shouldForceUpdate: updateInfo.shouldForceUpdate,
|
|
96
|
+
message: updateInfo.message,
|
|
89
97
|
});
|
|
90
98
|
setUpdateStatus("UPDATE_PROCESS_COMPLETED");
|
|
91
99
|
return;
|
|
@@ -111,6 +119,7 @@ export function wrap<P>(
|
|
|
111
119
|
id: updateInfo.id,
|
|
112
120
|
status: updateInfo.status,
|
|
113
121
|
shouldForceUpdate: updateInfo.shouldForceUpdate,
|
|
122
|
+
message: updateInfo.message,
|
|
114
123
|
});
|
|
115
124
|
setUpdateStatus("UPDATE_PROCESS_COMPLETED");
|
|
116
125
|
} catch (error) {
|
|
@@ -135,7 +144,13 @@ export function wrap<P>(
|
|
|
135
144
|
updateStatus !== "UPDATE_PROCESS_COMPLETED"
|
|
136
145
|
) {
|
|
137
146
|
const Fallback = restConfig.fallbackComponent;
|
|
138
|
-
return
|
|
147
|
+
return (
|
|
148
|
+
<Fallback
|
|
149
|
+
progress={progress}
|
|
150
|
+
status={updateStatus}
|
|
151
|
+
message={message}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
139
154
|
}
|
|
140
155
|
|
|
141
156
|
return <WrappedComponent />;
|
package/src/ensureUpdateInfo.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Bundle,
|
|
3
|
-
BundleArg,
|
|
4
|
-
GetBundlesArgs,
|
|
5
|
-
UpdateInfo,
|
|
6
|
-
} from "@hot-updater/core";
|
|
7
|
-
|
|
8
|
-
export const ensureUpdateInfo = async (
|
|
9
|
-
source: BundleArg,
|
|
10
|
-
{ appVersion, bundleId, platform }: GetBundlesArgs,
|
|
11
|
-
requestHeaders?: Record<string, string>,
|
|
12
|
-
): Promise<Bundle[] | UpdateInfo> => {
|
|
13
|
-
try {
|
|
14
|
-
let bundles: Bundle[] | null = null;
|
|
15
|
-
if (typeof source === "string") {
|
|
16
|
-
if (source.startsWith("http")) {
|
|
17
|
-
return await fetch(source, {
|
|
18
|
-
headers: {
|
|
19
|
-
"x-app-platform": platform,
|
|
20
|
-
"x-app-version": appVersion,
|
|
21
|
-
"x-bundle-id": bundleId,
|
|
22
|
-
...requestHeaders,
|
|
23
|
-
},
|
|
24
|
-
}).then((res) => res.json());
|
|
25
|
-
}
|
|
26
|
-
} else if (typeof source === "function") {
|
|
27
|
-
bundles = await source();
|
|
28
|
-
} else {
|
|
29
|
-
bundles = source;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return bundles ?? [];
|
|
33
|
-
} catch {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
};
|