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

Compare commits

..

6 Commits

Author SHA1 Message Date
sunnylqm
571c2819b9 v10.4.0 2024-04-18 22:41:00 +08:00
sunnylqm
1f75688b92 Refactor assertRelease function 2024-04-18 22:39:03 +08:00
sunnylqm
de332c1796 Update PushyOptions strategy to allow null value 2024-04-02 21:21:15 +08:00
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
9 changed files with 52 additions and 43 deletions

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;
}

View File

@@ -45,7 +45,6 @@ public class UpdateModule extends NativePushySpec {
if (rolledBackVersion != null) {
updateContext.clearRollbackMark();
}
constants.put("blockUpdate", updateContext.getBlockUpdate());
constants.put("uuid", updateContext.getKv("uuid"));
return constants;
}

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;
}

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];

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "10.3.0",
"version": "10.4.0",
"description": "react-native hot update",
"main": "src/index.ts",
"scripts": {

View File

@@ -1,5 +1,5 @@
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
import { assertRelease, log, testUrls } from './utils';
import { log, testUrls } from './utils';
import {
EmitterSubscription,
PermissionsAndroid,
@@ -112,8 +112,7 @@ export class Pushy {
return true;
};
markSuccess = () => {
assertRelease();
if (this.marked) {
if (this.marked || __DEV__) {
return;
}
this.marked = true;
@@ -121,7 +120,12 @@ export class Pushy {
this.report({ type: 'markSuccess' });
};
switchVersion = (hash: string) => {
assertRelease();
if (__DEV__) {
console.warn(
'您调用了switchVersion方法但是当前是开发环境不会进行任何操作。',
);
return;
}
if (this.assertHash(hash) && !this.applyingUpdate) {
log('switchVersion: ' + hash);
this.applyingUpdate = true;
@@ -130,14 +134,18 @@ export class Pushy {
};
switchVersionLater = (hash: string) => {
assertRelease();
if (__DEV__) {
console.warn(
'您调用了switchVersionLater方法但是当前是开发环境不会进行任何操作。',
);
return;
}
if (this.assertHash(hash)) {
log('switchVersionLater: ' + hash);
PushyModule.setNeedUpdate({ hash });
}
};
checkUpdate = async () => {
assertRelease();
const now = Date.now();
if (
this.lastRespJson &&
@@ -148,18 +156,22 @@ export class Pushy {
}
this.lastChecking = now;
this.report({ type: 'checking' });
const fetchBody = {
packageVersion,
hash: currentVersion,
buildTime,
cInfo,
};
if (__DEV__) {
delete fetchBody.buildTime;
}
const fetchPayload = {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
packageVersion,
hash: currentVersion,
buildTime,
cInfo,
}),
body: JSON.stringify(fetchBody),
};
let resp;
try {
@@ -225,7 +237,6 @@ export class Pushy {
info: CheckResult,
onDownloadProgress?: (data: ProgressData) => void,
) => {
assertRelease();
const {
hash,
diffUrl: _diffUrl,
@@ -275,7 +286,11 @@ export class Pushy {
});
succeeded = true;
} catch (e: any) {
log(`diff error: ${e.message}, try pdiff`);
if (__DEV__) {
succeeded = true;
} else {
log(`diff error: ${e.message}, try pdiff`);
}
}
}
const pdiffUrl = (await testUrls(pdiffUrls)) || _pdiffUrl;
@@ -288,7 +303,11 @@ export class Pushy {
});
succeeded = true;
} catch (e: any) {
log(`pdiff error: ${e.message}, try full patch`);
if (__DEV__) {
succeeded = true;
} else {
log(`pdiff error: ${e.message}, try full patch`);
}
}
}
const updateUrl = (await testUrls(updateUrls)) || _updateUrl;
@@ -301,13 +320,20 @@ export class Pushy {
});
succeeded = true;
} catch (e: any) {
log(`full patch error: ${e.message}`);
if (__DEV__) {
succeeded = true;
} else {
log(`full patch error: ${e.message}`);
}
}
}
if (this.progressHandlers[hash]) {
this.progressHandlers[hash].remove();
delete this.progressHandlers[hash];
}
if (__DEV__) {
return hash;
}
if (!succeeded) {
return this.report({
type: 'errorUpdate',

View File

@@ -124,20 +124,20 @@ export const PushyProvider = ({
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(
'提示',

View File

@@ -70,7 +70,7 @@ export interface PushyOptions {
server?: PushyServerConfig;
logger?: UpdateEventsLogger;
useAlert?: boolean;
strategy?: 'onAppStart' | 'onAppResume' | 'both';
strategy?: 'onAppStart' | 'onAppResume' | 'both' | null;
autoMarkSuccess?: boolean;
dismissErrorAfter?: number;
}

View File

@@ -2,12 +2,6 @@ export function log(...args: any[]) {
console.log('pushy: ', ...args);
}
export function assertRelease() {
if (__DEV__) {
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
}
}
const ping = async (url: string) =>
Promise.race([
fetch(url, {