mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-11-22 15:36:10 +08:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc9b5d722a | ||
|
|
e151c9c618 | ||
|
|
2a79061b89 | ||
|
|
e04ce54de6 | ||
|
|
38229a8bca | ||
|
|
6661e307cd | ||
|
|
027bd16af2 | ||
|
|
4daaadce70 | ||
|
|
43ed2f50fe | ||
|
|
e46d01714a | ||
|
|
366b2a6618 | ||
|
|
34e053ae48 | ||
|
|
d55ef1d8c8 | ||
|
|
de3e7d9e4c | ||
|
|
e0201d3882 | ||
|
|
ba5b35813d | ||
|
|
3134f36739 | ||
|
|
d4f4740053 | ||
|
|
a248f18035 |
@@ -7,7 +7,7 @@
|
||||
"@react-native-oh/react-native-harmony": "^0.72.59",
|
||||
"react": "18.2.0",
|
||||
"react-native": "0.72.5",
|
||||
"react-native-update": "^10.34.9",
|
||||
"react-native-update": "^10.35.4",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.0",
|
||||
@@ -1399,7 +1399,7 @@
|
||||
|
||||
"react-native": ["react-native@0.72.5", "", { "dependencies": { "@jest/create-cache-key-function": "^29.2.1", "@react-native-community/cli": "11.3.7", "@react-native-community/cli-platform-android": "11.3.7", "@react-native-community/cli-platform-ios": "11.3.7", "@react-native/assets-registry": "^0.72.0", "@react-native/codegen": "^0.72.7", "@react-native/gradle-plugin": "^0.72.11", "@react-native/js-polyfills": "^0.72.1", "@react-native/normalize-colors": "^0.72.0", "@react-native/virtualized-lists": "^0.72.8", "abort-controller": "^3.0.0", "anser": "^1.4.9", "base64-js": "^1.1.2", "deprecated-react-native-prop-types": "4.1.0", "event-target-shim": "^5.0.1", "flow-enums-runtime": "^0.0.5", "invariant": "^2.2.4", "jest-environment-node": "^29.2.1", "jsc-android": "^250231.0.0", "memoize-one": "^5.0.0", "metro-runtime": "0.76.8", "metro-source-map": "0.76.8", "mkdirp": "^0.5.1", "nullthrows": "^1.1.1", "pretty-format": "^26.5.2", "promise": "^8.3.0", "react-devtools-core": "^4.27.2", "react-refresh": "^0.4.0", "react-shallow-renderer": "^16.15.0", "regenerator-runtime": "^0.13.2", "scheduler": "0.24.0-canary-efb381bbf-20230505", "stacktrace-parser": "^0.1.10", "use-sync-external-store": "^1.0.0", "whatwg-fetch": "^3.0.0", "ws": "^6.2.2", "yargs": "^17.6.2" }, "peerDependencies": { "react": "18.2.0" }, "bin": { "react-native": "cli.js" } }, "sha512-oIewslu5DBwOmo7x5rdzZlZXCqDIna0R4dUwVpfmVteORYLr4yaZo5wQnMeR+H7x54GaMhmgeqp0ZpULtulJFg=="],
|
||||
|
||||
"react-native-update": ["react-native-update@10.34.9", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-Bk9Wr6R3XTz4OwKnmcxm4S1heuZMFvdW+544Kcc5KMN/D8JHrf656yK35TYTNhRJPjq6oEsGfLDxgbQWSPtbIg=="],
|
||||
"react-native-update": ["react-native-update@10.35.4", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-daSbe0EtQhihy+ldHaivmBdAUQ0WjQgS8t++icMcxOsS5vD5F5IdLusrb5LVFLmCLZQ7Z81e5CwbKUSn5o087A=="],
|
||||
|
||||
"react-native-url-polyfill": ["react-native-url-polyfill@2.0.0", "", { "dependencies": { "whatwg-url-without-unicode": "8.0.0-3" }, "peerDependencies": { "react-native": "*" } }, "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA=="],
|
||||
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
buildOption: {
|
||||
strictMode: {
|
||||
caseSensitiveCheck: true,
|
||||
useNormalizedOHMUrl: true,
|
||||
useNormalizedOHMUrl: true
|
||||
},
|
||||
"nativeCompiler": "BiSheng"
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1,44 +1,9 @@
|
||||
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export function generatePushyBuildTime(str?: string) {
|
||||
return {
|
||||
pluginId: 'PushyBuildTimePlugin',
|
||||
apply(pluginContext) {
|
||||
pluginContext.registerTask({
|
||||
name: 'pushy_build_time',
|
||||
run: (taskContext) => {
|
||||
const metaFilePath = path.resolve(__dirname, 'src/main/resources/rawfile/meta.json');
|
||||
const dirPath = path.dirname(metaFilePath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
const moduleJsonPath = path.resolve(__dirname, '../AppScope/app.json5');
|
||||
let versionName = '';
|
||||
if (fs.existsSync(moduleJsonPath)) {
|
||||
const moduleContent = fs.readFileSync(moduleJsonPath, 'utf-8');
|
||||
const versionMatch = moduleContent.match(/"versionName":\s*"([^"]+)"/);
|
||||
if (versionMatch && versionMatch[1]) {
|
||||
versionName = versionMatch[1];
|
||||
}
|
||||
}
|
||||
const buildTime = new Date().toISOString();
|
||||
const metaContent = {
|
||||
pushy_build_time: buildTime,
|
||||
versionName: versionName
|
||||
};
|
||||
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4));
|
||||
console.log(`Build time written to ${metaFilePath}`);
|
||||
},
|
||||
dependencies: [],
|
||||
postDependencies: ['default@BuildJS']
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
import {hapTasks} from '@ohos/hvigor-ohos-plugin';
|
||||
import {reactNativeUpdatePlugin} from 'pushy/hvigor-plugin';
|
||||
|
||||
export default {
|
||||
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[generatePushyBuildTime()] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
||||
system: hapTasks /* Built-in plugin of Hvigor. It cannot be modified. */,
|
||||
plugins: [
|
||||
reactNativeUpdatePlugin(),
|
||||
] /* Custom plugin to extend the functionality of Hvigor. */,
|
||||
};
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38",
|
||||
"@rnoh/react-native-openharmony@0.72.96": "@rnoh/react-native-openharmony@0.72.96",
|
||||
"pushy@../../node_modules/react-native-update/harmony/pushy": "pushy@../../node_modules/react-native-update/harmony/pushy"
|
||||
},
|
||||
"packages": {
|
||||
"@rnoh/react-native-openharmony@0.72.38": {
|
||||
"@rnoh/react-native-openharmony@0.72.96": {
|
||||
"name": "",
|
||||
"version": "0.72.38",
|
||||
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
|
||||
"version": "0.72.96",
|
||||
"integrity": "sha512-gBbm8LLyqi5UE7qHWdZYeQnjyncfEpCczKZUP/9M2U1Z7exR0Kya8PMKMwr1ta5ujy7w/hZVC2LomEV4QvBeqA==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.96.har",
|
||||
"registryType": "ohpm"
|
||||
},
|
||||
"pushy@../../node_modules/react-native-update/harmony/pushy": {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
author: '',
|
||||
license: '',
|
||||
dependencies: {
|
||||
'@rnoh/react-native-openharmony': '0.72.38',
|
||||
'@rnoh/react-native-openharmony': '0.72.96',
|
||||
pushy: 'file:../../node_modules/react-native-update/harmony/pushy',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ struct Index {
|
||||
enableCAPIArchitecture: true,
|
||||
arkTsComponentNames: arkTsComponentNames,
|
||||
},
|
||||
initialProps: { "foo": "bar" } as Record<string, string>,
|
||||
appKey: "harmony_use_pushy",
|
||||
wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
|
||||
onSetUp: (rnInstance) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"dependencies": {
|
||||
pushy: 'file:../../node_modules/react-native-update/harmony/pushy'
|
||||
},
|
||||
"execution": {
|
||||
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
},
|
||||
},
|
||||
overrides: {
|
||||
'@rnoh/react-native-openharmony': '0.72.38',
|
||||
'@rnoh/react-native-openharmony': '0.72.96',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"lint": "eslint .",
|
||||
"start": "npm run codegen && hdc rport tcp:8081 tcp:8081 && react-native start",
|
||||
"codegen": "react-native codegen-harmony --rnoh-module-path ./harmony/react_native_openharmony",
|
||||
"build": "pushy bundle --platform harmony",
|
||||
"build": "pushy bundle --platform harmony --no-interactive",
|
||||
"test": "jest",
|
||||
"hdiffFromPPK": "pushy hdiffFromPPK .pushy/output/harmony.1735052610653.ppk .pushy/output/harmony.1735052678646.ppk .pushy/output/hdiff.ppk-patch",
|
||||
"hdiffFromApp": "pushy hdiffFromApp .pushy/output/version-1.0.0.app .pushy/output/harmony.1735052610653.ppk .pushy/output/hdiff.app-patch",
|
||||
@@ -18,7 +18,7 @@
|
||||
"@react-native-oh/react-native-harmony": "^0.72.59",
|
||||
"react": "18.2.0",
|
||||
"react-native": "0.72.5",
|
||||
"react-native-update": "^10.34.9"
|
||||
"react-native-update": "^10.35.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.0",
|
||||
@@ -40,4 +40,4 @@
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"react-native-paper": "^5.14.5",
|
||||
"react-native-safe-area-context": "^5.6.1",
|
||||
"react-native-svg": "^15.13.0",
|
||||
"react-native-update": "^10.34.4",
|
||||
"react-native-update": "^10.35.6",
|
||||
"react-native-vector-icons": "^10.3.0",
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -1430,7 +1430,7 @@
|
||||
|
||||
"react-native-svg": ["react-native-svg@15.13.0", "", { "dependencies": { "css-select": "^5.1.0", "css-tree": "^1.1.3", "warn-once": "0.1.1" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-/YPK+PAAXg4T0x2d2vYPvqqAhOYid2bRKxUVT7STIyd1p2JxWmsGQkfZxXCkEFN7TwLfIyVlT5RimT91Pj/qXw=="],
|
||||
|
||||
"react-native-update": ["react-native-update@10.34.4", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-yuXlff7EMUDyp1js2NylOw9jT0sVXoc5rpaRhzoYYcwfQTQq1Qp53qpyupDuUj43MEv5ikfJ6xBd/iRpXuanNg=="],
|
||||
"react-native-update": ["react-native-update@10.35.6", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-2k16I1QdI4wVbepaXjf+Ej9vSpnL7hpzTknitK0s4dI+hVah+cKVntnIexW4DdIpyTk7abCLVJH4MUFGjlaUSQ=="],
|
||||
|
||||
"react-native-url-polyfill": ["react-native-url-polyfill@2.0.0", "", { "dependencies": { "whatwg-url-without-unicode": "8.0.0-3" }, "peerDependencies": { "react-native": "*" } }, "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA=="],
|
||||
|
||||
|
||||
@@ -1835,7 +1835,7 @@ PODS:
|
||||
- ReactCommon/turbomodule/core
|
||||
- SocketRocket
|
||||
- Yoga
|
||||
- react-native-update (10.34.4):
|
||||
- react-native-update (10.35.6):
|
||||
- boost
|
||||
- DoubleConversion
|
||||
- fast_float
|
||||
@@ -1854,7 +1854,7 @@ PODS:
|
||||
- React-graphics
|
||||
- React-ImageManager
|
||||
- React-jsi
|
||||
- react-native-update/RCTPushy (= 10.34.4)
|
||||
- react-native-update/RCTPushy (= 10.35.6)
|
||||
- React-NativeModulesApple
|
||||
- React-RCTFabric
|
||||
- React-renderercss
|
||||
@@ -1866,7 +1866,7 @@ PODS:
|
||||
- SocketRocket
|
||||
- SSZipArchive
|
||||
- Yoga
|
||||
- react-native-update/RCTPushy (10.34.4):
|
||||
- react-native-update/RCTPushy (10.35.6):
|
||||
- boost
|
||||
- DoubleConversion
|
||||
- fast_float
|
||||
@@ -2800,7 +2800,7 @@ SPEC CHECKSUMS:
|
||||
React-Mapbuffer: 9d2434a42701d6144ca18f0ca1c4507808ca7696
|
||||
React-microtasksnativemodule: 75b6604b667d297292345302cc5bfb6b6aeccc1b
|
||||
react-native-safe-area-context: c6e2edd1c1da07bdce287fa9d9e60c5f7b514616
|
||||
react-native-update: 822780a6d3c8482d47ba50b5801ed295c0dfcaff
|
||||
react-native-update: 5e2274c66e654b001fae360600f5a9314c1c67e1
|
||||
React-NativeModulesApple: 879fbdc5dcff7136abceb7880fe8a2022a1bd7c3
|
||||
React-oscompat: 93b5535ea7f7dff46aaee4f78309a70979bdde9d
|
||||
React-perflogger: 5536d2df3d18fe0920263466f7b46a56351c0510
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"react-native-paper": "^5.14.5",
|
||||
"react-native-safe-area-context": "^5.6.1",
|
||||
"react-native-svg": "^15.13.0",
|
||||
"react-native-update": "^10.34.4",
|
||||
"react-native-update": "^10.35.6",
|
||||
"react-native-vector-icons": "^10.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
27
README.md
27
README.md
@@ -19,6 +19,33 @@
|
||||
7. meta 信息及开放 API,提供更高扩展性。
|
||||
8. 提供付费的专人技术支持。
|
||||
|
||||
### 与其他热更新库对比
|
||||
|
||||
| 对比维度 | react-native-update | expo-update | react-native-code-push |
|
||||
|---------|---------------------|-------------|------------------------|
|
||||
| **价格/成本** | 提供免费额度,多级梯度付费(最低约 66 元/月),流量不单独计费 | 提供免费额度,多级梯度付费(最低约 136 元/月),超出流量额外计费 | ❌ **已停运**(Microsoft App Center 已于 2025 年 3 月 31 日停止服务) |
|
||||
| **更新包大小** | ⭐⭐⭐⭐⭐ 几十 KB(增量更新) | ⭐⭐⭐ 全量更新(通常几十 MB) | ❌ **已停运** |
|
||||
| **中国地区访问速度** | ⭐⭐⭐⭐⭐ 阿里云 CDN,速度极快 | ⭐⭐ 国外服务器,可能较慢 | ❌ **已停运** |
|
||||
| **iOS 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **Android 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **鸿蒙支持** | ✅ 支持 | ❌ 不支持 | ❌ **已停运** |
|
||||
| **Expo 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **RN 版本支持** | ⭐⭐⭐⭐⭐ 第一时间支持最新版本 | ⭐⭐⭐⭐ 跟随 Expo SDK | ❌ **已停运** |
|
||||
| **新架构支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **Hermes 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **崩溃回滚** | ✅ 自动回滚机制 | ✅ 支持 | ❌ **已停运** |
|
||||
| **管理界面** | ✅ 命令行工具 + Web 管理界面 | ✅ Expo Dashboard | ❌ **已停运** |
|
||||
| **CI/CD 集成** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **API 扩展性** | ✅ Meta 信息 + 开放 API | ⚠️ 有限 | ❌ **已停运** |
|
||||
| **中文文档/支持** | ⭐⭐⭐⭐⭐ 完整中文文档,中文社区支持 | ⭐⭐ 英文为主 | ❌ **已停运** |
|
||||
| **技术支持** | ✅ 付费专人技术支持 | ⚠️ 社区支持 | ❌ **已停运** |
|
||||
| **服务器部署** | ✅ 可托管也可付费私有部署 | ✅ Expo 托管(EAS Update) | ❌ **已停运** |
|
||||
| **更新策略** | 灵活配置(静默/提示/立即/延迟) | 相对固定 | ❌ **已停运** |
|
||||
| **流量消耗** | ⭐⭐⭐⭐⭐ 极低(增量更新) | ⭐⭐⭐ 较高(全量更新) | ❌ **已停运** |
|
||||
| **更新成功率** | ⭐⭐⭐⭐⭐ 极高(国内 CDN 优势) | ⭐⭐⭐ 中等 | ❌ **已停运** |
|
||||
|
||||
|
||||
|
||||
### 本地开发
|
||||
|
||||
```
|
||||
|
||||
@@ -22,6 +22,10 @@ public class UpdateContext {
|
||||
public static boolean DEBUG = false;
|
||||
private static ReactInstanceManager mReactInstanceManager;
|
||||
private static boolean isUsingBundleUrl = false;
|
||||
|
||||
// Singleton instance
|
||||
private static UpdateContext sInstance;
|
||||
private static final Object sLock = new Object();
|
||||
|
||||
public UpdateContext(Context context) {
|
||||
this.context = context;
|
||||
@@ -54,13 +58,17 @@ public class UpdateContext {
|
||||
boolean buildTimeChanged = !buildTime.equals(storedBuildTime);
|
||||
|
||||
if (packageVersionChanged || buildTimeChanged) {
|
||||
// Execute cleanUp before clearing SharedPreferences to avoid race condition
|
||||
this.cleanUp();
|
||||
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
editor.putString("packageVersion", packageVersion);
|
||||
editor.putString("buildTime", buildTime);
|
||||
editor.apply();
|
||||
|
||||
this.cleanUp();
|
||||
// Use commit() instead of apply() to ensure synchronous write completion
|
||||
// This prevents race condition where getBundleUrl() might read null values
|
||||
// if called before apply() completes
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,12 +235,26 @@ public class UpdateContext {
|
||||
return mReactInstanceManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get singleton instance of UpdateContext
|
||||
*/
|
||||
public static UpdateContext getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
synchronized (sLock) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new UpdateContext(context.getApplicationContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public static String getBundleUrl(Context context) {
|
||||
return new UpdateContext(context.getApplicationContext()).getBundleUrl();
|
||||
return getInstance(context).getBundleUrl();
|
||||
}
|
||||
|
||||
public static String getBundleUrl(Context context, String defaultAssetsUrl) {
|
||||
return new UpdateContext(context.getApplicationContext()).getBundleUrl(defaultAssetsUrl);
|
||||
return getInstance(context).getBundleUrl(defaultAssetsUrl);
|
||||
}
|
||||
|
||||
public String getBundleUrl() {
|
||||
@@ -273,6 +295,7 @@ public class UpdateContext {
|
||||
if (lastVersion == null) {
|
||||
editor.remove("currentVersion");
|
||||
} else {
|
||||
editor.remove("lastVersion");
|
||||
editor.putString("currentVersion", lastVersion);
|
||||
}
|
||||
editor.putBoolean("firstTimeOk", true);
|
||||
|
||||
@@ -27,7 +27,7 @@ public class UpdateModule extends NativePushySpec {
|
||||
}
|
||||
|
||||
public UpdateModule(ReactApplicationContext reactContext) {
|
||||
this(reactContext, new UpdateContext(reactContext.getApplicationContext()));
|
||||
this(reactContext, UpdateContext.getInstance(reactContext));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
|
||||
public UpdateModule(ReactApplicationContext reactContext) {
|
||||
this(reactContext, new UpdateContext(reactContext.getApplicationContext()));
|
||||
this(reactContext, UpdateContext.getInstance(reactContext));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
39
harmony/pushy/hvigor-plugin.ts
Normal file
39
harmony/pushy/hvigor-plugin.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export function reactNativeUpdatePlugin() {
|
||||
return {
|
||||
pluginId: 'reactNativeUpdatePlugin',
|
||||
apply(node) {
|
||||
node.registerTask({
|
||||
name: 'reactNativeUpdatePlugin',
|
||||
run: () => {
|
||||
const cwd = process.cwd();
|
||||
const metaFilePath = path.resolve(
|
||||
cwd,
|
||||
'entry/src/main/resources/rawfile/meta.json',
|
||||
);
|
||||
fs.mkdirSync(path.dirname(metaFilePath), { recursive: true });
|
||||
|
||||
const moduleJsonPath = path.resolve(cwd, 'AppScope/app.json5');
|
||||
let versionName = '';
|
||||
if (fs.existsSync(moduleJsonPath)) {
|
||||
const content = fs.readFileSync(moduleJsonPath, 'utf-8');
|
||||
const match = content.match(
|
||||
/(?:"versionName"|versionName):\s*["']([^"']+)["']/,
|
||||
);
|
||||
versionName = match?.[1] || '';
|
||||
}
|
||||
|
||||
const metaContent = {
|
||||
pushy_build_time: new Date().toISOString(),
|
||||
versionName,
|
||||
};
|
||||
|
||||
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 2));
|
||||
console.log(`Build time written to ${metaFilePath}`);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -6,14 +6,14 @@
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38"
|
||||
"@rnoh/react-native-openharmony@^0.72.96": "@rnoh/react-native-openharmony@0.72.96"
|
||||
},
|
||||
"packages": {
|
||||
"@rnoh/react-native-openharmony@0.72.38": {
|
||||
"@rnoh/react-native-openharmony@0.72.96": {
|
||||
"name": "",
|
||||
"version": "0.72.38",
|
||||
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
|
||||
"version": "0.72.96",
|
||||
"integrity": "sha512-gBbm8LLyqi5UE7qHWdZYeQnjyncfEpCczKZUP/9M2U1Z7exR0Kya8PMKMwr1ta5ujy7w/hZVC2LomEV4QvBeqA==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.96.har",
|
||||
"registryType": "ohpm"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"license": "MIT",
|
||||
"types": "",
|
||||
"devDependencies": {},
|
||||
"name": "pushy",
|
||||
"description": "",
|
||||
"main": "index.ets",
|
||||
"version": "3.1.0-0.0.7",
|
||||
"dependencies": {
|
||||
"@rnoh/react-native-openharmony":"^0.72.38"
|
||||
license: 'MIT',
|
||||
types: '',
|
||||
devDependencies: {},
|
||||
name: 'pushy',
|
||||
description: '',
|
||||
main: 'index.ets',
|
||||
version: '10.35.1',
|
||||
dependencies: {
|
||||
'@rnoh/react-native-openharmony': '^0.72.96',
|
||||
},
|
||||
"modelVersion": "5.0.0"
|
||||
modelVersion: '5.0.0',
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import http from '@ohos.net.http';
|
||||
import fileIo from '@ohos.file.fs';
|
||||
import util from '@ohos.util';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { buffer } from '@kit.ArkTS';
|
||||
import zip from '@ohos.zlib';
|
||||
import { zlib } from '@kit.BasicServicesKit';
|
||||
import { EventHub } from './EventHub';
|
||||
import { DownloadTaskParams } from './DownloadTaskParams';
|
||||
import Pushy from 'librnupdate.so';
|
||||
@@ -37,7 +34,9 @@ export class DownloadTask {
|
||||
if (stat.isDirectory()) {
|
||||
const files = await fileIo.listFile(path);
|
||||
for (const file of files) {
|
||||
if (file === '.' || file === '..') continue;
|
||||
if (file === '.' || file === '..') {
|
||||
continue;
|
||||
}
|
||||
await this.removeDirectory(`${path}/${file}`);
|
||||
}
|
||||
await fileIo.rmdir(path);
|
||||
@@ -128,64 +127,12 @@ export class DownloadTask {
|
||||
});
|
||||
}
|
||||
|
||||
private async copyFile(from: string, to: string): Promise<void> {
|
||||
let reader;
|
||||
let writer;
|
||||
try {
|
||||
reader = fileIo.openSync(from, fileIo.OpenMode.READ_ONLY);
|
||||
writer = fileIo.openSync(
|
||||
to,
|
||||
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
|
||||
);
|
||||
const arrayBuffer = new ArrayBuffer(4096);
|
||||
let bytesRead: number;
|
||||
do {
|
||||
bytesRead = await fileIo
|
||||
.read(reader.fd, arrayBuffer)
|
||||
.catch((err: BusinessError) => {
|
||||
throw Error(
|
||||
`Error reading file: ${err.message}, code: ${err.code}`,
|
||||
);
|
||||
});
|
||||
if (bytesRead > 0) {
|
||||
const buf = buffer.from(arrayBuffer, 0, bytesRead);
|
||||
await fileIo
|
||||
.write(writer.fd, buf.buffer, {
|
||||
offset: 0,
|
||||
length: bytesRead,
|
||||
})
|
||||
.catch((err: BusinessError) => {
|
||||
throw Error(
|
||||
`Error writing file: ${err.message}, code: ${err.code}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
} while (bytesRead > 0);
|
||||
console.info('File copied successfully');
|
||||
} catch (error) {
|
||||
console.error('Copy file failed:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
if (reader !== undefined) {
|
||||
fileIo.closeSync(reader);
|
||||
}
|
||||
if (writer !== undefined) {
|
||||
fileIo.closeSync(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async doFullPatch(params: DownloadTaskParams): Promise<void> {
|
||||
await this.downloadFile(params);
|
||||
await this.removeDirectory(params.unzipDirectory);
|
||||
await fileIo.mkdir(params.unzipDirectory);
|
||||
|
||||
try {
|
||||
await zip.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
} catch (error) {
|
||||
console.error('Unzip failed:', error);
|
||||
throw error;
|
||||
}
|
||||
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
}
|
||||
|
||||
private async processUnzippedFiles(directory: string): Promise<ZipFile> {
|
||||
@@ -193,7 +140,9 @@ export class DownloadTask {
|
||||
try {
|
||||
const files = await fileIo.listFile(directory);
|
||||
for (const file of files) {
|
||||
if (file === '.' || file === '..') continue;
|
||||
if (file === '.' || file === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const filePath = `${directory}/${file}`;
|
||||
const stat = await fileIo.stat(filePath);
|
||||
@@ -230,7 +179,7 @@ export class DownloadTask {
|
||||
let foundDiff = false;
|
||||
let foundBundlePatch = false;
|
||||
const copyList: Map<string, Array<any>> = new Map();
|
||||
await zip.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
|
||||
for (const entry of zipFile.entries) {
|
||||
const fn = entry.filename;
|
||||
@@ -246,7 +195,7 @@ export class DownloadTask {
|
||||
|
||||
const copies = obj.copies;
|
||||
for (const to in copies) {
|
||||
let from = copies[to];
|
||||
let from = copies[to].replace('resources/rawfile/', '');
|
||||
if (from === '') {
|
||||
from = to;
|
||||
}
|
||||
@@ -295,10 +244,6 @@ export class DownloadTask {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (fn !== '.DS_Store') {
|
||||
await zip.decompressFile(fn, params.unzipDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundDiff) {
|
||||
@@ -317,14 +262,20 @@ export class DownloadTask {
|
||||
|
||||
let foundDiff = false;
|
||||
let foundBundlePatch = false;
|
||||
const copyList: Map<string, Array<any>> = new Map();
|
||||
await zip.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
|
||||
for (const entry of zipFile.entries) {
|
||||
const fn = entry.filename;
|
||||
|
||||
if (fn === '__diff.json') {
|
||||
foundDiff = true;
|
||||
|
||||
await fileIo
|
||||
.copyDir(params.originDirectory + '/', params.unzipDirectory + '/')
|
||||
.catch(error => {
|
||||
console.error('copy error:', error);
|
||||
});
|
||||
|
||||
let jsonContent = '';
|
||||
const bufferArray = new Uint8Array(entry.content);
|
||||
for (let i = 0; i < bufferArray.length; i++) {
|
||||
@@ -332,22 +283,23 @@ export class DownloadTask {
|
||||
}
|
||||
const obj = JSON.parse(jsonContent);
|
||||
|
||||
const copies = obj.copies;
|
||||
for (const to in copies) {
|
||||
let from = copies[to];
|
||||
if (from === '') {
|
||||
from = to;
|
||||
}
|
||||
|
||||
if (!copyList.has(from)) {
|
||||
copyList.set(from, []);
|
||||
}
|
||||
|
||||
const target = copyList.get(from);
|
||||
if (target) {
|
||||
const toFile = `${params.unzipDirectory}/${to}`;
|
||||
target.push(toFile);
|
||||
}
|
||||
const { copies, deletes } = obj;
|
||||
for (const [to, from] of Object.entries(copies)) {
|
||||
await fileIo
|
||||
.copyFile(
|
||||
`${params.originDirectory}/${from}`,
|
||||
`${params.unzipDirectory}/${to}`,
|
||||
)
|
||||
.catch(error => {
|
||||
console.error('copy error:', error);
|
||||
});
|
||||
}
|
||||
for (const fileToDelete of Object.keys(deletes)) {
|
||||
await fileIo
|
||||
.unlink(`${params.unzipDirectory}/${fileToDelete}`)
|
||||
.catch(error => {
|
||||
console.error('delete error:', error);
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -389,8 +341,6 @@ export class DownloadTask {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await zip.decompressFile(entry.filename, params.unzipDirectory);
|
||||
}
|
||||
|
||||
if (!foundDiff) {
|
||||
@@ -406,27 +356,14 @@ export class DownloadTask {
|
||||
copyList: Map<string, Array<string>>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const bundlePath = this.context.bundleCodeDir;
|
||||
const resourceManager = this.context.resourceManager;
|
||||
|
||||
const files = await fileIo.listFile(bundlePath);
|
||||
for (const file of files) {
|
||||
if (file === '.' || file === '..') continue;
|
||||
|
||||
const targets = copyList.get(file);
|
||||
if (targets) {
|
||||
let lastTarget: string | undefined;
|
||||
|
||||
for (const target of targets) {
|
||||
console.info(`Copying from resource ${file} to ${target}`);
|
||||
|
||||
if (lastTarget) {
|
||||
await this.copyFile(lastTarget, target);
|
||||
} else {
|
||||
const sourcePath = `${bundlePath}/${file}`;
|
||||
await this.copyFile(sourcePath, target);
|
||||
lastTarget = target;
|
||||
}
|
||||
}
|
||||
for (const [from, targets] of copyList.entries()) {
|
||||
const fromContent = await resourceManager.getRawFileContent(from);
|
||||
for (const target of targets) {
|
||||
const fileStream = fileIo.createStreamSync(target, 'w+');
|
||||
fileStream.writeSync(fromContent.buffer);
|
||||
fileStream.close();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -443,7 +380,9 @@ export class DownloadTask {
|
||||
try {
|
||||
const files = await fileIo.listFile(params.unzipDirectory);
|
||||
for (const file of files) {
|
||||
if (file.startsWith('.')) continue;
|
||||
if (file.startsWith('.')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const filePath = `${params.unzipDirectory}/${file}`;
|
||||
const stat = await fileIo.stat(filePath);
|
||||
|
||||
@@ -23,14 +23,17 @@ export class PushyFileJSBundleProvider extends JSBundleProvider {
|
||||
}
|
||||
|
||||
async getBundle(): Promise<FileJSBundle> {
|
||||
if (!this.path) {
|
||||
throw new JSBundleProviderError({
|
||||
whatHappened: 'No pushy bundle found. using default bundle',
|
||||
howCanItBeFixed: ['']
|
||||
})
|
||||
}
|
||||
try {
|
||||
const status = await fs.access(this.path, fs.OpenMode.READ_ONLY);
|
||||
if (status) {
|
||||
return {
|
||||
filePath: this.path
|
||||
}
|
||||
await fs.access(this.path, fs.OpenMode.READ_ONLY);
|
||||
return {
|
||||
filePath: this.path
|
||||
}
|
||||
throw new Error('Update bundle not found');
|
||||
} catch (error) {
|
||||
throw new JSBundleProviderError({
|
||||
whatHappened: `Couldn't load JSBundle from ${this.path}`,
|
||||
|
||||
@@ -37,10 +37,10 @@ export class UpdateContext {
|
||||
this.preferences.putSync('packageVersion', packageVersion);
|
||||
this.preferences.flush();
|
||||
} else if (storedVersion && packageVersion !== storedVersion) {
|
||||
this.cleanUp();
|
||||
this.preferences.clear();
|
||||
this.preferences.putSync('packageVersion', packageVersion);
|
||||
this.preferences.flush();
|
||||
this.cleanUp();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to init preferences:', e);
|
||||
@@ -189,18 +189,11 @@ export class UpdateContext {
|
||||
}
|
||||
}
|
||||
|
||||
public static getBundleUrl(
|
||||
context: common.UIAbilityContext,
|
||||
defaultAssetsUrl?: string,
|
||||
) {
|
||||
return new UpdateContext(context).getBundleUrl(defaultAssetsUrl);
|
||||
}
|
||||
|
||||
public getBundleUrl(defaultAssetsUrl?: string) {
|
||||
public getBundleUrl() {
|
||||
UpdateContext.isUsingBundleUrl = true;
|
||||
const currentVersion = this.getCurrentVersion();
|
||||
if (!currentVersion) {
|
||||
return defaultAssetsUrl;
|
||||
return '';
|
||||
}
|
||||
if (!this.isFirstTime()) {
|
||||
if (!this.preferences.getSync('firstTimeOk', true)) {
|
||||
@@ -222,7 +215,7 @@ export class UpdateContext {
|
||||
version = this.rollBack();
|
||||
}
|
||||
}
|
||||
return defaultAssetsUrl;
|
||||
return '';
|
||||
}
|
||||
|
||||
getPackageVersion(): string {
|
||||
@@ -252,6 +245,7 @@ export class UpdateContext {
|
||||
if (!lastVersion) {
|
||||
this.preferences.deleteSync('currentVersion');
|
||||
} else {
|
||||
this.preferences.deleteSync('lastVersion');
|
||||
this.preferences.putSync('currentVersion', lastVersion);
|
||||
}
|
||||
this.preferences.putSync('firstTimeOk', true);
|
||||
|
||||
@@ -78,7 +78,7 @@ RCT_EXPORT_MODULE(RCTPushy);
|
||||
NSString *storedBuildTime = [defaults stringForKey:paramBuildTime];
|
||||
|
||||
// If stored versions don't exist, write current versions first
|
||||
if (!storedPackageVersion || !storedBuildTime) {
|
||||
if (!storedPackageVersion && !storedBuildTime) {
|
||||
[defaults setObject:curPackageVersion forKey:paramPackageVersion];
|
||||
[defaults setObject:curBuildTime forKey:paramBuildTime];
|
||||
storedPackageVersion = curPackageVersion;
|
||||
@@ -86,7 +86,7 @@ RCT_EXPORT_MODULE(RCTPushy);
|
||||
}
|
||||
|
||||
BOOL packageVersionChanged = ![curPackageVersion isEqualToString:storedPackageVersion];
|
||||
BOOL buildTimeChanged = ![curBuildTime isEqualToString:storedBuildTime];
|
||||
BOOL buildTimeChanged = curBuildTime && ![curBuildTime isEqualToString:storedBuildTime];
|
||||
|
||||
if (packageVersionChanged || buildTimeChanged) {
|
||||
// Clear all update data and store new versions
|
||||
@@ -304,8 +304,8 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options
|
||||
if (hash.length) {
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSString *lastVersion = nil;
|
||||
if ([defaults objectForKey:keyPushyInfo]) {
|
||||
NSDictionary *pushyInfo = [defaults objectForKey:keyPushyInfo];
|
||||
NSDictionary *pushyInfo = [defaults objectForKey:keyPushyInfo];
|
||||
if (pushyInfo) {
|
||||
lastVersion = pushyInfo[paramCurrentVersion];
|
||||
}
|
||||
|
||||
@@ -679,4 +679,4 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
@end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.35.0",
|
||||
"version": "10.35.8",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createContext, useContext } from 'react';
|
||||
import { CheckResult, ProgressData } from './type';
|
||||
import { Pushy, Cresc } from './client';
|
||||
import i18n from './i18n';
|
||||
|
||||
const noop = () => {};
|
||||
const asyncNoop = () => Promise.resolve();
|
||||
@@ -50,7 +51,16 @@ export const UpdateContext = createContext<{
|
||||
lastError?: Error;
|
||||
}>(defaultContext);
|
||||
|
||||
export const useUpdate = () => useContext(UpdateContext);
|
||||
export const useUpdate = __DEV__ ? () => {
|
||||
const context = useContext(UpdateContext);
|
||||
|
||||
// 检查是否在 UpdateProvider 内部使用
|
||||
if (!context.client) {
|
||||
throw new Error(i18n.t('error_use_update_outside_provider'));
|
||||
}
|
||||
|
||||
return context;
|
||||
} : () => useContext(UpdateContext);
|
||||
|
||||
/** @deprecated Please use `useUpdate` instead */
|
||||
export const usePushy = useUpdate;
|
||||
|
||||
@@ -71,4 +71,8 @@ export default {
|
||||
// Development environment messages
|
||||
dev_incremental_update_disabled:
|
||||
'Currently in development environment, incremental hot update cannot be executed and restart will not take effect. If you need to test effective full hot update in development environment (but will reconnect to metro after restart), please enable "ignore timestamp" switch and retry.',
|
||||
|
||||
// Context error messages
|
||||
error_use_update_outside_provider:
|
||||
'useUpdate must be used within an UpdateProvider. Please wrap your component tree with <UpdateProvider client={...}>.',
|
||||
};
|
||||
|
||||
@@ -68,4 +68,8 @@ export default {
|
||||
// Development environment messages
|
||||
dev_incremental_update_disabled:
|
||||
'当前是开发环境,无法执行增量式热更新,重启不会生效。如果需要在开发环境中测试可生效的全量热更新(但也会在再次重启后重新连接 metro),请打开"忽略时间戳"开关再重试。',
|
||||
|
||||
// Context error messages
|
||||
error_use_update_outside_provider:
|
||||
'useUpdate 必须在 UpdateProvider 内部使用。请使用 <UpdateProvider client={...}> 包裹您的组件树。',
|
||||
};
|
||||
|
||||
@@ -13,7 +13,12 @@ import {
|
||||
Linking,
|
||||
} from 'react-native';
|
||||
import { Pushy, Cresc, sharedState } from './client';
|
||||
import { currentVersion, packageVersion, getCurrentVersionInfo, currentVersionInfo } from './core';
|
||||
import {
|
||||
currentVersion,
|
||||
packageVersion,
|
||||
getCurrentVersionInfo,
|
||||
currentVersionInfo,
|
||||
} from './core';
|
||||
import {
|
||||
CheckResult,
|
||||
ProgressData,
|
||||
@@ -165,7 +170,7 @@ export const UpdateProvider = ({
|
||||
lastChecking.current = now;
|
||||
let rootInfo: CheckResult | undefined;
|
||||
try {
|
||||
rootInfo = await client.checkUpdate(extra);
|
||||
rootInfo = { ...(await client.checkUpdate(extra)) };
|
||||
} catch (e: any) {
|
||||
setLastError(e);
|
||||
alertError(client.t('error_update_check_failed'), e.message);
|
||||
@@ -175,7 +180,9 @@ export const UpdateProvider = ({
|
||||
if (!rootInfo) {
|
||||
return;
|
||||
}
|
||||
const versions = [rootInfo.expVersion, rootInfo].filter(Boolean) as VersionInfo[];
|
||||
const versions = [rootInfo.expVersion, rootInfo].filter(
|
||||
Boolean,
|
||||
) as VersionInfo[];
|
||||
delete rootInfo.expVersion;
|
||||
for (const versionInfo of versions) {
|
||||
const info: CheckResult = {
|
||||
|
||||
Reference in New Issue
Block a user