mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-23 09:38:52 +08:00
Update react-native-update to version 10.32.0 in package.json, refactor error handling in DownloadTask and UpdateContext for improved readability, and enhance type definitions in various files for better TypeScript support.
This commit is contained in:
@@ -93,7 +93,6 @@ export class Pushy {
|
||||
clientType: 'Pushy' | 'Cresc' = 'Pushy';
|
||||
lastChecking?: number;
|
||||
lastRespJson?: Promise<CheckResult>;
|
||||
lastRespText?: Promise<string>;
|
||||
|
||||
version = cInfo.rnu;
|
||||
loggerPromise = (() => {
|
||||
@@ -116,7 +115,7 @@ export class Pushy {
|
||||
|
||||
if (Platform.OS === 'ios' || Platform.OS === 'android') {
|
||||
if (!options.appKey) {
|
||||
throw new Error(i18n.t('error_appkey_required'));
|
||||
throw Error(i18n.t('error_appkey_required'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,10 +292,10 @@ export class Pushy {
|
||||
),
|
||||
);
|
||||
} catch (err: any) {
|
||||
this.throwIfEnabled(new Error('errorCheckingUseBackup'));
|
||||
this.throwIfEnabled(Error('errorCheckingUseBackup'));
|
||||
}
|
||||
} else {
|
||||
this.throwIfEnabled(new Error('errorCheckingGetBackup'));
|
||||
this.throwIfEnabled(Error('errorCheckingGetBackup'));
|
||||
}
|
||||
}
|
||||
if (!resp) {
|
||||
@@ -304,21 +303,21 @@ export class Pushy {
|
||||
type: 'errorChecking',
|
||||
message: this.t('error_cannot_connect_server'),
|
||||
});
|
||||
this.throwIfEnabled(new Error('errorChecking'));
|
||||
this.throwIfEnabled(Error('errorChecking'));
|
||||
return this.lastRespJson ? await this.lastRespJson : emptyObj;
|
||||
}
|
||||
|
||||
if (resp.status !== 200) {
|
||||
if (!resp.ok) {
|
||||
const respText = await resp.text();
|
||||
const errorMessage = this.t('error_http_status', {
|
||||
status: resp.status,
|
||||
statusText: resp.statusText,
|
||||
statusText: respText,
|
||||
});
|
||||
this.report({
|
||||
type: 'errorChecking',
|
||||
message: errorMessage,
|
||||
});
|
||||
this.throwIfEnabled(new Error(errorMessage));
|
||||
log('error checking response:', resp.status, await resp.text());
|
||||
this.throwIfEnabled(Error(errorMessage));
|
||||
return this.lastRespJson ? await this.lastRespJson : emptyObj;
|
||||
}
|
||||
this.lastRespJson = resp.json();
|
||||
@@ -435,7 +434,7 @@ export class Pushy {
|
||||
message: e.message,
|
||||
});
|
||||
errorMessages.push(errorMessage);
|
||||
lastError = new Error(errorMessage);
|
||||
lastError = Error(errorMessage);
|
||||
log(errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -454,7 +453,7 @@ export class Pushy {
|
||||
message: e.message,
|
||||
});
|
||||
errorMessages.push(errorMessage);
|
||||
lastError = new Error(errorMessage);
|
||||
lastError = Error(errorMessage);
|
||||
log(errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -474,7 +473,7 @@ export class Pushy {
|
||||
message: e.message,
|
||||
});
|
||||
errorMessages.push(errorMessage);
|
||||
lastError = new Error(errorMessage);
|
||||
lastError = Error(errorMessage);
|
||||
log(errorMessage);
|
||||
}
|
||||
} else if (__DEV__) {
|
||||
@@ -532,7 +531,7 @@ export class Pushy {
|
||||
}
|
||||
if (sharedState.apkStatus === 'downloaded') {
|
||||
this.report({ type: 'errorInstallApk' });
|
||||
this.throwIfEnabled(new Error('errorInstallApk'));
|
||||
this.throwIfEnabled(Error('errorInstallApk'));
|
||||
return;
|
||||
}
|
||||
if (Platform.Version <= 23) {
|
||||
@@ -542,7 +541,7 @@ export class Pushy {
|
||||
);
|
||||
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
|
||||
this.report({ type: 'rejectStoragePermission' });
|
||||
this.throwIfEnabled(new Error('rejectStoragePermission'));
|
||||
this.throwIfEnabled(Error('rejectStoragePermission'));
|
||||
return;
|
||||
}
|
||||
} catch (e: any) {
|
||||
@@ -575,7 +574,7 @@ export class Pushy {
|
||||
}).catch(() => {
|
||||
sharedState.apkStatus = null;
|
||||
this.report({ type: 'errorDownloadAndInstallApk' });
|
||||
this.throwIfEnabled(new Error('errorDownloadAndInstallApk'));
|
||||
this.throwIfEnabled(Error('errorDownloadAndInstallApk'));
|
||||
});
|
||||
sharedState.apkStatus = 'downloaded';
|
||||
if (sharedState.progressHandlers[progressKey]) {
|
||||
|
@@ -18,7 +18,7 @@ export const PushyModule =
|
||||
export const UpdateModule = PushyModule;
|
||||
|
||||
if (!PushyModule) {
|
||||
throw new Error(
|
||||
throw Error(
|
||||
'Failed to load react-native-update native module, please try to recompile',
|
||||
);
|
||||
}
|
||||
|
@@ -16,9 +16,9 @@ import { Pushy, Cresc, sharedState } from './client';
|
||||
import { currentVersion, packageVersion, getCurrentVersionInfo, currentVersionInfo } from './core';
|
||||
import {
|
||||
CheckResult,
|
||||
MixedCheckResult,
|
||||
ProgressData,
|
||||
UpdateTestPayload,
|
||||
VersionInfo,
|
||||
} from './type';
|
||||
import { UpdateContext } from './context';
|
||||
import { URL } from 'react-native-url-polyfill';
|
||||
@@ -163,7 +163,7 @@ export const UpdateProvider = ({
|
||||
return;
|
||||
}
|
||||
lastChecking.current = now;
|
||||
let rootInfo: MixedCheckResult | undefined;
|
||||
let rootInfo: CheckResult | undefined;
|
||||
try {
|
||||
rootInfo = await client.checkUpdate(extra);
|
||||
} catch (e: any) {
|
||||
@@ -175,8 +175,8 @@ export const UpdateProvider = ({
|
||||
if (!rootInfo) {
|
||||
return;
|
||||
}
|
||||
const versions = rootInfo.versions || [rootInfo as CheckResult];
|
||||
delete rootInfo.versions;
|
||||
const versions = [rootInfo.expVersion, rootInfo].filter(Boolean) as VersionInfo[];
|
||||
delete rootInfo.expVersion;
|
||||
for (const versionInfo of versions) {
|
||||
const info: CheckResult = {
|
||||
...versionInfo,
|
||||
@@ -242,7 +242,7 @@ export const UpdateProvider = ({
|
||||
alertUpdate(
|
||||
client.t('alert_title'),
|
||||
client.t('alert_new_version_found', {
|
||||
name: info.name,
|
||||
name: info.name!,
|
||||
description: info.description,
|
||||
}),
|
||||
[
|
||||
|
12
src/type.ts
12
src/type.ts
@@ -24,14 +24,10 @@ interface RootResult {
|
||||
paths?: string[];
|
||||
}
|
||||
|
||||
export type CheckResult = RootResult & VersionInfo;
|
||||
|
||||
export type CheckResultV2 = RootResult & {
|
||||
versions?: VersionInfo[];
|
||||
};
|
||||
|
||||
export type MixedCheckResult = CheckResult | CheckResultV2;
|
||||
|
||||
export type CheckResult = RootResult &
|
||||
Partial<VersionInfo> & {
|
||||
expVersion?: VersionInfo;
|
||||
};
|
||||
|
||||
export interface ProgressData {
|
||||
hash: string;
|
||||
|
@@ -17,7 +17,7 @@ export function promiseAny<T>(promises: Promise<T>[]) {
|
||||
.catch(() => {
|
||||
count++;
|
||||
if (count === promises.length) {
|
||||
reject(new Error(i18n.t('error_all_promises_rejected')));
|
||||
reject(Error(i18n.t('error_all_promises_rejected')));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -51,7 +51,7 @@ const ping = isWeb
|
||||
return finalUrl;
|
||||
}
|
||||
log('ping failed', url, status, statusText);
|
||||
throw new Error(i18n.t('error_ping_failed'));
|
||||
throw Error(i18n.t('error_ping_failed'));
|
||||
})
|
||||
.catch(e => {
|
||||
pingFinished = true;
|
||||
@@ -60,7 +60,7 @@ const ping = isWeb
|
||||
}),
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => {
|
||||
reject(new Error(i18n.t('error_ping_timeout')));
|
||||
reject(Error(i18n.t('error_ping_timeout')));
|
||||
if (!pingFinished) {
|
||||
log('ping timeout', url);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ export const enhancedFetch = async (
|
||||
if (r.ok) {
|
||||
return r;
|
||||
}
|
||||
throw new Error(
|
||||
throw Error(
|
||||
i18n.t('error_http_status', {
|
||||
status: r.status,
|
||||
statusText: r.statusText,
|
||||
|
Reference in New Issue
Block a user