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

chore: lint

This commit is contained in:
sunnylqm
2024-03-07 22:11:44 +08:00
parent 22c4b01ead
commit 94cf96a0e5
13 changed files with 627 additions and 383 deletions

View File

@@ -37,11 +37,11 @@ export class Pushy {
logger: noop,
};
lastChecking: number;
lastChecking?: number;
lastRespJson?: Promise<any>;
progressHandlers: Record<string, EmitterSubscription> = {};
downloadedHash: string;
downloadedHash?: string;
marked = false;
applyingUpdate = false;
@@ -57,6 +57,7 @@ export class Pushy {
setOptions = (options: Partial<PushyOptions>) => {
for (const [key, value] of Object.entries(options)) {
if (value !== undefined) {
// @ts-expect-error
this.options[key] = value;
if (key === 'logger') {
if (isRolledBack) {
@@ -163,7 +164,7 @@ export class Pushy {
let resp;
try {
resp = await fetch(this.getCheckUrl(), fetchPayload);
} catch (e) {
} catch (e: any) {
this.report({
type: 'errorChecking',
message: 'Can not connect to update server. Trying backup endpoints.',
@@ -172,7 +173,7 @@ export class Pushy {
if (backupEndpoints) {
try {
resp = await Promise.race(
backupEndpoints.map((endpoint) =>
backupEndpoints.map(endpoint =>
fetch(this.getCheckUrl(endpoint), fetchPayload),
),
);
@@ -214,7 +215,7 @@ export class Pushy {
new Set([...(server.backups || []), ...remoteEndpoints]),
);
}
} catch (e) {
} catch (e: any) {
log('failed to fetch endpoints from: ', server.queryUrl);
}
}
@@ -254,7 +255,7 @@ export class Pushy {
if (onDownloadProgress) {
this.progressHandlers[hash] = pushyNativeEventEmitter.addListener(
'RCTPushyDownloadProgress',
(progressData) => {
progressData => {
if (progressData.hash === hash) {
onDownloadProgress(progressData);
}
@@ -273,7 +274,7 @@ export class Pushy {
originHash: currentVersion,
});
succeeded = true;
} catch (e) {
} catch (e: any) {
log(`diff error: ${e.message}, try pdiff`);
}
}
@@ -286,7 +287,7 @@ export class Pushy {
hash,
});
succeeded = true;
} catch (e) {
} catch (e: any) {
log(`pdiff error: ${e.message}, try full patch`);
}
}
@@ -299,7 +300,7 @@ export class Pushy {
hash,
});
succeeded = true;
} catch (e) {
} catch (e: any) {
log(`full patch error: ${e.message}`);
}
}
@@ -338,7 +339,7 @@ export class Pushy {
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
return this.report({ type: 'rejectStoragePermission' });
}
} catch (err) {
} catch (e: any) {
return this.report({ type: 'errorStoragePermission' });
}
}

View File

@@ -4,7 +4,9 @@ const {
version: v,
} = require('react-native/Libraries/Core/ReactNativeVersion');
const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const isTurboModuleEnabled =
// @ts-expect-error
global.__turboModuleProxy != null;
export const PushyModule = isTurboModuleEnabled
? require('./turboModuleSpec').default

View File

@@ -86,9 +86,9 @@ export const PushyProvider = ({
},
},
]);
} catch (err) {
setLastError(err);
showAlert('更新失败', err.message);
} catch (e: any) {
setLastError(e);
showAlert('更新失败', e.message);
}
}, [client, showAlert, updateInfo]);
@@ -105,9 +105,9 @@ export const PushyProvider = ({
let info: CheckResult;
try {
info = await client.checkUpdate();
} catch (err) {
setLastError(err);
showAlert('更新检查失败', err.message);
} catch (e: any) {
setLastError(e);
showAlert('更新检查失败', e.message);
return;
}
setUpdateInfo(info);
@@ -159,7 +159,7 @@ export const PushyProvider = ({
if (strategy === 'both' || strategy === 'onAppResume') {
stateListener.current = AppState.addEventListener(
'change',
(nextAppState) => {
nextAppState => {
if (nextAppState === 'active') {
checkUpdate();
}
@@ -198,8 +198,7 @@ export const PushyProvider = ({
progress,
downloadAndInstallApk,
getCurrentVersionInfo,
}}
>
}}>
{children}
</PushyContext.Provider>
);

View File

@@ -12,9 +12,8 @@ const ping = async (url: string) =>
Promise.race([
fetch(url, {
method: 'HEAD',
redirect: 'follow',
}).then(({ status }) => status === 200),
new Promise<false>((r) => setTimeout(() => r(false), 2000)),
new Promise<false>(r => setTimeout(() => r(false), 2000)),
]);
const canUseGoogle = ping('https://www.google.com');
@@ -23,7 +22,7 @@ export const testUrls = async (urls?: string[]) => {
if (!urls?.length || (await canUseGoogle)) {
return null;
}
return Promise.race(urls.map((url) => ping(url).then(() => url))).catch(
return Promise.race(urls.map(url => ping(url).then(() => url))).catch(
() => null,
);
};