1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-18 00:26:11 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Compare commits

..

14 Commits

Author SHA1 Message Date
sunnylqm
dba4a98fd0 v6.0.5 2021-06-24 15:13:35 +08:00
sunnylqm
d4d12e1889 Fix until int conversion 2021-06-24 15:13:03 +08:00
sunnylqm
daf870fd75 v6.0.4 2021-06-19 14:38:51 +08:00
sunnylqm
33641fcbef Try pdiff if diff error 2021-06-19 13:01:07 +08:00
sunnylqm
a02ca4fa71 Update npmignore 2021-06-18 09:20:10 +08:00
sunnylqm
c5a2a10f9d v6.0.3 2021-06-17 17:17:30 +08:00
sunnylqm
da7e9c6498 Add a delay after download 2021-06-17 17:16:51 +08:00
sunnylqm
30425db7b2 Add x86 abi to example 2021-05-18 12:23:50 +08:00
sunnylqm
61077bbc38 Fix install apk under android 7 2021-05-18 12:23:33 +08:00
Sunny Luo
29648ff56f Update README.md 2021-05-10 14:47:43 +08:00
sunnylqm
9080c5f325 v6.0.1 2021-05-10 14:39:18 +08:00
sunnylqm
58c2248686 v6.0.0 2021-05-04 21:18:15 +08:00
sunnylqm
cb736d7ec5 Update example setting 2021-05-04 20:56:12 +08:00
Sunny Luo
f82be5a68c Merge pull request #371 from reactnativecn/hdp-dev
Adopt hdiffpatch
2021-05-04 20:47:32 +08:00
9 changed files with 61 additions and 19 deletions

View File

@@ -36,6 +36,8 @@ project.xcworkspace
.idea
.gradle
local.properties
android/build
android/obj
# node.js
#
@@ -43,7 +45,6 @@ node_modules/
npm-debug.log
Example
yarn.lock
android/jni
domains.json
endpoints.json

View File

@@ -57,3 +57,6 @@ buck-out/
# CocoaPods
/ios/Pods/
.pushy

View File

@@ -139,9 +139,9 @@ android {
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
enable true
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
include "x86", "arm64-v8a"
}
}
signingConfigs {

View File

@@ -8,11 +8,12 @@
### 优势
1. 命令行工具&网页双端管理,版本发布过程简单便捷,完全可以集成 CI
1. 基于阿里云高速 CDN 分发,对比其他在服务器在国外的热更新服务,分发更稳定,更新成功率极高
2. 基于 bsdiff/hdiff 算法创建的**超小更新包**,通常版本迭代后在 1-10KB 之间,避免数百 KB 的流量消耗。
3. 支持崩溃回滚,安全可靠
4. meta 信息及开放 API提供更高扩展性
5. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新
3. 跨越多个版本进行更新时,只需要下载**一个更新包**,不需要逐版本依次更新
4. 命令行工具&网页双端管理,版本发布过程简单便捷,完全可以集成 CI
5. 支持崩溃回滚,安全可靠
6. meta 信息及开放 API提供更高扩展性。
### 本地开发

View File

@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.reactnative.modules.update">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application>
<meta-data android:name="pushy_build_time" android:value="@string/pushy_build_time" />
<provider

View File

@@ -4,7 +4,10 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
import com.facebook.react.ReactInstanceManager;
import java.util.HashMap;
@@ -13,7 +16,6 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.io.File;
import java.net.URL;
/**
* Created by tdzl2003 on 3/31/16.
@@ -107,7 +109,14 @@ public class UpdateContext {
params.url = url;
params.hash = hash;
params.listener = listener;
params.targetFile = new File(rootDir, fileName);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N && fileName.equals("update.apk")) {
params.targetFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "pushy_update.apk");
} else {
params.targetFile = new File(rootDir, fileName);
}
// params.unzipDirectory = new File(rootDir, hash);
new DownloadTask(context).executeOnExecutor(this.executor, params);
}

View File

@@ -125,14 +125,13 @@ public class UpdateModule extends ReactContextBaseJavaModule {
intent.setData(apkUri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
} else {
apkUri = Uri.fromFile(toInstall);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
mContext.startActivity(intent);
}
@ReactMethod

View File

@@ -3,7 +3,12 @@ import {
getCheckUrl,
setCustomEndpoints,
} from './endpoint';
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
import {
NativeEventEmitter,
NativeModules,
Platform,
PermissionsAndroid,
} from 'react-native';
export { setCustomEndpoints };
const {
version: v,
@@ -133,7 +138,7 @@ function checkOperation(op) {
if (action.type === 'block') {
blockUpdate = {
reason: action.reason,
until: (Date.now() + action.duration) / 1000,
until: Math.round((Date.now() + action.duration) / 1000),
};
Pushy.setBlockUpdate(blockUpdate);
}
@@ -161,11 +166,20 @@ export async function downloadUpdate(options, eventListeners) {
}
if (options.diffUrl) {
logger('downloading diff');
await Pushy.downloadPatchFromPpk({
updateUrl: options.diffUrl,
hash: options.hash,
originHash: currentVersion,
});
try {
await Pushy.downloadPatchFromPpk({
updateUrl: options.diffUrl,
hash: options.hash,
originHash: currentVersion,
});
} catch (e) {
logger(e.message);
logger('diff error, try pdiff');
await Pushy.downloadPatchFromPackage({
updateUrl: options.pdiffUrl,
hash: options.hash,
});
}
} else if (options.pdiffUrl) {
logger('downloading pdiff');
await Pushy.downloadPatchFromPackage({
@@ -174,6 +188,7 @@ export async function downloadUpdate(options, eventListeners) {
});
}
progressHandler && progressHandler.remove();
await new Promise((resolve) => setTimeout(resolve, 100));
return options.hash;
}
@@ -197,6 +212,18 @@ export function markSuccess() {
export async function downloadAndInstallApk({ url, onDownloadProgress }) {
logger('downloadAndInstallApk');
if (Platform.OS === 'android' && Platform.Version <= 23) {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
return;
}
} catch (err) {
console.warn(err);
}
}
let hash = Date.now().toString();
let progressHandler;
if (onDownloadProgress) {

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "6.0.0-beta0",
"version": "6.0.5",
"description": "react-native hot update",
"main": "lib/index.js",
"scripts": {