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

Compare commits

...

19 Commits

Author SHA1 Message Date
sunnylqm
80e0451983 v10.3.1 2024-03-21 22:11:38 +08:00
sunnylqm
b512ae18b7 do not show alert if no downloadurl 2024-03-21 22:11:09 +08:00
sunnylqm
fe75a2ca9e Remove blockUpdate method from UpdateContext and UpdateModule 2024-03-21 13:03:32 +08:00
sunnylqm
d84ad103fb v10.3.0 2024-03-20 21:50:18 +08:00
sunnylqm
208034fa7d fix module name 2024-03-20 21:49:44 +08:00
sunnylqm
c6430a9ed4 v10.2.9 2024-03-20 21:48:31 +08:00
sunnylqm
f2aec36705 remove blockupdate 2024-03-20 21:47:44 +08:00
sunnylqm
71e5b947d3 v10.2.8 2024-03-20 21:43:13 +08:00
sunnylqm
5dc8d8defc fix module name 2024-03-20 21:42:44 +08:00
sunnylqm
30687dddf2 v10.2.7 2024-03-20 21:38:51 +08:00
sunnylqm
57ddcc7758 fix codegenconfig 2024-03-20 21:37:59 +08:00
sunnylqm
a93bbe553d v10.3.0-beta.0 2024-03-20 20:54:48 +08:00
sunnylqm
356050d839 Add NativePushy module to the project 2024-03-20 20:42:31 +08:00
sunnylqm
5df3cb65b3 Merge branch 'master' of github.com:reactnativecn/react-native-pushy 2024-03-20 10:16:11 +08:00
sunnylqm
699eb0ea05 Update jsSrcsDir in package.json 2024-03-20 10:15:49 +08:00
Sunny Luo
36c4ff085c Create tea.yaml 2024-03-10 20:39:13 +08:00
sunnylqm
8c13dd69b1 v10.2.6 2024-03-08 16:05:08 +08:00
sunnylqm
2df04cb377 fix a wrong dep 2024-03-08 16:04:16 +08:00
sunnylqm
e39d4fa370 v10.2.5 2024-03-08 11:27:31 +08:00
15 changed files with 108 additions and 170 deletions

View File

@@ -47,4 +47,6 @@ Example
yarn.lock
domains.json
endpoints.json
endpoints.json
tea.yaml

View File

@@ -28,14 +28,7 @@ describe('测试Native模块的方法', () => {
await element(by.id('done')).longPress();
await expect(element(by.id('done'))).toBeNotVisible();
});
it('setBlockUpdate', async () => {
await element(by.id('setBlockUpdate')).longPress();
await element(by.id('submit')).longPress();
await expect(element(by.text('done'))).toBeVisible();
await element(by.id('done')).longPress();
await expect(element(by.id('done'))).toBeNotVisible();
});
if (device.getPlatform() === 'android') {
it('reloadUpdate', async () => {
await element(by.id('reloadUpdate')).longPress();

View File

@@ -18,7 +18,7 @@
"react-native": "0.69.8",
"react-native-paper": "^5.12.1",
"react-native-safe-area-context": "^4.8.2",
"react-native-update": "^10.0.2",
"react-native-update": "^10.2.6",
"react-native-vector-icons": "^10.0.3"
},
"devDependencies": {

View File

@@ -19,23 +19,25 @@ const UUID = '00000000-0000-0000-0000-000000000000';
const DownloadUrl =
'http://cos.pgyer.com/697913e94d7441f20c686e2b0996a1aa.apk?sign=7a8f11b1df82cba45c8ac30b1acec88c&t=1680404102&response-content-disposition=attachment%3Bfilename%3DtestHotupdate_1.0.apk';
const CustomDialog = ({title, visible, onConfirm}) => {
if (!visible) {
return null;
}
const CustomDialog = ({title, visible, onConfirm}) => {
if (!visible) {
return null;
}
return (
<View style={styles.overlay}>
<View style={styles.dialog}>
<Text style={styles.title}>{title}</Text>
<TouchableOpacity testID='done' style={styles.button} onLongPress={onConfirm}>
<Text style={styles.buttonText}>确认</Text>
</TouchableOpacity>
</View>
return (
<View style={styles.overlay}>
<View style={styles.dialog}>
<Text style={styles.title}>{title}</Text>
<TouchableOpacity
testID="done"
style={styles.button}
onLongPress={onConfirm}>
<Text style={styles.buttonText}>确认</Text>
</TouchableOpacity>
</View>
);
};
</View>
);
};
export default function TestConsole({visible}) {
const [text, setText] = useState('');
const [running, setRunning] = useState(false);
@@ -64,13 +66,6 @@ export default function TestConsole({visible}) {
setText(`setUuid\n${UUID}`);
},
},
{
name: 'setBlockUpdate',
invoke: () => {
setText('setBlockUpdate');
setOptions({reason: 'application has been block', until: 1673082950});
},
},
{
name: 'reloadUpdate',
invoke: () => {
@@ -132,9 +127,8 @@ export default function TestConsole({visible}) {
testID={NativeTestMethod[i].name}
onLongPress={() => {
NativeTestMethod[i].invoke();
}}
>
<Text>{NativeTestMethod[i].name}</Text>
}}>
<Text>{NativeTestMethod[i].name}</Text>
</TouchableOpacity>,
);
}
@@ -164,8 +158,14 @@ export default function TestConsole({visible}) {
/>
{running && <ActivityIndicator />}
<TouchableOpacity
style={{backgroundColor:'rgb(0,140,237)', justifyContent: 'center',
alignItems: 'center',paddingTop:10,paddingBottom:10,marginBottom:5}}
style={{
backgroundColor: 'rgb(0,140,237)',
justifyContent: 'center',
alignItems: 'center',
paddingTop: 10,
paddingBottom: 10,
marginBottom: 5,
}}
testID="submit"
onLongPress={async () => {
setRunning(true);
@@ -190,22 +190,23 @@ export default function TestConsole({visible}) {
}
setAlertVisible(true);
setAlertMsg('done');
} catch (e: any) {
} catch (e) {
setAlertVisible(true);
setAlertMsg(e.message);
}
setRunning(false);
}}
>
<Text style={{color:'white'}}>执行</Text>
}}>
<Text style={{color: 'white'}}>执行</Text>
</TouchableOpacity>
<Button title="重置" onPress={() => setText('')} />
{renderTestView()}
<CustomDialog
title={alertMsg}
visible={alertVisible}
onConfirm={()=>{setAlertVisible(false)}}
/>
<Button title="重置" onPress={() => setText('')} />
{renderTestView()}
<CustomDialog
title={alertMsg}
visible={alertVisible}
onConfirm={() => {
setAlertVisible(false);
}}
/>
</SafeAreaView>
</Modal>
);

View File

@@ -6231,10 +6231,10 @@ react-native-safe-area-context@^4.8.2:
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-4.8.2.tgz#e6b3d8acf3c6afcb4b5db03a97f9c37df7668f65"
integrity sha512-ffUOv8BJQ6RqO3nLml5gxJ6ab3EestPiyWekxdzO/1MQ7NF8fW1Mzh1C5QE9yq573Xefnc7FuzGXjtesZGv7cQ==
react-native-update@^10.0.2:
version "10.0.2"
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.0.2.tgz#2bb01ab6e41e72bbbb535cebd34083b1fed69eb0"
integrity sha512-XkEPmTC3X6FV1eXq6uDyjfhXpAaug0HI48Mm+PkbMlXcgFjTrOmtuq7yuvemS2nPG2pwnrYQuGs0A6tE2aoRBA==
react-native-update@^10.2.6:
version "10.2.6"
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.2.6.tgz#976c1d1b48ac3522677b5ecbfe3e64fa04df1839"
integrity sha512-x72ga106wEWsinHSN/ANk+YygvGq6hyTEVOCibakps7Wb+5JgTiMeE0p2+GOOPhuxMavEHiil5WdhYOipI3/Qg==
dependencies:
nanoid "^3.3.3"

View File

@@ -69,13 +69,6 @@ public class UpdateContext {
return context.getString(R.string.pushy_build_time);
}
public Map getBlockUpdate() {
return new HashMap<String, Object>() {{
put("until", sp.getInt("blockUntil", 0));
put("reason", sp.getString("blockReason", null));
}};
}
public boolean getIsUsingBundleUrl() {
return isUsingBundleUrl;
}
@@ -166,13 +159,6 @@ public class UpdateContext {
return sp.getString(key, null);
}
public void setBlockUpdate(int until, String reason) {
SharedPreferences.Editor editor = sp.edit();
editor.putInt("blockUntil", until);
editor.putString("blockReason", reason);
editor.apply();
}
public String getCurrentVersion() {
return sp.getString("currentVersion", null);
}

View File

@@ -192,23 +192,6 @@ public class UpdateModuleImpl {
}
}
public static void setBlockUpdate(UpdateContext updateContext, ReadableMap options,Promise promise) {
try {
final int until = options.getInt("until");
final String reason = options.getString("reason");
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
updateContext.setBlockUpdate(until, reason);
}
});
promise.resolve(true);
}catch (Exception e){
promise.reject("执行报错:"+e.getMessage());
}
}
public static void setUuid(UpdateContext updateContext, String uuid, Promise promise) {
try {
UiThreadUtil.runOnUiThread(new Runnable() {

View File

@@ -14,7 +14,7 @@ import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class UpdateModule extends NativeUpdateSpec {
public class UpdateModule extends NativePushySpec {
UpdateContext updateContext;
public static ReactApplicationContext mContext;
public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) {
@@ -45,7 +45,6 @@ public class UpdateModule extends NativeUpdateSpec {
if (rolledBackVersion != null) {
updateContext.clearRollbackMark();
}
constants.put("blockUpdate", updateContext.getBlockUpdate());
constants.put("uuid", updateContext.getKv("uuid"));
return constants;
}
@@ -108,11 +107,6 @@ public class UpdateModule extends NativeUpdateSpec {
UpdateModuleImpl.markSuccess(updateContext,promise);
}
@Override
public void setBlockUpdate(ReadableMap options,Promise promise) {
UpdateModuleImpl.setBlockUpdate(updateContext,options,promise);
}
@Override
public void setUuid(final String uuid, Promise promise) {
UpdateModuleImpl.setUuid(updateContext,uuid,promise);

View File

@@ -59,7 +59,6 @@ public class UpdateModule extends ReactContextBaseJavaModule {
if (rolledBackVersion != null) {
updateContext.clearRollbackMark();
}
constants.put("blockUpdate", updateContext.getBlockUpdate());
constants.put("uuid", updateContext.getKv("uuid"));
return constants;
}
@@ -239,18 +238,6 @@ public class UpdateModule extends ReactContextBaseJavaModule {
});
}
@ReactMethod
public void setBlockUpdate(ReadableMap options) {
final int until = options.getInt("until");
final String reason = options.getString("reason");
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
updateContext.setBlockUpdate(until, reason);
}
});
}
@ReactMethod
public void setUuid(final String uuid) {
UiThreadUtil.runOnUiThread(new Runnable() {

View File

@@ -16,7 +16,6 @@ static NSString *const paramLastVersion = @"lastVersion";
static NSString *const paramCurrentVersion = @"currentVersion";
static NSString *const paramIsFirstTime = @"isFirstTime";
static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK";
static NSString *const keyBlockUpdate = @"REACTNATIVECN_PUSHY_BLOCKUPDATE";
static NSString *const keyUuid = @"REACTNATIVECN_PUSHY_UUID";
static NSString *const keyHashInfo = @"REACTNATIVECN_PUSHY_HASH_";
static NSString *const keyFirstLoadMarked = @"REACTNATIVECN_PUSHY_FIRSTLOADMARKED_KEY";
@@ -157,7 +156,6 @@ RCT_EXPORT_MODULE(RCTPushy);
ret[@"buildTime"] = [RCTPushy buildTime];
ret[@"rolledBackVersion"] = [defaults objectForKey:keyRolledBackMarked];
ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked];
ret[@"blockUpdate"] = [defaults objectForKey:keyBlockUpdate];
ret[@"uuid"] = [defaults objectForKey:keyUuid];
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion];
@@ -192,24 +190,6 @@ RCT_EXPORT_MODULE(RCTPushy);
return self;
}
RCT_EXPORT_METHOD(setBlockUpdate:(NSDictionary *)options
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
// NSMutableDictionary *blockUpdateInfo = [NSMutableDictionary new];
// blockUpdateInfo[@"reason"] = options[@"reason"];
// blockUpdateInfo[@"until"] = options[@"until"];
@try {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:options forKey:keyBlockUpdate];
[defaults synchronize];
resolve(@true);
}
@catch (NSException *exception) {
reject(@"执行报错", nil, nil);
}
}
RCT_EXPORT_METHOD(setUuid:(NSString *)uuid resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "10.2.4",
"version": "10.3.1",
"description": "react-native hot update",
"main": "src/index.ts",
"scripts": {
@@ -48,13 +48,9 @@
"nanoid": "^3.3.3"
},
"codegenConfig": {
"libraries": [
{
"name": "RCTPushySpec",
"type": "modules",
"jsSrcsDir": "lib"
}
]
"name": "RCTPushySpec",
"type": "modules",
"jsSrcsDir": "src"
},
"devDependencies": {
"@babel/core": "^7.24.0",
@@ -68,9 +64,9 @@
"detox": "^20.5.0",
"eslint": "^8.57.0",
"eslint-plugin-ft-flow": "^3.0.7",
"jest": "^29.7.0",
"firebase-tools": "^11.24.1",
"fs-extra": "^9.1.0",
"jest": "^29.7.0",
"pod-install": "^0.1.37",
"prettier": "^2",
"react": "18.2.0",

View File

@@ -1,5 +1,4 @@
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
import { TurboModuleRegistry } from 'react-native';
import { TurboModule, TurboModuleRegistry } from 'react-native';
export interface Spec extends TurboModule {
getConstants: () => {

View File

@@ -9,7 +9,7 @@ const isTurboModuleEnabled =
global.__turboModuleProxy != null;
export const PushyModule = isTurboModuleEnabled
? require('./turboModuleSpec').default
? require('./NativePushy').default
: NativeModules.Pushy;
if (!PushyModule) {

View File

@@ -32,8 +32,10 @@ export const PushyProvider = ({
const { options } = client;
const stateListener = useRef<NativeEventSubscription>();
const [updateInfo, setUpdateInfo] = useState<CheckResult>();
const updateInfoRef = useRef(updateInfo);
const [progress, setProgress] = useState<ProgressData>();
const [lastError, setLastError] = useState<Error>();
const lastChecking = useRef(0);
const dismissError = useCallback(() => {
setLastError(undefined);
@@ -60,37 +62,40 @@ export const PushyProvider = ({
}
}, [client, updateInfo]);
const downloadUpdate = useCallback(async () => {
if (!updateInfo || !updateInfo.update) {
return;
}
try {
const hash = await client.downloadUpdate(updateInfo, setProgress);
if (!hash) {
const downloadUpdate = useCallback(
async (info: CheckResult | undefined = updateInfoRef.current) => {
if (!info || !info.update) {
return;
}
stateListener.current && stateListener.current.remove();
showAlert('提示', '下载完毕,是否立即更新?', [
{
text: '下次再说',
style: 'cancel',
onPress: () => {
client.switchVersionLater(hash);
try {
const hash = await client.downloadUpdate(info, setProgress);
if (!hash) {
return;
}
stateListener.current && stateListener.current.remove();
showAlert('提示', '下载完毕,是否立即更新?', [
{
text: '下次再说',
style: 'cancel',
onPress: () => {
client.switchVersionLater(hash);
},
},
},
{
text: '立即更新',
style: 'default',
onPress: () => {
client.switchVersion(hash);
{
text: '立即更新',
style: 'default',
onPress: () => {
client.switchVersion(hash);
},
},
},
]);
} catch (e: any) {
setLastError(e);
showAlert('更新失败', e.message);
}
}, [client, showAlert, updateInfo]);
]);
} catch (e: any) {
setLastError(e);
showAlert('更新失败', e.message);
}
},
[client, showAlert],
);
const downloadAndInstallApk = useCallback(
async (downloadUrl: string) => {
@@ -102,6 +107,11 @@ export const PushyProvider = ({
);
const checkUpdate = useCallback(async () => {
const now = Date.now();
if (lastChecking.current && now - lastChecking.current < 1000) {
return;
}
lastChecking.current = now;
let info: CheckResult;
try {
info = await client.checkUpdate();
@@ -110,23 +120,24 @@ export const PushyProvider = ({
showAlert('更新检查失败', e.message);
return;
}
updateInfoRef.current = info;
setUpdateInfo(info);
if (info.expired) {
const { downloadUrl } = info;
showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
{
text: '更新',
onPress: () => {
if (downloadUrl) {
if (downloadUrl) {
showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
{
text: '更新',
onPress: () => {
if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
downloadAndInstallApk(downloadUrl);
} else {
Linking.openURL(downloadUrl);
}
}
},
},
},
]);
]);
}
} else if (info.update) {
showAlert(
'提示',

6
tea.yaml Normal file
View File

@@ -0,0 +1,6 @@
# https://tea.xyz/what-is-this-file
---
version: 1.0.0
codeOwners:
- '0x10D90dC0034E2e82F0AC55954B3ed4EC0550ECe7'
quorum: 1