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

support multiple versions

This commit is contained in:
sunnylqm
2025-09-04 00:24:35 +08:00
parent 41e1028b2d
commit e58903a634
3 changed files with 116 additions and 84 deletions

View File

@@ -91,7 +91,8 @@ export class Pushy {
options = defaultClientOptions; options = defaultClientOptions;
clientType: 'Pushy' | 'Cresc' = 'Pushy'; clientType: 'Pushy' | 'Cresc' = 'Pushy';
lastChecking?: number; lastChecking?: number;
lastRespJson?: Promise<any>; lastRespJson?: Promise<CheckResult>;
lastRespText?: Promise<string>;
version = cInfo.rnu; version = cInfo.rnu;
loggerPromise = (() => { loggerPromise = (() => {
@@ -294,20 +295,23 @@ export class Pushy {
this.throwIfEnabled(new Error('errorChecking')); this.throwIfEnabled(new Error('errorChecking'));
return this.lastRespJson ? await this.lastRespJson : emptyObj; return this.lastRespJson ? await this.lastRespJson : emptyObj;
} }
if (resp.status !== 200) {
const errorMessage = `${resp.status}: ${resp.statusText}`;
this.report({
type: 'errorChecking',
message: errorMessage,
});
this.throwIfEnabled(new Error(errorMessage));
log('error checking response:', resp.status, await resp.text());
return this.lastRespJson ? await this.lastRespJson : emptyObj;
}
this.lastRespJson = resp.json(); this.lastRespJson = resp.json();
const result: CheckResult = await this.lastRespJson; const result: CheckResult = await this.lastRespJson;
log('checking result:', result); log('checking result:', result);
if (resp.status !== 200) {
this.report({
type: 'errorChecking',
message: result.message,
});
this.throwIfEnabled(new Error(result.message));
}
return result; return result;
}; };
getBackupEndpoints = async () => { getBackupEndpoints = async () => {

View File

@@ -14,7 +14,12 @@ import {
} from 'react-native'; } from 'react-native';
import { Pushy, Cresc, sharedState } from './client'; import { Pushy, Cresc, sharedState } from './client';
import { currentVersion, packageVersion, getCurrentVersionInfo } from './core'; import { currentVersion, packageVersion, getCurrentVersionInfo } from './core';
import { CheckResult, ProgressData, UpdateTestPayload } from './type'; import {
CheckResult,
MixedCheckResult,
ProgressData,
UpdateTestPayload,
} from './type';
import { UpdateContext } from './context'; import { UpdateContext } from './context';
import { URL } from 'react-native-url-polyfill'; import { URL } from 'react-native-url-polyfill';
import { isInRollout } from './isInRollout'; import { isInRollout } from './isInRollout';
@@ -158,25 +163,32 @@ export const UpdateProvider = ({
return; return;
} }
lastChecking.current = now; lastChecking.current = now;
let info: CheckResult; let rootInfo: MixedCheckResult | undefined;
try { try {
info = await client.checkUpdate(extra); rootInfo = await client.checkUpdate(extra);
} catch (e: any) { } catch (e: any) {
setLastError(e); setLastError(e);
alertError('更新检查失败', e.message); alertError('更新检查失败', e.message);
throwErrorIfEnabled(e); throwErrorIfEnabled(e);
return; return;
} }
if (!info) { if (!rootInfo) {
return; return;
} }
const versions = rootInfo.versions || [rootInfo as CheckResult];
delete rootInfo.versions;
for (const versionInfo of versions) {
const info: CheckResult = {
...versionInfo,
...rootInfo,
};
const rollout = info.config?.rollout?.[packageVersion]; const rollout = info.config?.rollout?.[packageVersion];
if (info.update && rollout) { if (info.update && rollout) {
if (!isInRollout(rollout)) { if (!isInRollout(rollout)) {
log(`not in ${rollout}% rollout, ignored`); log(`${info.name} not in ${rollout}% rollout, ignored`);
return; continue;
} }
log(`in ${rollout}% rollout, continue`); log(`${info.name} in ${rollout}% rollout, continue`);
} }
info.description = info.description ?? ''; info.description = info.description ?? '';
updateInfoRef.current = info; updateInfoRef.current = info;
@@ -203,7 +215,10 @@ export const UpdateProvider = ({
{ {
text: '更新', text: '更新',
onPress: () => { onPress: () => {
if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) { if (
Platform.OS === 'android' &&
downloadUrl.endsWith('.apk')
) {
downloadAndInstallApk(downloadUrl); downloadAndInstallApk(downloadUrl);
} else { } else {
Linking.openURL(downloadUrl); Linking.openURL(downloadUrl);
@@ -236,6 +251,7 @@ export const UpdateProvider = ({
); );
} }
return info; return info;
}
}, },
[ [
client, client,

View File

@@ -1,14 +1,10 @@
export interface CheckResult { export interface VersionInfo {
upToDate?: true; name: string;
expired?: true; hash: string;
downloadUrl?: string; description: string;
update?: true; metaInfo: string;
name?: string; // version name config: {
hash?: string; rollout: {
description?: string;
metaInfo?: string;
config?: {
rollout?: {
[packageVersion: string]: number; [packageVersion: string]: number;
}; };
[key: string]: any; [key: string]: any;
@@ -16,11 +12,27 @@ export interface CheckResult {
pdiff?: string; pdiff?: string;
diff?: string; diff?: string;
full?: string; full?: string;
paths?: string[]; }
interface RootResult {
upToDate?: true;
expired?: true;
downloadUrl?: string;
update?: true;
paused?: 'app' | 'package'; paused?: 'app' | 'package';
message?: string; message?: string;
paths?: string[];
} }
export type CheckResult = RootResult & VersionInfo;
export type CheckResultV2 = RootResult & {
versions?: VersionInfo[];
};
export type MixedCheckResult = CheckResult | CheckResultV2;
export interface ProgressData { export interface ProgressData {
hash: string; hash: string;
received: number; received: number;