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

Compare commits

..

5 Commits

Author SHA1 Message Date
sunnylqm
af932665fe v8.5.6 2025-05-14 12:26:52 +08:00
sunnylqm
d1920cdb4f cleanup 2025-04-10 12:15:43 +08:00
sunnylqm
3fe3daf599 Merge branch 'v8' of github.com:reactnativecn/react-native-update into v8
# Conflicts:
#	lib/utils.ts
2025-04-07 15:24:59 +08:00
sunnylqm
7fea63b2eb fix testurls 2025-04-07 15:23:52 +08:00
sunny.luo
2630096760 v8.5.3 2024-12-13 18:46:09 +08:00
7 changed files with 70 additions and 19 deletions

1
.gitignore vendored
View File

@@ -44,3 +44,4 @@ npm-debug.log
Example/**/update.json
yarn-error.log
Example/testHotUpdate/.pushy
dist/

View File

@@ -24,7 +24,7 @@ export async function updateBackupEndpoints() {
logger('fetch remote endpoints:', remoteEndpoints);
logger('merged backup endpoints:', backupEndpoints);
}
} catch (e) {
} catch (e: any) {
logger('fetch remote endpoints failed');
}
}

View File

@@ -154,7 +154,7 @@ export async function checkUpdate(APPKEY: string) {
let resp;
try {
resp = await fetch(getCheckUrl(APPKEY), fetchPayload);
} catch (e) {
} catch (e: any) {
report({
type: 'errorChecking',
message: '无法连接主更新服务器,尝试备用节点',
@@ -265,7 +265,7 @@ export async function downloadUpdate(
originHash: currentVersion,
});
succeeded = true;
} catch (e) {
} catch (e: any) {
logger(`diff error: ${e.message}, try pdiff`);
}
}
@@ -279,7 +279,7 @@ export async function downloadUpdate(
hash: options.hash,
});
succeeded = true;
} catch (e) {
} catch (e: any) {
logger(`pdiff error: ${e.message}, try full patch`);
}
}
@@ -294,7 +294,7 @@ export async function downloadUpdate(
hash: options.hash,
});
succeeded = true;
} catch (e) {
} catch (e: any) {
logger(`full patch error: ${e.message}`);
}
}
@@ -371,7 +371,7 @@ export async function downloadAndInstallApk({
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
return report({ type: 'rejectStoragePermission' });
}
} catch (err) {
} catch (err: any) {
return report({ type: 'errorStoragePermission' });
}
}

View File

@@ -34,7 +34,7 @@ export function simpleUpdate(
return __DEV__
? WrappedComponent
: class AppUpdate extends PureComponent {
stateListener: NativeEventSubscription;
stateListener: NativeEventSubscription | null = null;
componentDidMount() {
if (isRolledBack) {
Alert.alert('抱歉', '刚刚更新遭遇错误,已为您恢复到更新前版本');
@@ -77,7 +77,7 @@ export function simpleUpdate(
},
},
]);
} catch (err) {
} catch (err: any) {
Alert.alert('更新失败', err.message);
}
};
@@ -86,7 +86,7 @@ export function simpleUpdate(
let info;
try {
info = await checkUpdate(appKey!);
} catch (err) {
} catch (err: any) {
Alert.alert('更新检查失败', err.message);
return;
}

View File

@@ -4,7 +4,7 @@ export function promiseAny<T>(promises: Promise<T>[]) {
return new Promise<T>((resolve, reject) => {
let count = 0;
promises.forEach(promise => {
promises.forEach((promise) => {
Promise.resolve(promise)
.then(resolve)
.catch(() => {
@@ -30,17 +30,46 @@ export function assertRelease() {
const ping =
Platform.OS === 'web'
? Promise.resolve
: async (url: string) =>
Promise.race([
: async (url: string) => {
let pingFinished = false;
return Promise.race([
fetch(url, {
method: 'HEAD',
}).then(({ status }) => (status === 200 ? url : null)),
new Promise(r => setTimeout(() => r(null), 2000)),
})
.then(({ status, statusText }) => {
pingFinished = true;
if (status === 200) {
return url;
}
logger('ping failed', url, status, statusText);
throw new Error('Ping failed');
})
.catch((e) => {
pingFinished = true;
logger('ping error', url, e);
throw e;
}),
new Promise((_, reject) =>
setTimeout(() => {
reject(new Error('Ping timeout'));
if (!pingFinished) {
logger('ping timeout', url);
}
}, 2000),
),
]);
};
export const testUrls = async (urls?: string[]) => {
if (!urls?.length) {
return null;
}
return promiseAny(urls.map(ping)).catch(() => null);
try {
const ret = await promiseAny(urls.map(ping));
if (ret) {
return ret;
}
} catch {}
logger('all ping failed, use first url:', urls[0]);
return urls[0];
};

View File

@@ -1,10 +1,13 @@
{
"name": "react-native-update",
"version": "8.5.2",
"version": "8.5.6",
"description": "react-native hot update",
"main": "lib/index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prepublish": "yarn submodule",
"prepublishOnly": "yarn submodule && yarn build",
"build": "yarn clean && tsc",
"clean": "rm -rf dist",
"submodule": "git submodule update --init --recursive",
"test": "echo \"Error: no test specified\" && exit 1",
"build-lib": "yarn submodule && $ANDROID_HOME/ndk/20.1.5948944/ndk-build NDK_PROJECT_PATH=android APP_BUILD_SCRIPT=android/jni/Android.mk NDK_APPLICATION_MK=android/jni/Application.mk NDK_LIBS_OUT=android/lib"
@@ -25,7 +28,7 @@
"url": "https://github.com/reactnativecn/react-native-pushy/issues"
},
"peerDependencies": {
"react-native": ">=0.57.0"
"react-native": "*"
},
"homepage": "https://github.com/reactnativecn/react-native-pushy#readme",
"dependencies": {

18
tsconfig.json Normal file
View File

@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-native",
"lib": ["es2016", "dom"],
"moduleResolution": "node"
},
"include": ["lib/**/*"],
"exclude": ["node_modules", "dist", "Example"]
}