Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84b71e33a8 | ||
|
|
6cd99dece0 | ||
|
|
d726f3602b | ||
|
|
da21c99bcc | ||
|
|
1f8748375c | ||
|
|
fa731cd583 | ||
|
|
d077dcb6d3 | ||
|
|
59b60fdc6d | ||
|
|
c768705221 | ||
|
|
57206dd2f1 | ||
|
|
4e27d906c3 | ||
|
|
c24f469475 | ||
|
|
8f8a29eda8 | ||
|
|
a78542b214 | ||
|
|
8d9ae57a5f | ||
|
|
2502935fc0 | ||
|
|
8e6d9bf460 | ||
|
|
897f334343 | ||
|
|
33bc69c3fb | ||
|
|
5028ce31be | ||
|
|
d3a4007763 | ||
|
|
a4f3e3cc38 | ||
|
|
9d51128ed3 | ||
|
|
eddb072927 | ||
|
|
4f9417d620 | ||
|
|
6f2314d3c9 | ||
|
|
a6e9ece559 | ||
|
|
78430e2ec2 | ||
|
|
ec5b9e1938 | ||
|
|
53dfb45ca2 | ||
|
|
4a62e89c73 | ||
|
|
655f4c8cf5 | ||
|
|
3732c196a1 | ||
|
|
bfb520bd07 | ||
|
|
f7be8a4d71 | ||
|
|
4383a66274 | ||
|
|
a82b75f51f | ||
|
|
584f698329 | ||
|
|
e58903a634 | ||
|
|
41e1028b2d | ||
|
|
11d40ce5f2 | ||
|
|
4a1d4d5a50 | ||
|
|
02517a9eb0 | ||
|
|
f7309f699f | ||
|
|
a224113998 | ||
|
|
f2ede92ea1 | ||
|
|
a913e8c10e | ||
|
|
c5f458291a | ||
|
|
9699632a43 | ||
|
|
80e42f5dba | ||
|
|
9b718b8f75 | ||
|
|
99e3431844 | ||
|
|
d7b5562ab7 | ||
|
|
6a0a5b2d49 | ||
|
|
7023ff57ca | ||
|
|
17e21d79cf | ||
|
|
1cab582bd0 | ||
|
|
7da5a165fd | ||
|
|
d5194a1ad1 | ||
|
|
ebc9b97e70 | ||
|
|
40742e16d8 | ||
|
|
598ae1a506 | ||
|
|
e5424591d1 | ||
|
|
2cf7336b6a | ||
|
|
7eac48ab5d | ||
|
|
18d9b75545 | ||
|
|
e8ec85c65f | ||
|
|
48a776d506 | ||
|
|
8ad526148f | ||
|
|
cea39f1746 | ||
|
|
aa56c2ec0f | ||
|
|
00a989d567 | ||
|
|
83ca3a6c05 | ||
|
|
257f2697e0 | ||
|
|
77aa345f11 | ||
|
|
66332d007a | ||
|
|
37849b1730 |
6
.gitignore
vendored
@@ -51,3 +51,9 @@ android/bin
|
|||||||
Example/testHotUpdate/harmony
|
Example/testHotUpdate/harmony
|
||||||
Example/testHotUpdate/android/app/.cxx
|
Example/testHotUpdate/android/app/.cxx
|
||||||
Example/harmony_use_pushy/libs
|
Example/harmony_use_pushy/libs
|
||||||
|
**/mcp.json
|
||||||
|
|
||||||
|
|
||||||
|
harmony/package
|
||||||
|
**/oh_modules
|
||||||
|
harmony/pushy/.preview
|
||||||
|
|||||||
8
.gitmodules
vendored
@@ -4,9 +4,9 @@
|
|||||||
[submodule "android/jni/HDiffPatch"]
|
[submodule "android/jni/HDiffPatch"]
|
||||||
path = android/jni/HDiffPatch
|
path = android/jni/HDiffPatch
|
||||||
url = https://github.com/sisong/HDiffPatch.git
|
url = https://github.com/sisong/HDiffPatch.git
|
||||||
[submodule "harmony/src/main/cpp/HDiffPatch"]
|
[submodule "harmony/pushy/src/main/cpp/HDiffPatch"]
|
||||||
path = harmony/src/main/cpp/HDiffPatch
|
path = harmony/pushy/src/main/cpp/HDiffPatch
|
||||||
url = https://github.com/sisong/HDiffPatch.git
|
url = https://github.com/sisong/HDiffPatch.git
|
||||||
[submodule "harmony/src/main/cpp/lzma"]
|
[submodule "harmony/pushy/src/main/cpp/lzma"]
|
||||||
path = harmony/src/main/cpp/lzma
|
path = harmony/pushy/src/main/cpp/lzma
|
||||||
url = https://github.com/sisong/lzma.git
|
url = https://github.com/sisong/lzma.git
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
Example
|
Example
|
||||||
android/build
|
android/build
|
||||||
.vscode
|
.vscode
|
||||||
|
.github/
|
||||||
|
|
||||||
# OSX
|
# OSX
|
||||||
#
|
#
|
||||||
@@ -52,3 +53,5 @@ endpoints.json
|
|||||||
endpoints_cresc.json
|
endpoints_cresc.json
|
||||||
|
|
||||||
tea.yaml
|
tea.yaml
|
||||||
|
|
||||||
|
e2e/
|
||||||
@@ -1 +0,0 @@
|
|||||||
nodeLinker: node-modules
|
|
||||||
36
Example/expoUsePushy/.gitignore
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Expo
|
||||||
|
.expo/
|
||||||
|
dist/
|
||||||
|
web-build/
|
||||||
|
expo-env.d.ts
|
||||||
|
|
||||||
|
# Native
|
||||||
|
*.orig.*
|
||||||
|
*.jks
|
||||||
|
*.p8
|
||||||
|
*.p12
|
||||||
|
*.key
|
||||||
|
*.mobileprovision
|
||||||
|
|
||||||
|
# Metro
|
||||||
|
.metro-health-check*
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.*
|
||||||
|
yarn-debug.*
|
||||||
|
yarn-error.*
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env*.local
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
221
Example/expoUsePushy/App.tsx
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
/* eslint-disable react/no-unstable-nested-components */
|
||||||
|
/* eslint-disable react-native/no-inline-styles */
|
||||||
|
import React, {useState} from 'react';
|
||||||
|
import {StyleSheet, Text, View, TouchableOpacity, Image} from 'react-native';
|
||||||
|
|
||||||
|
import TestConsole from './TestConsole';
|
||||||
|
|
||||||
|
import _updateConfig from './update.json';
|
||||||
|
import {PushyProvider, Pushy, usePushy} from 'react-native-update';
|
||||||
|
const {appKey} = _updateConfig.android;
|
||||||
|
|
||||||
|
function Home() {
|
||||||
|
const {
|
||||||
|
client,
|
||||||
|
checkUpdate,
|
||||||
|
downloadUpdate,
|
||||||
|
switchVersionLater,
|
||||||
|
switchVersion,
|
||||||
|
updateInfo,
|
||||||
|
packageVersion,
|
||||||
|
currentHash,
|
||||||
|
progress: {received, total} = {},
|
||||||
|
} = usePushy();
|
||||||
|
const [useDefaultAlert, setUseDefaultAlert] = useState(false);
|
||||||
|
const [showTestConsole, setShowTestConsole] = useState(false);
|
||||||
|
const [showUpdateBanner, setShowUpdateBanner] = useState(false);
|
||||||
|
const [showUpdateSnackbar, setShowUpdateSnackbar] = useState(false);
|
||||||
|
// if (updateInfo) {
|
||||||
|
// updateInfo!.name = 'name';
|
||||||
|
// updateInfo!.update = true;
|
||||||
|
// }
|
||||||
|
const snackbarVisible =
|
||||||
|
!useDefaultAlert && showUpdateSnackbar && updateInfo?.update;
|
||||||
|
|
||||||
|
if (showTestConsole) {
|
||||||
|
return (
|
||||||
|
<TestConsole visible={true} onClose={() => setShowTestConsole(false)} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<Text style={styles.welcome}>欢迎使用Pushy热更新服务</Text>
|
||||||
|
{/* <Text style={styles.welcome}>😁hdiffFromAPP更新成功!!!</Text> */}
|
||||||
|
{/* <Text style={styles.welcome}>😁hdiffFromPPk更新成功!!!</Text> */}
|
||||||
|
<View style={{flexDirection: 'row'}}>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => {
|
||||||
|
client?.setOptions({
|
||||||
|
updateStrategy: !useDefaultAlert ? null : 'alwaysAlert',
|
||||||
|
});
|
||||||
|
setShowUpdateSnackbar(useDefaultAlert);
|
||||||
|
setUseDefaultAlert(!useDefaultAlert);
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: '#999',
|
||||||
|
backgroundColor: useDefaultAlert ? 'blue' : 'white',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}>
|
||||||
|
{useDefaultAlert && <Text style={{color: 'white'}}>✓</Text>}
|
||||||
|
</View>
|
||||||
|
<Text style={{marginLeft: 8}}>
|
||||||
|
{' '}
|
||||||
|
{useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
<Image
|
||||||
|
resizeMode={'contain'}
|
||||||
|
source={require('./assets/shezhi.png')}
|
||||||
|
style={styles.image}
|
||||||
|
/>
|
||||||
|
<Text style={styles.instructions}>
|
||||||
|
这是版本一 {'\n'}
|
||||||
|
当前原生包版本号: {packageVersion}
|
||||||
|
{'\n'}
|
||||||
|
当前热更新版本Hash: {currentHash || '(空)'}
|
||||||
|
{'\n'}
|
||||||
|
</Text>
|
||||||
|
<Text>
|
||||||
|
下载进度:{received} / {total}
|
||||||
|
</Text>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => {
|
||||||
|
checkUpdate();
|
||||||
|
setShowUpdateSnackbar(true);
|
||||||
|
}}>
|
||||||
|
<Text style={styles.instructions}>点击这里检查更新</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
|
||||||
|
<TouchableOpacity
|
||||||
|
testID="testcase"
|
||||||
|
style={{marginTop: 15}}
|
||||||
|
onPress={() => {
|
||||||
|
setShowTestConsole(true);
|
||||||
|
}}>
|
||||||
|
<Text style={styles.instructions}>
|
||||||
|
react-native-update版本:{client?.version}
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
{snackbarVisible && (
|
||||||
|
<View style={styles.overlay}>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
backgroundColor: '#333',
|
||||||
|
padding: 16,
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}>
|
||||||
|
<Text style={{color: 'white'}}>
|
||||||
|
有新版本({updateInfo.name})可用,是否更新?
|
||||||
|
</Text>
|
||||||
|
<View style={{flexDirection: 'row'}}>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => setShowUpdateSnackbar(false)}
|
||||||
|
style={{marginRight: 10}}>
|
||||||
|
<Text style={{color: 'white'}}>取消</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={async () => {
|
||||||
|
setShowUpdateSnackbar(false);
|
||||||
|
await downloadUpdate();
|
||||||
|
setShowUpdateBanner(true);
|
||||||
|
}}>
|
||||||
|
<Text style={{color: '#2196F3'}}>更新</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
{showUpdateBanner && (
|
||||||
|
<View style={styles.overlay}>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
backgroundColor: '#fff',
|
||||||
|
padding: 16,
|
||||||
|
borderBottomWidth: 1,
|
||||||
|
borderBottomColor: '#eee',
|
||||||
|
}}>
|
||||||
|
<View style={{flexDirection: 'row', alignItems: 'center'}}>
|
||||||
|
<Text>更新已完成,是否立即重启?</Text>
|
||||||
|
</View>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
marginTop: 10,
|
||||||
|
}}>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => {
|
||||||
|
switchVersionLater();
|
||||||
|
setShowUpdateBanner(false);
|
||||||
|
}}
|
||||||
|
style={{marginRight: 20}}>
|
||||||
|
<Text style={{color: '#2196F3'}}>下次再说</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity onPress={switchVersion}>
|
||||||
|
<Text style={{color: '#2196F3'}}>立即重启</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
overlay: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
backgroundColor: '#F5FCFF',
|
||||||
|
},
|
||||||
|
welcome: {
|
||||||
|
fontSize: 20,
|
||||||
|
textAlign: 'center',
|
||||||
|
margin: 10,
|
||||||
|
},
|
||||||
|
instructions: {
|
||||||
|
textAlign: 'center',
|
||||||
|
color: '#333333',
|
||||||
|
marginBottom: 5,
|
||||||
|
},
|
||||||
|
image: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const pushyClient = new Pushy({
|
||||||
|
appKey,
|
||||||
|
debug: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function HomeScreen() {
|
||||||
|
return (
|
||||||
|
<PushyProvider client={pushyClient}>
|
||||||
|
<Home />
|
||||||
|
</PushyProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
274
Example/expoUsePushy/TestConsole.js
Normal file
@@ -0,0 +1,274 @@
|
|||||||
|
/* eslint-disable react-native/no-inline-styles */
|
||||||
|
/* eslint-disable react/react-in-jsx-scope */
|
||||||
|
import {useCallback, useMemo, useState} from 'react';
|
||||||
|
import {
|
||||||
|
ActivityIndicator,
|
||||||
|
TextInput,
|
||||||
|
Button,
|
||||||
|
StyleSheet,
|
||||||
|
SafeAreaView,
|
||||||
|
Text,
|
||||||
|
View,
|
||||||
|
TouchableOpacity,
|
||||||
|
} from 'react-native';
|
||||||
|
|
||||||
|
import {PushyModule} from 'react-native-update';
|
||||||
|
const Hash = '9D5CE6EBA420717BE7E7D308B11F8207681B066C951D68F3994D19828F342474';
|
||||||
|
const UUID = '00000000-0000-0000-0000-000000000000';
|
||||||
|
const DownloadUrl = 'https://localhost:3000/diff.ppk-patch';
|
||||||
|
const AppPatchDownloadUrl = 'https://github.com/bozaigao/test_pushy_server/raw/refs/heads/main/hdiff.app-patch';
|
||||||
|
const AppPatchHash = 'f5ba92c7c04250d4b8a446c8267ef459';
|
||||||
|
const PPKDownloadUrl = 'https://github.com/bozaigao/test_pushy_server/raw/refs/heads/main/hdiff.ppk-patch';
|
||||||
|
const PPKPatchHash = '6b3d26b7d868d1f67aedadb7f0b342d9';
|
||||||
|
const OriginHash = 'f5ba92c7c04250d4b8a446c8267ef459';
|
||||||
|
|
||||||
|
|
||||||
|
const CustomDialog = ({title, visible, onConfirm}) => {
|
||||||
|
if (!visible) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.overlay}>
|
||||||
|
<View style={styles.dialog}>
|
||||||
|
<Text style={styles.title}>{title}</Text>
|
||||||
|
<TouchableOpacity
|
||||||
|
testID="done"
|
||||||
|
style={styles.button}
|
||||||
|
onPress={onConfirm}>
|
||||||
|
<Text style={styles.buttonText}>确认</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default function TestConsole({visible, onClose}) {
|
||||||
|
const [text, setText] = useState('');
|
||||||
|
const [running, setRunning] = useState(false);
|
||||||
|
const [options, setOptions] = useState();
|
||||||
|
const [alertVisible, setAlertVisible] = useState(false);
|
||||||
|
const [alertMsg, setAlertMsg] = useState('');
|
||||||
|
const NativeTestMethod = useMemo(() => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
name: 'setLocalHashInfo',
|
||||||
|
invoke: () => {
|
||||||
|
setText(
|
||||||
|
`setLocalHashInfo\n${Hash}\n{\"version\":\"1.0.0\",\"size\":\"19M\"}`,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'getLocalHashInfo',
|
||||||
|
invoke: () => {
|
||||||
|
setText(`getLocalHashInfo\n${Hash}`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'setUuid',
|
||||||
|
invoke: () => {
|
||||||
|
setText(`setUuid\n${UUID}`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'reloadUpdate',
|
||||||
|
invoke: () => {
|
||||||
|
setText('reloadUpdate');
|
||||||
|
setOptions({hash: Hash});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'setNeedUpdateForApp',
|
||||||
|
invoke: () => {
|
||||||
|
setText('setNeedUpdate');
|
||||||
|
setOptions({hash: AppPatchHash});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'setNeedUpdateForPPK',
|
||||||
|
invoke: () => {
|
||||||
|
setText('setNeedUpdate');
|
||||||
|
setOptions({hash: PPKPatchHash});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'markSuccess',
|
||||||
|
invoke: () => {
|
||||||
|
setText('markSuccess');
|
||||||
|
setOptions(undefined);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'downloadPatchFromPpk',
|
||||||
|
invoke: () => {
|
||||||
|
setText('downloadPatchFromPpk');
|
||||||
|
setOptions({updateUrl: PPKDownloadUrl, hash: PPKPatchHash, originHash: OriginHash});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'downloadPatchFromPackage',
|
||||||
|
invoke: () => {
|
||||||
|
setText('downloadPatchFromPackage');
|
||||||
|
setOptions({updateUrl: AppPatchDownloadUrl, hash: AppPatchHash});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'downloadFullUpdate',
|
||||||
|
invoke: () => {
|
||||||
|
setText('downloadFullUpdate');
|
||||||
|
setOptions({updateUrl: DownloadUrl, hash: Hash});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'downloadAndInstallApk',
|
||||||
|
invoke: () => {
|
||||||
|
setText('downloadAndInstallApk');
|
||||||
|
setOptions({url: DownloadUrl, target: Hash, hash: Hash});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const renderTestView = useCallback(() => {
|
||||||
|
const views = [];
|
||||||
|
for (let i = 0; i < NativeTestMethod.length; i++) {
|
||||||
|
views.push(
|
||||||
|
<TouchableOpacity
|
||||||
|
key={i}
|
||||||
|
testID={NativeTestMethod[i].name}
|
||||||
|
onPress={() => {
|
||||||
|
NativeTestMethod[i].invoke();
|
||||||
|
}}>
|
||||||
|
<Text>{NativeTestMethod[i].name}</Text>
|
||||||
|
</TouchableOpacity>,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <View>{views}</View>;
|
||||||
|
}, [NativeTestMethod]);
|
||||||
|
if (!visible) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SafeAreaView style={{flex: 1, padding: 10}}>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
padding: 10,
|
||||||
|
}}>
|
||||||
|
<Text>调试Pushy方法(方法名,参数,值换行)</Text>
|
||||||
|
<Button title="关闭" onPress={() => onClose()} />
|
||||||
|
</View>
|
||||||
|
<TextInput
|
||||||
|
autoCorrect={false}
|
||||||
|
autoCapitalize="none"
|
||||||
|
style={{
|
||||||
|
borderWidth: StyleSheet.hairlineWidth * 4,
|
||||||
|
borderColor: 'black',
|
||||||
|
height: '30%',
|
||||||
|
marginTop: 20,
|
||||||
|
marginBottom: 20,
|
||||||
|
padding: 10,
|
||||||
|
fontSize: 20,
|
||||||
|
}}
|
||||||
|
textAlignVertical="top"
|
||||||
|
multiline={true}
|
||||||
|
value={text}
|
||||||
|
onChangeText={setText}
|
||||||
|
/>
|
||||||
|
{running && <ActivityIndicator />}
|
||||||
|
<TouchableOpacity
|
||||||
|
style={{
|
||||||
|
backgroundColor: 'rgb(0,140,237)',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
paddingTop: 10,
|
||||||
|
paddingBottom: 10,
|
||||||
|
marginBottom: 5,
|
||||||
|
}}
|
||||||
|
testID="submit"
|
||||||
|
onPress={async () => {
|
||||||
|
setRunning(true);
|
||||||
|
try {
|
||||||
|
const inputs = text.split('\n');
|
||||||
|
const methodName = inputs[0];
|
||||||
|
let params = [];
|
||||||
|
if (inputs.length === 1) {
|
||||||
|
if (options) {
|
||||||
|
await PushyModule[methodName](options);
|
||||||
|
} else {
|
||||||
|
await PushyModule[methodName]();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (inputs.length === 2) {
|
||||||
|
params = [inputs[1]];
|
||||||
|
} else {
|
||||||
|
params = [inputs[1], inputs[2]];
|
||||||
|
console.log({inputs, params});
|
||||||
|
}
|
||||||
|
await PushyModule[methodName](...params);
|
||||||
|
}
|
||||||
|
setAlertVisible(true);
|
||||||
|
setAlertMsg('done');
|
||||||
|
} catch (e) {
|
||||||
|
setAlertVisible(true);
|
||||||
|
setAlertMsg(e.message);
|
||||||
|
}
|
||||||
|
setRunning(false);
|
||||||
|
}}>
|
||||||
|
<Text style={{color: 'white'}}>执行</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<Button title="重置" onPress={() => setText('')} />
|
||||||
|
{renderTestView()}
|
||||||
|
<CustomDialog
|
||||||
|
title={alertMsg}
|
||||||
|
visible={alertVisible}
|
||||||
|
onConfirm={() => {
|
||||||
|
setAlertVisible(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</SafeAreaView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
overlay: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
dialog: {
|
||||||
|
backgroundColor: 'white',
|
||||||
|
borderRadius: 10,
|
||||||
|
padding: 20,
|
||||||
|
width: '80%',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
marginBottom: 20,
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
backgroundColor: '#2196F3',
|
||||||
|
borderRadius: 5,
|
||||||
|
paddingVertical: 10,
|
||||||
|
paddingHorizontal: 20,
|
||||||
|
},
|
||||||
|
buttonText: {
|
||||||
|
color: 'white',
|
||||||
|
fontWeight: 'bold',
|
||||||
|
},
|
||||||
|
});
|
||||||
30
Example/expoUsePushy/app.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"expo": {
|
||||||
|
"name": "expoUsePushy",
|
||||||
|
"slug": "expoUsePushy",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"orientation": "portrait",
|
||||||
|
"icon": "./assets/icon.png",
|
||||||
|
"userInterfaceStyle": "light",
|
||||||
|
"newArchEnabled": true,
|
||||||
|
"splash": {
|
||||||
|
"image": "./assets/splash-icon.png",
|
||||||
|
"resizeMode": "contain",
|
||||||
|
"backgroundColor": "#ffffff"
|
||||||
|
},
|
||||||
|
"ios": {
|
||||||
|
"supportsTablet": true,
|
||||||
|
"bundleIdentifier": "com.anonymous.expoUsePushy"
|
||||||
|
},
|
||||||
|
"android": {
|
||||||
|
"adaptiveIcon": {
|
||||||
|
"foregroundImage": "./assets/adaptive-icon.png",
|
||||||
|
"backgroundColor": "#ffffff"
|
||||||
|
},
|
||||||
|
"package": "com.anonymous.expoUsePushy"
|
||||||
|
},
|
||||||
|
"web": {
|
||||||
|
"favicon": "./assets/favicon.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Example/expoUsePushy/assets/adaptive-icon.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
Example/expoUsePushy/assets/favicon.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
Example/expoUsePushy/assets/icon.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
Example/expoUsePushy/assets/shezhi.png
Normal file
|
After Width: | Height: | Size: 696 B |
BIN
Example/expoUsePushy/assets/shezhi@2x.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
Example/expoUsePushy/assets/shezhi@3x.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
Example/expoUsePushy/assets/splash-icon.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
2005
Example/expoUsePushy/bun.lock
Normal file
1
Example/expoUsePushy/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import 'expo-router/entry';
|
||||||
50
Example/expoUsePushy/package.json
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"name": "expousepushy",
|
||||||
|
"main": "index.js",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"start": "expo start",
|
||||||
|
"reset-project": "node ./scripts/reset-project.js",
|
||||||
|
"android": "expo run:android",
|
||||||
|
"ios": "expo run:ios",
|
||||||
|
"web": "expo start --web",
|
||||||
|
"lint": "expo lint"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@expo/vector-icons": "^14.1.0",
|
||||||
|
"@react-navigation/bottom-tabs": "^7.3.10",
|
||||||
|
"@react-navigation/elements": "^2.3.8",
|
||||||
|
"@react-navigation/native": "^7.1.6",
|
||||||
|
"expo": "~53.0.22",
|
||||||
|
"expo-blur": "~14.1.5",
|
||||||
|
"expo-constants": "~17.1.7",
|
||||||
|
"expo-font": "~13.3.2",
|
||||||
|
"expo-haptics": "~14.1.4",
|
||||||
|
"expo-image": "~2.4.0",
|
||||||
|
"expo-linking": "~7.1.7",
|
||||||
|
"expo-router": "~5.1.5",
|
||||||
|
"expo-splash-screen": "~0.30.10",
|
||||||
|
"expo-status-bar": "~2.2.3",
|
||||||
|
"expo-symbols": "~0.4.5",
|
||||||
|
"expo-system-ui": "~5.0.11",
|
||||||
|
"expo-web-browser": "~14.2.0",
|
||||||
|
"react": "19.0.0",
|
||||||
|
"react-dom": "19.0.0",
|
||||||
|
"react-native": "0.79.6",
|
||||||
|
"react-native-gesture-handler": "~2.24.0",
|
||||||
|
"react-native-reanimated": "~3.17.4",
|
||||||
|
"react-native-safe-area-context": "5.4.0",
|
||||||
|
"react-native-screens": "~4.11.1",
|
||||||
|
"react-native-update": "^10.34.4",
|
||||||
|
"react-native-web": "~0.20.0",
|
||||||
|
"react-native-webview": "13.13.5"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.25.2",
|
||||||
|
"@types/react": "~19.0.10",
|
||||||
|
"typescript": "~5.8.3",
|
||||||
|
"eslint": "^9.25.0",
|
||||||
|
"eslint-config-expo": "~9.2.0"
|
||||||
|
},
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
6
Example/expoUsePushy/tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "expo/tsconfig.base",
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Example/expoUsePushy/update.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"ios": {
|
||||||
|
"appId": 29439,
|
||||||
|
"appKey": "jNA71vpFHTDpEqeZd9yx87zj"
|
||||||
|
},
|
||||||
|
"android": {
|
||||||
|
"appId": 29413,
|
||||||
|
"appKey": "vdZWPXU6eyaPE6Avk96-YvwK"
|
||||||
|
},
|
||||||
|
"harmony": {
|
||||||
|
"appId": 29140,
|
||||||
|
"appKey": "JLklGflGIRbY-cMebjQwm1J1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "harmony_use_pushy",
|
"name": "harmony_use_pushy",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-native-oh/react-native-harmony": "^0.72.43",
|
"@react-native-oh/react-native-harmony": "^0.72.59",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-native": "0.72.5",
|
"react-native": "0.72.5",
|
||||||
"react-native-update": "^10.26.4",
|
"react-native-update": "^10.26.4",
|
||||||
|
|||||||
@@ -1,45 +1,49 @@
|
|||||||
{
|
{
|
||||||
"app": {
|
app: {
|
||||||
"signingConfigs": [],
|
signingConfigs: [],
|
||||||
"products": [
|
products: [
|
||||||
{
|
{
|
||||||
"name": "default",
|
name: 'default',
|
||||||
"signingConfig": "default",
|
signingConfig: 'default',
|
||||||
"compatibleSdkVersion": "5.0.0(12)",
|
compatibleSdkVersion: '5.0.0(12)',
|
||||||
"runtimeOS": "HarmonyOS",
|
runtimeOS: 'HarmonyOS',
|
||||||
"buildOption": {
|
buildOption: {
|
||||||
"strictMode": {
|
strictMode: {
|
||||||
"caseSensitiveCheck": true,
|
caseSensitiveCheck: true,
|
||||||
"useNormalizedOHMUrl": true
|
useNormalizedOHMUrl: true,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
"buildModeSet": [
|
buildModeSet: [
|
||||||
{
|
{
|
||||||
"name": "debug",
|
name: 'debug',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "release"
|
name: 'release',
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"modules": [
|
],
|
||||||
|
},
|
||||||
|
modules: [
|
||||||
{
|
{
|
||||||
"name": "entry",
|
name: 'entry',
|
||||||
"srcPath": "./entry",
|
srcPath: './entry',
|
||||||
"targets": [
|
targets: [
|
||||||
{
|
{
|
||||||
"name": "default",
|
name: 'default',
|
||||||
"applyToProducts": [
|
applyToProducts: ['default'],
|
||||||
"default"
|
},
|
||||||
]
|
],
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'pushy',
|
name: 'pushy',
|
||||||
srcPath: '../node_modules/react-native-update/harmony',
|
srcPath: '../../../harmony/pushy',
|
||||||
}
|
targets: [
|
||||||
]
|
{
|
||||||
|
name: 'default',
|
||||||
|
applyToProducts: ['default'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,26 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"stableOrder": true
|
"stableOrder": true,
|
||||||
|
"enableUnifiedLockfile": false
|
||||||
},
|
},
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||||
"specifiers": {
|
"specifiers": {
|
||||||
"@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38",
|
"@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38",
|
||||||
"pushy@../../node_modules/react-native-update/harmony": "pushy@../../node_modules/react-native-update/harmony"
|
"pushy@../../node_modules/react-native-update/harmony/pushy": "pushy@../../node_modules/react-native-update/harmony/pushy"
|
||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
"@rnoh/react-native-openharmony@0.72.38": {
|
"@rnoh/react-native-openharmony@0.72.38": {
|
||||||
"name": "@rnoh/react-native-openharmony",
|
"name": "",
|
||||||
"version": "0.72.38",
|
"version": "0.72.38",
|
||||||
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
|
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
|
||||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
|
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
|
||||||
"registryType": "ohpm"
|
"registryType": "ohpm"
|
||||||
},
|
},
|
||||||
"pushy@../../node_modules/react-native-update/harmony": {
|
"pushy@../../node_modules/react-native-update/harmony/pushy": {
|
||||||
"name": "pushy",
|
"name": "pushy",
|
||||||
"version": "3.1.0-0.0.7",
|
"version": "3.1.0-0.0.7",
|
||||||
"resolved": "../../node_modules/react-native-update/harmony",
|
"resolved": "",
|
||||||
"registryType": "local",
|
"registryType": "local",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rnoh/react-native-openharmony": "^0.72.38"
|
"@rnoh/react-native-openharmony": "^0.72.38"
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "entry",
|
name: 'entry',
|
||||||
"version": "1.0.0",
|
version: '1.0.0',
|
||||||
"description": "Please describe the basic information.",
|
description: 'Please describe the basic information.',
|
||||||
"main": "",
|
main: '',
|
||||||
"author": "",
|
author: '',
|
||||||
"license": "",
|
license: '',
|
||||||
"dependencies": {
|
dependencies: {
|
||||||
"@rnoh/react-native-openharmony": "0.72.38",
|
'@rnoh/react-native-openharmony': '0.72.38',
|
||||||
"pushy": "file:../../node_modules/react-native-update/harmony"
|
pushy: 'file:../../node_modules/react-native-update/harmony/pushy',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider';
|
import { PushyFileJSBundleProvider } from 'pushy/src/main/ets/PushyFileJSBundleProvider';
|
||||||
import { ComponentBuilderContext, RNOHCoreContext,RNAbility,
|
import { ComponentBuilderContext, RNOHCoreContext,RNAbility,
|
||||||
MetroJSBundleProvider } from '@rnoh/react-native-openharmony';
|
MetroJSBundleProvider } from '@rnoh/react-native-openharmony';
|
||||||
import {
|
import {
|
||||||
@@ -65,7 +65,7 @@ struct Index {
|
|||||||
// local debug mode
|
// local debug mode
|
||||||
new MetroJSBundleProvider(),
|
new MetroJSBundleProvider(),
|
||||||
// release mode
|
// release mode
|
||||||
new FileJSBundleProvider(this.rnohCoreContext.uiAbilityContext),
|
new PushyFileJSBundleProvider(this.rnohCoreContext.uiAbilityContext),
|
||||||
new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
|
new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
|
||||||
]),
|
]),
|
||||||
this.rnohCoreContext.logger),
|
this.rnohCoreContext.logger),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"pushy_build_time": "2025-04-12T11:12:43.423Z",
|
"pushy_build_time": "2025-04-30T02:46:33.340Z",
|
||||||
"versionName": "1.0.0"
|
"versionName": "1.0.0"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import {appTasks} from '@ohos/hvigor-ohos-plugin';
|
import {appTasks} from '@ohos/hvigor-ohos-plugin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
system: appTasks /* Built-in plugin of Hvigor. It cannot be modified. */,
|
||||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
plugins: [] /* Custom plugin to extend the functionality of Hvigor. */,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -15,10 +15,10 @@
|
|||||||
"hash": "pushy hash /Users/yanbo.he/Desktop/HarmonyOS/react-native-pushy/Example/harmony_use_pushy/.pushy/output/harmony.1735048297258.ppk"
|
"hash": "pushy hash /Users/yanbo.he/Desktop/HarmonyOS/react-native-pushy/Example/harmony_use_pushy/.pushy/output/harmony.1735048297258.ppk"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-native-oh/react-native-harmony": "^0.72.43",
|
"@react-native-oh/react-native-harmony": "^0.72.59",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-native": "0.72.5",
|
"react-native": "0.72.5",
|
||||||
"react-native-update": "^10.26.4"
|
"react-native-update": "latest"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.20.0",
|
"@babel/core": "^7.20.0",
|
||||||
|
|||||||
4
Example/testHotUpdate/.gitignore
vendored
@@ -62,3 +62,7 @@ buck-out/
|
|||||||
# Ruby / CocoaPods
|
# Ruby / CocoaPods
|
||||||
/ios/Pods/
|
/ios/Pods/
|
||||||
/vendor/bundle/
|
/vendor/bundle/
|
||||||
|
|
||||||
|
# react-native-update
|
||||||
|
.update
|
||||||
|
.pushy
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
arrowParens: 'avoid',
|
arrowParens: 'avoid',
|
||||||
bracketSameLine: true,
|
|
||||||
bracketSpacing: false,
|
|
||||||
singleQuote: true,
|
singleQuote: true,
|
||||||
trailingComma: 'all',
|
trailingComma: 'all',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ android {
|
|||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.81.4"
|
||||||
}
|
}
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
debug {
|
debug {
|
||||||
|
|||||||
@@ -5,13 +5,11 @@ import cn.reactnative.modules.update.UpdateContext
|
|||||||
import com.facebook.react.PackageList
|
import com.facebook.react.PackageList
|
||||||
import com.facebook.react.ReactApplication
|
import com.facebook.react.ReactApplication
|
||||||
import com.facebook.react.ReactHost
|
import com.facebook.react.ReactHost
|
||||||
|
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
|
||||||
import com.facebook.react.ReactNativeHost
|
import com.facebook.react.ReactNativeHost
|
||||||
import com.facebook.react.ReactPackage
|
import com.facebook.react.ReactPackage
|
||||||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
|
|
||||||
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
|
||||||
import com.facebook.react.defaults.DefaultReactNativeHost
|
import com.facebook.react.defaults.DefaultReactNativeHost
|
||||||
import com.facebook.react.soloader.OpenSourceMergedSoMapping
|
|
||||||
import com.facebook.soloader.SoLoader
|
|
||||||
|
|
||||||
class MainApplication : Application(), ReactApplication {
|
class MainApplication : Application(), ReactApplication {
|
||||||
|
|
||||||
@@ -39,10 +37,6 @@ class MainApplication : Application(), ReactApplication {
|
|||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
SoLoader.init(this, OpenSourceMergedSoMapping)
|
loadReactNative(this)
|
||||||
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
||||||
// If you opted-in for the New Architecture, we load the native entry point for this app.
|
|
||||||
load()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext {
|
ext {
|
||||||
buildToolsVersion = "35.0.0"
|
buildToolsVersion = "36.0.0"
|
||||||
minSdkVersion = 24
|
minSdkVersion = 24
|
||||||
compileSdkVersion = 35
|
compileSdkVersion = 36
|
||||||
targetSdkVersion = 35
|
targetSdkVersion = 36
|
||||||
ndkVersion = "27.1.12297006"
|
ndkVersion = "27.1.12297006"
|
||||||
kotlinVersion = "2.0.21"
|
kotlinVersion = "2.1.20"
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ android.useAndroidX=true
|
|||||||
# Use this property to specify which architecture you want to build.
|
# Use this property to specify which architecture you want to build.
|
||||||
# You can also override it from the CLI using
|
# You can also override it from the CLI using
|
||||||
# ./gradlew <task> -PreactNativeArchitectures=x86_64
|
# ./gradlew <task> -PreactNativeArchitectures=x86_64
|
||||||
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
|
# reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
|
||||||
|
reactNativeArchitectures=arm64-v8a
|
||||||
|
|
||||||
# Use this property to enable support to the new architecture.
|
# Use this property to enable support to the new architecture.
|
||||||
# This will allow you to use TurboModules and the Fabric render in
|
# This will allow you to use TurboModules and the Fabric render in
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
6
Example/testHotUpdate/android/gradlew
vendored
@@ -114,7 +114,7 @@ case "$( uname )" in #(
|
|||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH="\\\"\\\""
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@@ -205,7 +205,7 @@ fi
|
|||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
# Collect all arguments for the java command:
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
# and any embedded shellness will be escaped.
|
# and any embedded shellness will be escaped.
|
||||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
# treated as '${Hostname}' itself on the command line.
|
# treated as '${Hostname}' itself on the command line.
|
||||||
@@ -213,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-classpath "$CLASSPATH" \
|
-classpath "$CLASSPATH" \
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
# Stop when "xargs" is not available.
|
||||||
|
|||||||
9
Example/testHotUpdate/android/gradlew.bat
vendored
@@ -1,3 +1,8 @@
|
|||||||
|
@REM Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
@REM
|
||||||
|
@REM This source code is licensed under the MIT license found in the
|
||||||
|
@REM LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
@rem
|
@rem
|
||||||
@rem Copyright 2015 the original author or authors.
|
@rem Copyright 2015 the original author or authors.
|
||||||
@rem
|
@rem
|
||||||
@@ -70,11 +75,11 @@ goto fail
|
|||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
|||||||
@@ -403,6 +403,8 @@
|
|||||||
"-DFOLLY_NO_CONFIG",
|
"-DFOLLY_NO_CONFIG",
|
||||||
"-DFOLLY_MOBILE=1",
|
"-DFOLLY_MOBILE=1",
|
||||||
"-DFOLLY_USE_LIBCPP=1",
|
"-DFOLLY_USE_LIBCPP=1",
|
||||||
|
"-DFOLLY_CFG_NO_COROUTINES=1",
|
||||||
|
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
|
||||||
);
|
);
|
||||||
OTHER_LDFLAGS = "$(inherited)";
|
OTHER_LDFLAGS = "$(inherited)";
|
||||||
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
||||||
@@ -475,6 +477,8 @@
|
|||||||
"-DFOLLY_NO_CONFIG",
|
"-DFOLLY_NO_CONFIG",
|
||||||
"-DFOLLY_MOBILE=1",
|
"-DFOLLY_MOBILE=1",
|
||||||
"-DFOLLY_USE_LIBCPP=1",
|
"-DFOLLY_USE_LIBCPP=1",
|
||||||
|
"-DFOLLY_CFG_NO_COROUTINES=1",
|
||||||
|
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
|
||||||
);
|
);
|
||||||
OTHER_LDFLAGS = "$(inherited)";
|
OTHER_LDFLAGS = "$(inherited)";
|
||||||
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
||||||
|
|||||||
@@ -2,12 +2,14 @@
|
|||||||
#import "RCTPushy.h"
|
#import "RCTPushy.h"
|
||||||
|
|
||||||
#import <React/RCTBundleURLProvider.h>
|
#import <React/RCTBundleURLProvider.h>
|
||||||
|
#import <ReactAppDependencyProvider/RCTAppDependencyProvider.h>
|
||||||
|
|
||||||
@implementation AppDelegate
|
@implementation AppDelegate
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||||
{
|
{
|
||||||
self.moduleName = @"AwesomeProject";
|
self.moduleName = @"AwesomeProject";
|
||||||
|
self.dependencyProvider = [RCTAppDependencyProvider new];
|
||||||
// You can add your custom initial props in the dictionary below.
|
// You can add your custom initial props in the dictionary below.
|
||||||
// They will be passed down to the ViewController used by React Native.
|
// They will be passed down to the ViewController used by React Native.
|
||||||
self.initialProps = @{};
|
self.initialProps = @{};
|
||||||
|
|||||||
@@ -37,8 +37,14 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
<key>NSCameraUsageDescription</key>
|
||||||
|
<string>For taking photos</string>
|
||||||
<key>NSLocationWhenInUseUsageDescription</key>
|
<key>NSLocationWhenInUseUsageDescription</key>
|
||||||
<string></string>
|
<string></string>
|
||||||
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
|
<string>For saving photos</string>
|
||||||
|
<key>RCTNewArchEnabled</key>
|
||||||
|
<true/>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
<string>LaunchScreen</string>
|
<string>LaunchScreen</string>
|
||||||
<key>UIRequiredDeviceCapabilities</key>
|
<key>UIRequiredDeviceCapabilities</key>
|
||||||
@@ -53,10 +59,5 @@
|
|||||||
</array>
|
</array>
|
||||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>NSCameraUsageDescription</key>
|
|
||||||
<string>For taking photos</string>
|
|
||||||
|
|
||||||
<key>NSPhotoLibraryUsageDescription</key>
|
|
||||||
<string>For saving photos</string>
|
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -10,43 +10,42 @@
|
|||||||
"test:e2e": "detox test --configuration android.emu.debug",
|
"test:e2e": "detox test --configuration android.emu.debug",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"postinstall": "patch-package",
|
"postinstall": "patch-package",
|
||||||
"apk": "cd android && ./gradlew assembleRelease",
|
"apk": "cd android && ./gradlew assembleRelease"
|
||||||
"dev:harmony": "react-native bundle-harmony --dev"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"form-data": "^4.0.2",
|
"form-data": "^4.0.4",
|
||||||
"patch-package": "^8.0.0",
|
"patch-package": "^8.0.0",
|
||||||
"react": "19.0.0",
|
"react": "19.1.0",
|
||||||
"react-native": "0.78.0",
|
"react-native": "0.81.4",
|
||||||
"react-native-camera-kit": "^14.2.0",
|
"react-native-camera-kit": "^16.1.2",
|
||||||
"react-native-paper": "^5.13.1",
|
"react-native-paper": "^5.14.5",
|
||||||
"react-native-safe-area-context": "^5.3.0",
|
"react-native-safe-area-context": "^5.6.1",
|
||||||
"react-native-svg": "^15.11.2",
|
"react-native-svg": "^15.13.0",
|
||||||
"react-native-update": "^10.26.4",
|
"react-native-update": "^10.34.4",
|
||||||
"react-native-vector-icons": "^10.2.0"
|
"react-native-vector-icons": "^10.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.26.0",
|
"@babel/core": "^7.27.3",
|
||||||
"@babel/preset-env": "^7.26.0",
|
"@babel/preset-env": "^7.27.2",
|
||||||
"@babel/runtime": "^7.26.0",
|
"@babel/runtime": "^7.27.3",
|
||||||
"@react-native-community/cli": "15.0.1",
|
"@react-native-community/cli": "20.0.0",
|
||||||
"@react-native-community/cli-platform-android": "15.0.1",
|
"@react-native-community/cli-platform-android": "20.0.0",
|
||||||
"@react-native-community/cli-platform-ios": "15.0.1",
|
"@react-native-community/cli-platform-ios": "20.0.0",
|
||||||
"@react-native/babel-preset": "0.78.0",
|
"@react-native/babel-preset": "0.81.4",
|
||||||
"@react-native/eslint-config": "0.78.0",
|
"@react-native/eslint-config": "0.81.4",
|
||||||
"@react-native/metro-config": "0.78.0",
|
"@react-native/metro-config": "0.81.4",
|
||||||
"@react-native/typescript-config": "0.78.0",
|
"@react-native/typescript-config": "0.81.4",
|
||||||
"@types/react": "^19.0.0",
|
"@types/react": "^19.1.13",
|
||||||
"@types/react-test-renderer": "^19.0.0",
|
"@types/react-test-renderer": "^19.1.0",
|
||||||
"detox": "^20.32.0",
|
"detox": "^20.41.2",
|
||||||
"eslint": "^8.19.0",
|
"eslint": "^9.35.0",
|
||||||
"jest": "^29.6.3",
|
"jest": "^29.6.3",
|
||||||
"prettier": "2.8.8",
|
"prettier": "2.8.8",
|
||||||
"react-test-renderer": "19.0.0",
|
"react-test-renderer": "19.1.1",
|
||||||
"typescript": "5.8.2"
|
"typescript": "5.8.3"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=20"
|
||||||
},
|
},
|
||||||
"trustedDependencies": [
|
"trustedDependencies": [
|
||||||
"detox",
|
"detox",
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ function App() {
|
|||||||
currentHash,
|
currentHash,
|
||||||
parseTestQrCode,
|
parseTestQrCode,
|
||||||
progress: { received, total } = {},
|
progress: { received, total } = {},
|
||||||
|
currentVersionInfo,
|
||||||
} = useUpdate();
|
} = useUpdate();
|
||||||
const [useDefaultAlert, setUseDefaultAlert] = useState(true);
|
const [useDefaultAlert, setUseDefaultAlert] = useState(true);
|
||||||
const [showTestConsole, setShowTestConsole] = useState(false);
|
const [showTestConsole, setShowTestConsole] = useState(false);
|
||||||
@@ -52,7 +53,7 @@ function App() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcome}>欢迎使用Pushy热更新服务</Text>
|
<Text style={styles.welcome}>欢迎22使用Pushy热更新服务</Text>
|
||||||
<View style={{ flexDirection: 'row' }}>
|
<View style={{ flexDirection: 'row' }}>
|
||||||
<Text>
|
<Text>
|
||||||
{useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示
|
{useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示
|
||||||
@@ -113,6 +114,7 @@ function App() {
|
|||||||
{'\n'}
|
{'\n'}
|
||||||
当前热更新版本Hash: {currentHash || '(空)'}
|
当前热更新版本Hash: {currentHash || '(空)'}
|
||||||
{'\n'}
|
{'\n'}
|
||||||
|
当前热更新版本信息: {JSON.stringify(currentVersionInfo) || '(空)'}
|
||||||
</Text>
|
</Text>
|
||||||
<Text>
|
<Text>
|
||||||
下载进度:{received} / {total}
|
下载进度:{received} / {total}
|
||||||
@@ -121,7 +123,8 @@ function App() {
|
|||||||
onPress={() => {
|
onPress={() => {
|
||||||
checkUpdate();
|
checkUpdate();
|
||||||
setShowUpdateSnackbar(true);
|
setShowUpdateSnackbar(true);
|
||||||
}}>
|
}}
|
||||||
|
>
|
||||||
<Text style={styles.instructions}>点击这里检查更新</Text>
|
<Text style={styles.instructions}>点击这里检查更新</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
|
||||||
@@ -130,7 +133,8 @@ function App() {
|
|||||||
style={{ marginTop: 15 }}
|
style={{ marginTop: 15 }}
|
||||||
onLongPress={() => {
|
onLongPress={() => {
|
||||||
setShowTestConsole(true);
|
setShowTestConsole(true);
|
||||||
}}>
|
}}
|
||||||
|
>
|
||||||
<Text style={styles.instructions}>
|
<Text style={styles.instructions}>
|
||||||
react-native-update版本:{client?.version}
|
react-native-update版本:{client?.version}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -152,7 +156,8 @@ function App() {
|
|||||||
await downloadUpdate();
|
await downloadUpdate();
|
||||||
setShowUpdateBanner(true);
|
setShowUpdateBanner(true);
|
||||||
},
|
},
|
||||||
}}>
|
}}
|
||||||
|
>
|
||||||
<Text style={{ color: 'white' }}>
|
<Text style={{ color: 'white' }}>
|
||||||
有新版本({updateInfo.name})可用,是否更新?
|
有新版本({updateInfo.name})可用,是否更新?
|
||||||
</Text>
|
</Text>
|
||||||
@@ -176,7 +181,8 @@ function App() {
|
|||||||
]}
|
]}
|
||||||
icon={({ size }) => (
|
icon={({ size }) => (
|
||||||
<Icon name="checkcircleo" size={size} color="#00f" />
|
<Icon name="checkcircleo" size={size} color="#00f" />
|
||||||
)}>
|
)}
|
||||||
|
>
|
||||||
更新已完成,是否立即重启?
|
更新已完成,是否立即重启?
|
||||||
</Banner>
|
</Banner>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
5
Example/testHotUpdate/tsconfig.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"extends": "@react-native/typescript-config",
|
||||||
|
"include": ["**/*.ts", "**/*.tsx"],
|
||||||
|
"exclude": ["**/node_modules", "**/Pods"]
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"ios": {
|
"ios": {
|
||||||
"appId": 24794,
|
"appId": 28943,
|
||||||
"appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T"
|
"appKey": "d-OmPxIBivPrDfKhLHjxN-HS"
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
"appId": 27509,
|
"appId": 27509,
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ if (expoProject) {
|
|||||||
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
||||||
apply from: expoModulesCorePlugin
|
apply from: expoModulesCorePlugin
|
||||||
applyKotlinExpoModulesCorePlugin()
|
applyKotlinExpoModulesCorePlugin()
|
||||||
useExpoPublishing()
|
// useExpoPublishing()
|
||||||
useCoreDependencies()
|
useCoreDependencies()
|
||||||
} else {
|
} else {
|
||||||
group = 'cn.reactnative.modules.update'
|
group = 'cn.reactnative.modules.update'
|
||||||
@@ -101,7 +101,7 @@ android {
|
|||||||
minSdkVersion safeExtGet('minSdkVersion', 16)
|
minSdkVersion safeExtGet('minSdkVersion', 16)
|
||||||
targetSdkVersion safeExtGet('targetSdkVersion', 27)
|
targetSdkVersion safeExtGet('targetSdkVersion', 27)
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.81.4"
|
||||||
consumerProguardFiles "proguard.pro"
|
consumerProguardFiles "proguard.pro"
|
||||||
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,6 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.facebook.react:react-native:+'
|
implementation 'com.facebook.react:react-native:+'
|
||||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
|
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
|
||||||
implementation 'com.jakewharton:process-phoenix:3.0.0'
|
|
||||||
}
|
}
|
||||||
if (isNewArchitectureEnabled()) {
|
if (isNewArchitectureEnabled()) {
|
||||||
react {
|
react {
|
||||||
|
|||||||
15
android/proguard.pro
vendored
@@ -1,3 +1,18 @@
|
|||||||
|
# Keep our update module classes
|
||||||
-keepnames class cn.reactnative.modules.update.DownloadTask { *; }
|
-keepnames class cn.reactnative.modules.update.DownloadTask { *; }
|
||||||
-keepnames class cn.reactnative.modules.update.UpdateModuleImpl { *; }
|
-keepnames class cn.reactnative.modules.update.UpdateModuleImpl { *; }
|
||||||
|
-keepnames class cn.reactnative.modules.update.** { *; }
|
||||||
|
|
||||||
|
# Keep React Native classes
|
||||||
-keepnames class com.facebook.react.ReactInstanceManager { *; }
|
-keepnames class com.facebook.react.ReactInstanceManager { *; }
|
||||||
|
-keepnames class com.facebook.react.** { *; }
|
||||||
|
-keepnames class com.facebook.react.bridge.** { *; }
|
||||||
|
-keepnames class com.facebook.react.devsupport.** { *; }
|
||||||
|
|
||||||
|
# Keep fields used in reflection
|
||||||
|
-keepclassmembers class com.facebook.react.ReactActivity { *; }
|
||||||
|
-keepclassmembers class com.facebook.react.ReactInstanceManager { *; }
|
||||||
|
-keepclassmembers class com.facebook.react.ReactDelegate { *; }
|
||||||
|
-keepclassmembers class com.facebook.react.ReactHost { *; }
|
||||||
|
|
||||||
|
-keepnames class expo.modules.ExpoReactHostFactory$ExpoReactHostDelegate { *; }
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.CRC32;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
@@ -198,6 +199,10 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|||||||
return fout.toByteArray();
|
return fout.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getCRC32AsDecimal(long crc32Value) {
|
||||||
|
return String.valueOf(crc32Value & 0xFFFFFFFFL);
|
||||||
|
}
|
||||||
|
|
||||||
private void copyFilesWithBlacklist(String current, File from, File to, JSONObject blackList) throws IOException {
|
private void copyFilesWithBlacklist(String current, File from, File to, JSONObject blackList) throws IOException {
|
||||||
File[] files = from.listFiles();
|
File[] files = from.listFiles();
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
@@ -273,12 +278,41 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|||||||
zipFile.close();
|
zipFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void copyFromResourceV2(HashMap<String, ArrayList<File>> resToCopy2) throws IOException {
|
||||||
|
SafeZipFile zipFile = new SafeZipFile(new File(context.getPackageResourcePath()));
|
||||||
|
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
ZipEntry ze = entries.nextElement();
|
||||||
|
String fn = ze.getName();
|
||||||
|
long zipCrc32 = ze.getCrc();
|
||||||
|
String crc32Decimal = getCRC32AsDecimal(zipCrc32);
|
||||||
|
ArrayList<File> targets = resToCopy2.get(crc32Decimal);
|
||||||
|
if (targets != null) {
|
||||||
|
File lastTarget = null;
|
||||||
|
for (File target: targets) {
|
||||||
|
if (UpdateContext.DEBUG) {
|
||||||
|
Log.d("react-native-update", "Copying from resource " + fn + " to " + target);
|
||||||
|
}
|
||||||
|
if (lastTarget != null) {
|
||||||
|
copyFile(lastTarget, target);
|
||||||
|
} else {
|
||||||
|
zipFile.unzipToFile(ze, target);
|
||||||
|
lastTarget = target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zipFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
private void doPatchFromApk(DownloadTaskParams param) throws IOException, JSONException {
|
private void doPatchFromApk(DownloadTaskParams param) throws IOException, JSONException {
|
||||||
downloadFile(param);
|
downloadFile(param);
|
||||||
|
|
||||||
removeDirectory(param.unzipDirectory);
|
removeDirectory(param.unzipDirectory);
|
||||||
param.unzipDirectory.mkdirs();
|
param.unzipDirectory.mkdirs();
|
||||||
HashMap<String, ArrayList<File>> copyList = new HashMap<String, ArrayList<File>>();
|
HashMap<String, ArrayList<File>> copyList = new HashMap<String, ArrayList<File>>();
|
||||||
|
HashMap<String, ArrayList<File>> copiesv2List = new HashMap<String, ArrayList<File>>();
|
||||||
|
Boolean isV2 = false;
|
||||||
|
|
||||||
boolean foundDiff = false;
|
boolean foundDiff = false;
|
||||||
boolean foundBundlePatch = false;
|
boolean foundBundlePatch = false;
|
||||||
@@ -297,7 +331,35 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|||||||
JSONObject obj = (JSONObject)new JSONTokener(json).nextValue();
|
JSONObject obj = (JSONObject)new JSONTokener(json).nextValue();
|
||||||
|
|
||||||
JSONObject copies = obj.getJSONObject("copies");
|
JSONObject copies = obj.getJSONObject("copies");
|
||||||
|
JSONObject copiesv2 = obj.getJSONObject("copiesv2");
|
||||||
Iterator<?> keys = copies.keys();
|
Iterator<?> keys = copies.keys();
|
||||||
|
Iterator<?> keysV2 = copiesv2.keys();
|
||||||
|
if(keysV2.hasNext()){
|
||||||
|
isV2 = true;
|
||||||
|
while( keysV2.hasNext() ) {
|
||||||
|
String from = (String)keysV2.next();
|
||||||
|
String to = copiesv2.getString(from);
|
||||||
|
if (from.isEmpty()) {
|
||||||
|
from = to;
|
||||||
|
}
|
||||||
|
ArrayList<File> target = null;
|
||||||
|
if (!copiesv2List.containsKey(from)) {
|
||||||
|
target = new ArrayList<File>();
|
||||||
|
copiesv2List.put(from, target);
|
||||||
|
} else {
|
||||||
|
target = copiesv2List.get((from));
|
||||||
|
}
|
||||||
|
File toFile = new File(param.unzipDirectory, to);
|
||||||
|
|
||||||
|
// Fixing a Zip Path Traversal Vulnerability
|
||||||
|
// https://support.google.com/faqs/answer/9294009
|
||||||
|
String canonicalPath = toFile.getCanonicalPath();
|
||||||
|
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) {
|
||||||
|
throw new SecurityException("Illegal name: " + to);
|
||||||
|
}
|
||||||
|
target.add(toFile);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
while( keys.hasNext() ) {
|
while( keys.hasNext() ) {
|
||||||
String to = (String)keys.next();
|
String to = (String)keys.next();
|
||||||
String from = copies.getString(to);
|
String from = copies.getString(to);
|
||||||
@@ -321,6 +383,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|||||||
}
|
}
|
||||||
target.add(toFile);
|
target.add(toFile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (fn.equals("index.bundlejs.patch")) {
|
if (fn.equals("index.bundlejs.patch")) {
|
||||||
@@ -348,7 +411,11 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
|||||||
throw new Error("bundle patch not found");
|
throw new Error("bundle patch not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isV2){
|
||||||
|
copyFromResourceV2(copiesv2List);
|
||||||
|
}else{
|
||||||
copyFromResource(copyList);
|
copyFromResource(copyList);
|
||||||
|
}
|
||||||
|
|
||||||
if (UpdateContext.DEBUG) {
|
if (UpdateContext.DEBUG) {
|
||||||
Log.d("react-native-update", "Unzip finished");
|
Log.d("react-native-update", "Unzip finished");
|
||||||
|
|||||||
@@ -36,10 +36,28 @@ public class UpdateContext {
|
|||||||
this.sp = context.getSharedPreferences("update", Context.MODE_PRIVATE);
|
this.sp = context.getSharedPreferences("update", Context.MODE_PRIVATE);
|
||||||
|
|
||||||
String packageVersion = getPackageVersion();
|
String packageVersion = getPackageVersion();
|
||||||
if (!packageVersion.equals(this.sp.getString("packageVersion", null))) {
|
String buildTime = getBuildTime();
|
||||||
|
String storedPackageVersion = this.sp.getString("packageVersion", null);
|
||||||
|
String storedBuildTime = this.sp.getString("buildTime", null);
|
||||||
|
|
||||||
|
// If stored versions don't exist, write current versions first
|
||||||
|
if (storedPackageVersion == null || storedBuildTime == null) {
|
||||||
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
|
editor.putString("packageVersion", packageVersion);
|
||||||
|
editor.putString("buildTime", buildTime);
|
||||||
|
editor.apply();
|
||||||
|
storedPackageVersion = packageVersion;
|
||||||
|
storedBuildTime = buildTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean packageVersionChanged = !packageVersion.equals(storedPackageVersion);
|
||||||
|
boolean buildTimeChanged = !buildTime.equals(storedBuildTime);
|
||||||
|
|
||||||
|
if (packageVersionChanged || buildTimeChanged) {
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
editor.clear();
|
editor.clear();
|
||||||
editor.putString("packageVersion", packageVersion);
|
editor.putString("packageVersion", packageVersion);
|
||||||
|
editor.putString("buildTime", buildTime);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
|
||||||
this.cleanUp();
|
this.cleanUp();
|
||||||
@@ -169,6 +187,7 @@ public class UpdateContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void markSuccess() {
|
public void markSuccess() {
|
||||||
|
if (!BuildConfig.DEBUG) {
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
editor.putBoolean("firstTimeOk", true);
|
editor.putBoolean("firstTimeOk", true);
|
||||||
String lastVersion = sp.getString("lastVersion", null);
|
String lastVersion = sp.getString("lastVersion", null);
|
||||||
@@ -181,6 +200,7 @@ public class UpdateContext {
|
|||||||
|
|
||||||
this.cleanUp();
|
this.cleanUp();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void clearFirstTime() {
|
public void clearFirstTime() {
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
|
|||||||
@@ -24,6 +24,38 @@ public class UpdateModuleImpl {
|
|||||||
|
|
||||||
public static final String NAME = "Pushy";
|
public static final String NAME = "Pushy";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字段的兼容性方法,尝试带m前缀和不带m前缀的字段名
|
||||||
|
* @param clazz 目标类
|
||||||
|
* @param fieldName 基础字段名(不带m前缀)
|
||||||
|
* @return 找到的字段对象
|
||||||
|
* @throws NoSuchFieldException 如果两种命名都找不到字段
|
||||||
|
*/
|
||||||
|
private static Field getCompatibleField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
|
||||||
|
// 首先尝试带m前缀的字段名
|
||||||
|
try {
|
||||||
|
return clazz.getDeclaredField("m" + capitalize(fieldName));
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// 如果找不到带m前缀的,尝试不带m前缀的
|
||||||
|
try {
|
||||||
|
return clazz.getDeclaredField(fieldName);
|
||||||
|
} catch (NoSuchFieldException e2) {
|
||||||
|
// 如果都找不到,抛出异常并包含两种尝试的信息
|
||||||
|
throw new NoSuchFieldException("Field not found with either name: m" + capitalize(fieldName) + " or " + fieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首字母大写的辅助方法
|
||||||
|
*/
|
||||||
|
private static String capitalize(String str) {
|
||||||
|
if (str == null || str.length() == 0) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
public static void downloadFullUpdate(UpdateContext updateContext, final ReadableMap options, final Promise promise) {
|
public static void downloadFullUpdate(UpdateContext updateContext, final ReadableMap options, final Promise promise) {
|
||||||
String url = options.getString("updateUrl");
|
String url = options.getString("updateUrl");
|
||||||
String hash = options.getString("hash");
|
String hash = options.getString("hash");
|
||||||
@@ -143,17 +175,26 @@ public class UpdateModuleImpl {
|
|||||||
ReactDelegate reactDelegate = (ReactDelegate)
|
ReactDelegate reactDelegate = (ReactDelegate)
|
||||||
getReactDelegateMethod.invoke(currentActivity);
|
getReactDelegateMethod.invoke(currentActivity);
|
||||||
|
|
||||||
Field reactHostField = ReactDelegate.class.getDeclaredField("mReactHost");
|
Field reactHostField = getCompatibleField(ReactDelegate.class, "reactHost");
|
||||||
reactHostField.setAccessible(true);
|
reactHostField.setAccessible(true);
|
||||||
Object reactHost = reactHostField.get(reactDelegate);
|
Object reactHost = reactHostField.get(reactDelegate);
|
||||||
|
|
||||||
// Access the mReactHostDelegate field
|
Field devSupport = getCompatibleField(reactHost.getClass(), "useDevSupport");
|
||||||
Field reactHostDelegateField = reactHost.getClass().getDeclaredField("mReactHostDelegate");
|
devSupport.setAccessible(true);
|
||||||
|
devSupport.set(reactHost, false);
|
||||||
|
|
||||||
|
// Access the ReactHostDelegate field (compatible with mReactHostDelegate/reactHostDelegate)
|
||||||
|
Field reactHostDelegateField = getCompatibleField(reactHost.getClass(), "reactHostDelegate");
|
||||||
reactHostDelegateField.setAccessible(true);
|
reactHostDelegateField.setAccessible(true);
|
||||||
Object reactHostDelegate = reactHostDelegateField.get(reactHost);
|
Object reactHostDelegate = reactHostDelegateField.get(reactHost);
|
||||||
|
|
||||||
|
String bundleFieldName = "jsBundleLoader";
|
||||||
|
if (reactHostDelegate.getClass().getCanonicalName().equals("expo.modules.ExpoReactHostFactory.ExpoReactHostDelegate")) {
|
||||||
|
bundleFieldName = "_jsBundleLoader";
|
||||||
|
}
|
||||||
|
|
||||||
// Modify the jsBundleLoader field
|
// Modify the jsBundleLoader field
|
||||||
Field jsBundleLoaderField = reactHostDelegate.getClass().getDeclaredField("jsBundleLoader");
|
Field jsBundleLoaderField = reactHostDelegate.getClass().getDeclaredField(bundleFieldName);
|
||||||
jsBundleLoaderField.setAccessible(true);
|
jsBundleLoaderField.setAccessible(true);
|
||||||
jsBundleLoaderField.set(reactHostDelegate, loader);
|
jsBundleLoaderField.set(reactHostDelegate, loader);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import static androidx.core.content.FileProvider.getUriForFile;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import com.facebook.react.bridge.Promise;
|
import com.facebook.react.bridge.Promise;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContext;
|
import com.facebook.react.bridge.ReactContext;
|
||||||
@@ -17,6 +19,7 @@ import java.util.Map;
|
|||||||
public class UpdateModule extends NativePushySpec {
|
public class UpdateModule extends NativePushySpec {
|
||||||
UpdateContext updateContext;
|
UpdateContext updateContext;
|
||||||
public static ReactApplicationContext mContext;
|
public static ReactApplicationContext mContext;
|
||||||
|
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||||
public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) {
|
public UpdateModule(ReactApplicationContext reactContext, UpdateContext updateContext) {
|
||||||
super(reactContext);
|
super(reactContext);
|
||||||
this.updateContext = updateContext;
|
this.updateContext = updateContext;
|
||||||
@@ -32,19 +35,31 @@ public class UpdateModule extends NativePushySpec {
|
|||||||
final Map<String, Object> constants = new HashMap<>();
|
final Map<String, Object> constants = new HashMap<>();
|
||||||
constants.put("downloadRootDir", updateContext.getRootDir());
|
constants.put("downloadRootDir", updateContext.getRootDir());
|
||||||
constants.put("packageVersion", updateContext.getPackageVersion());
|
constants.put("packageVersion", updateContext.getPackageVersion());
|
||||||
constants.put("currentVersion", updateContext.getCurrentVersion());
|
String currentVersion = updateContext.getCurrentVersion();
|
||||||
|
constants.put("currentVersion", currentVersion);
|
||||||
|
constants.put("currentVersionInfo", updateContext.getKv("hash_" + currentVersion));
|
||||||
constants.put("buildTime", updateContext.getBuildTime());
|
constants.put("buildTime", updateContext.getBuildTime());
|
||||||
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
||||||
boolean isFirstTime = updateContext.isFirstTime();
|
boolean isFirstTime = updateContext.isFirstTime();
|
||||||
constants.put("isFirstTime", isFirstTime);
|
constants.put("isFirstTime", isFirstTime);
|
||||||
if (isFirstTime) {
|
if (isFirstTime) {
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
updateContext.clearFirstTime();
|
updateContext.clearFirstTime();
|
||||||
}
|
}
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
String rolledBackVersion = updateContext.rolledBackVersion();
|
String rolledBackVersion = updateContext.rolledBackVersion();
|
||||||
constants.put("rolledBackVersion", rolledBackVersion);
|
constants.put("rolledBackVersion", rolledBackVersion);
|
||||||
if (rolledBackVersion != null) {
|
if (rolledBackVersion != null) {
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
updateContext.clearRollbackMark();
|
updateContext.clearRollbackMark();
|
||||||
}
|
}
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
constants.put("uuid", updateContext.getKv("uuid"));
|
constants.put("uuid", updateContext.getKv("uuid"));
|
||||||
return constants;
|
return constants;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import com.facebook.react.bridge.UiThreadUtil;
|
|||||||
import com.facebook.react.bridge.JSBundleLoader;
|
import com.facebook.react.bridge.JSBundleLoader;
|
||||||
import com.facebook.react.bridge.WritableMap;
|
import com.facebook.react.bridge.WritableMap;
|
||||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||||
import com.jakewharton.processphoenix.ProcessPhoenix;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -49,7 +48,9 @@ public class UpdateModule extends ReactContextBaseJavaModule {
|
|||||||
final Map<String, Object> constants = new HashMap<>();
|
final Map<String, Object> constants = new HashMap<>();
|
||||||
constants.put("downloadRootDir", updateContext.getRootDir());
|
constants.put("downloadRootDir", updateContext.getRootDir());
|
||||||
constants.put("packageVersion", updateContext.getPackageVersion());
|
constants.put("packageVersion", updateContext.getPackageVersion());
|
||||||
constants.put("currentVersion", updateContext.getCurrentVersion());
|
String currentVersion = updateContext.getCurrentVersion();
|
||||||
|
constants.put("currentVersion", currentVersion);
|
||||||
|
constants.put("currentVersionInfo", updateContext.getKv("hash_" + currentVersion));
|
||||||
constants.put("buildTime", updateContext.getBuildTime());
|
constants.put("buildTime", updateContext.getBuildTime());
|
||||||
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
||||||
boolean isFirstTime = updateContext.isFirstTime();
|
boolean isFirstTime = updateContext.isFirstTime();
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
["https://pushy-koa-qgbgqmcpis.cn-beijing.fcapp.run", "https://p.reactnative.cn/api"]
|
["https://p.reactnative.cn/api"]
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../harmony/oh_modules/.ohpm/@rnoh+react-native-openharmony@0.72.38/oh_modules/@rnoh/react-native-openharmony
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
"stableOrder": true
|
"stableOrder": true,
|
||||||
|
"enableUnifiedLockfile": false
|
||||||
},
|
},
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
"@rnoh/react-native-openharmony@0.72.38": {
|
"@rnoh/react-native-openharmony@0.72.38": {
|
||||||
"name": "@rnoh/react-native-openharmony",
|
"name": "",
|
||||||
"version": "0.72.38",
|
"version": "0.72.38",
|
||||||
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
|
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
|
||||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
|
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"types": "",
|
"types": "",
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"name": "pushy",
|
"name": "pushy",
|
||||||
@@ -8,5 +8,6 @@
|
|||||||
"version": "3.1.0-0.0.7",
|
"version": "3.1.0-0.0.7",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rnoh/react-native-openharmony":"^0.72.38"
|
"@rnoh/react-native-openharmony":"^0.72.38"
|
||||||
}
|
},
|
||||||
|
"modelVersion": "5.0.0"
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPpk(
|
|||||||
const jsi::Value* args,
|
const jsi::Value* args,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"downloadPatchFromPpk", args, count));
|
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadPatchFromPpk", args, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPackage(
|
static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPackage(
|
||||||
@@ -82,7 +82,7 @@ static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPackage(
|
|||||||
const jsi::Value* args,
|
const jsi::Value* args,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"downloadPatchFromPackage", args, count));
|
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadPatchFromPackage", args, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
static jsi::Value _hostFunction_PushyTurboModule_downloadFullUpdate(
|
static jsi::Value _hostFunction_PushyTurboModule_downloadFullUpdate(
|
||||||
@@ -91,7 +91,7 @@ static jsi::Value _hostFunction_PushyTurboModule_downloadFullUpdate(
|
|||||||
const jsi::Value* args,
|
const jsi::Value* args,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"downloadFullUpdate", args, count));
|
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadFullUpdate", args, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
static jsi::Value _hostFunction_PushyTurboModule_downloadAndInstallApk(
|
static jsi::Value _hostFunction_PushyTurboModule_downloadAndInstallApk(
|
||||||
@@ -100,7 +100,7 @@ static jsi::Value _hostFunction_PushyTurboModule_downloadAndInstallApk(
|
|||||||
const jsi::Value* args,
|
const jsi::Value* args,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"downloadAndInstallApk", args, count));
|
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadAndInstallApk", args, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ export class DownloadTask {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (response.responseCode > 299) {
|
if (response.responseCode > 299) {
|
||||||
throw new Error(`Server error: ${response.responseCode}`);
|
throw Error(`Server error: ${response.responseCode}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentLength = parseInt(response.header['content-length'] || '0');
|
const contentLength = parseInt(response.header['content-length'] || '0');
|
||||||
@@ -108,9 +108,10 @@ export class DownloadTask {
|
|||||||
const stats = await fileIo.stat(params.targetFile);
|
const stats = await fileIo.stat(params.targetFile);
|
||||||
const fileSize = stats.size;
|
const fileSize = stats.size;
|
||||||
if (fileSize !== contentLength) {
|
if (fileSize !== contentLength) {
|
||||||
throw new Error(`Download incomplete: expected ${contentLength} bytes but got ${stats.size} bytes`);
|
throw Error(
|
||||||
|
`Download incomplete: expected ${contentLength} bytes but got ${stats.size} bytes`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Download failed:', error);
|
console.error('Download failed:', error);
|
||||||
throw error;
|
throw error;
|
||||||
@@ -142,7 +143,7 @@ export class DownloadTask {
|
|||||||
bytesRead = await fileIo
|
bytesRead = await fileIo
|
||||||
.read(reader.fd, arrayBuffer)
|
.read(reader.fd, arrayBuffer)
|
||||||
.catch((err: BusinessError) => {
|
.catch((err: BusinessError) => {
|
||||||
throw new Error(
|
throw Error(
|
||||||
`Error reading file: ${err.message}, code: ${err.code}`,
|
`Error reading file: ${err.message}, code: ${err.code}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -154,7 +155,7 @@ export class DownloadTask {
|
|||||||
length: bytesRead,
|
length: bytesRead,
|
||||||
})
|
})
|
||||||
.catch((err: BusinessError) => {
|
.catch((err: BusinessError) => {
|
||||||
throw new Error(
|
throw Error(
|
||||||
`Error writing file: ${err.message}, code: ${err.code}`,
|
`Error writing file: ${err.message}, code: ${err.code}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -301,10 +302,10 @@ export class DownloadTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!foundDiff) {
|
if (!foundDiff) {
|
||||||
throw new Error('diff.json not found');
|
throw Error('diff.json not found');
|
||||||
}
|
}
|
||||||
if (!foundBundlePatch) {
|
if (!foundBundlePatch) {
|
||||||
throw new Error('bundle patch not found');
|
throw Error('bundle patch not found');
|
||||||
}
|
}
|
||||||
await this.copyFromResource(copyList);
|
await this.copyFromResource(copyList);
|
||||||
}
|
}
|
||||||
@@ -366,12 +367,18 @@ export class DownloadTask {
|
|||||||
new Uint8Array(entry.content),
|
new Uint8Array(entry.content),
|
||||||
);
|
);
|
||||||
const outputFile = `${params.unzipDirectory}/bundle.harmony.js`;
|
const outputFile = `${params.unzipDirectory}/bundle.harmony.js`;
|
||||||
const writer = await fileIo.open(outputFile, fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY);
|
const writer = await fileIo.open(
|
||||||
|
outputFile,
|
||||||
|
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
|
||||||
|
);
|
||||||
const chunkSize = 4096;
|
const chunkSize = 4096;
|
||||||
let bytesWritten = 0;
|
let bytesWritten = 0;
|
||||||
const totalLength = patched.byteLength;
|
const totalLength = patched.byteLength;
|
||||||
while (bytesWritten < totalLength) {
|
while (bytesWritten < totalLength) {
|
||||||
const chunk = patched.slice(bytesWritten, bytesWritten + chunkSize);
|
const chunk = patched.slice(
|
||||||
|
bytesWritten,
|
||||||
|
bytesWritten + chunkSize,
|
||||||
|
);
|
||||||
await fileIo.write(writer.fd, chunk);
|
await fileIo.write(writer.fd, chunk);
|
||||||
bytesWritten += chunk.byteLength;
|
bytesWritten += chunk.byteLength;
|
||||||
}
|
}
|
||||||
@@ -387,10 +394,10 @@ export class DownloadTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!foundDiff) {
|
if (!foundDiff) {
|
||||||
throw new Error('diff.json not found');
|
throw Error('diff.json not found');
|
||||||
}
|
}
|
||||||
if (!foundBundlePatch) {
|
if (!foundBundlePatch) {
|
||||||
throw new Error('bundle patch not found');
|
throw Error('bundle patch not found');
|
||||||
}
|
}
|
||||||
console.info('Patch from PPK completed');
|
console.info('Patch from PPK completed');
|
||||||
}
|
}
|
||||||
@@ -478,7 +485,7 @@ export class DownloadTask {
|
|||||||
await this.downloadFile(params);
|
await this.downloadFile(params);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown task type: ${params.type}`);
|
throw Error(`Unknown task type: ${params.type}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
params.listener?.onDownloadCompleted(params);
|
params.listener?.onDownloadCompleted(params);
|
||||||
@@ -3,7 +3,7 @@ import fileIo from '@ohos.file.fs';
|
|||||||
import common from '@ohos.app.ability.common';
|
import common from '@ohos.app.ability.common';
|
||||||
import { UpdateContext } from './UpdateContext';
|
import { UpdateContext } from './UpdateContext';
|
||||||
|
|
||||||
export class FileJSBundleProvider extends JSBundleProvider {
|
export class PushyFileJSBundleProvider extends JSBundleProvider {
|
||||||
private updateContext: UpdateContext;
|
private updateContext: UpdateContext;
|
||||||
private filePath: string = ''
|
private filePath: string = ''
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ export class FileJSBundleProvider extends JSBundleProvider {
|
|||||||
this.updateContext = new UpdateContext(context);
|
this.updateContext = new UpdateContext(context);
|
||||||
}
|
}
|
||||||
getURL(): string {
|
getURL(): string {
|
||||||
return this.updateContext.getBundleUrl();
|
return this.updateContext.getBundleUrl()?.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBundle(): Promise<ArrayBuffer> {
|
async getBundle(): Promise<ArrayBuffer> {
|
||||||
@@ -9,50 +9,52 @@ import { UpdateModuleImpl } from './UpdateModuleImpl';
|
|||||||
import { UpdateContext } from './UpdateContext';
|
import { UpdateContext } from './UpdateContext';
|
||||||
import { EventHub } from './EventHub';
|
import { EventHub } from './EventHub';
|
||||||
|
|
||||||
const TAG = "PushyTurboModule"
|
const TAG = 'PushyTurboModule';
|
||||||
|
|
||||||
export class PushyTurboModule extends TurboModule {
|
export class PushyTurboModule extends TurboModule {
|
||||||
mUiCtx: common.UIAbilityContext
|
mUiCtx: common.UIAbilityContext;
|
||||||
context: UpdateContext
|
context: UpdateContext;
|
||||||
|
|
||||||
constructor(protected ctx: TurboModuleContext) {
|
constructor(protected ctx: TurboModuleContext) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
logger.debug(TAG, ",PushyTurboModule constructor");
|
logger.debug(TAG, ',PushyTurboModule constructor');
|
||||||
this.mUiCtx = ctx.uiAbilityContext
|
this.mUiCtx = ctx.uiAbilityContext;
|
||||||
this.context = new UpdateContext(this.mUiCtx)
|
this.context = new UpdateContext(this.mUiCtx);
|
||||||
EventHub.getInstance().setRNInstance(ctx.rnInstance)
|
EventHub.getInstance().setRNInstance(ctx.rnInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
getConstants(): Object {
|
getConstants(): Object {
|
||||||
logger.debug(TAG, ",call getConstants");
|
logger.debug(TAG, ',call getConstants');
|
||||||
const context = this.mUiCtx;
|
const context = this.mUiCtx;
|
||||||
const preferencesManager = dataPreferences.getPreferencesSync(context,{ name: 'update' });
|
const preferencesManager = dataPreferences.getPreferencesSync(context,{ name: 'update' });
|
||||||
const isFirstTime = preferencesManager.getSync("isFirstTime", false) as boolean;
|
const isFirstTime = preferencesManager.getSync('isFirstTime', false) as boolean;
|
||||||
const rolledBackVersion = preferencesManager.getSync("rolledBackVersion", "") as string;
|
const rolledBackVersion = preferencesManager.getSync('rolledBackVersion', '') as string;
|
||||||
const uuid = preferencesManager.getSync("uuid", "") as string;
|
const uuid = preferencesManager.getSync('uuid', '') as string;
|
||||||
const currentVersion = preferencesManager.getSync("currentVersion", "") as string;
|
const currentVersion = preferencesManager.getSync('currentVersion', '') as string;
|
||||||
const buildTime = preferencesManager.getSync("buildTime", "") as string;
|
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
|
||||||
|
const buildTime = preferencesManager.getSync('buildTime', '') as string;
|
||||||
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
|
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
|
||||||
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
||||||
let packageVersion = '';
|
let packageVersion = '';
|
||||||
try {
|
try {
|
||||||
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
|
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
|
||||||
packageVersion = bundleInfo?.versionName || "Unknown"
|
packageVersion = bundleInfo?.versionName || 'Unknown';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to get bundle info:", error);
|
console.error('Failed to get bundle info:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFirstTime) {
|
if (isFirstTime) {
|
||||||
preferencesManager.deleteSync("isFirstTime");
|
preferencesManager.deleteSync('isFirstTime');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rolledBackVersion) {
|
if (rolledBackVersion) {
|
||||||
preferencesManager.deleteSync("rolledBackVersion");
|
preferencesManager.deleteSync('rolledBackVersion');
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
downloadRootDir: `${context.filesDir}/_update`,
|
downloadRootDir: `${context.filesDir}/_update`,
|
||||||
|
currentVersionInfo,
|
||||||
packageVersion,
|
packageVersion,
|
||||||
currentVersion,
|
currentVersion,
|
||||||
buildTime,
|
buildTime,
|
||||||
@@ -60,64 +62,64 @@ getConstants(): Object {
|
|||||||
isFirstTime,
|
isFirstTime,
|
||||||
rolledBackVersion,
|
rolledBackVersion,
|
||||||
uuid,
|
uuid,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async setLocalHashInfo(hash: string, info: string): Promise<boolean> {
|
setLocalHashInfo(hash: string, info: string): boolean {
|
||||||
logger.debug(TAG, ",call setLocalHashInfo");
|
logger.debug(TAG, ',call setLocalHashInfo');
|
||||||
return UpdateModuleImpl.setLocalHashInfo(this.context, hash, info);
|
return UpdateModuleImpl.setLocalHashInfo(this.context, hash, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLocalHashInfo(hash: string): Promise<string> {
|
getLocalHashInfo(hash: string): string {
|
||||||
return UpdateModuleImpl.getLocalHashInfo(this.context, hash);
|
return UpdateModuleImpl.getLocalHashInfo(this.context, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUuid(uuid: string): Promise<boolean> {
|
async setUuid(uuid: string): Promise<boolean> {
|
||||||
logger.debug(TAG, `,call setUuid`);
|
logger.debug(TAG, ',call setUuid');
|
||||||
return UpdateModuleImpl.setUuid(this.context,uuid);
|
return UpdateModuleImpl.setUuid(this.context,uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
async reloadUpdate(options: { hash: string }): Promise<void> {
|
async reloadUpdate(options: { hash: string }): Promise<void> {
|
||||||
logger.debug(TAG, `,call reloadUpdate`);
|
logger.debug(TAG, ',call reloadUpdate');
|
||||||
return UpdateModuleImpl.reloadUpdate(this.context, this.mUiCtx, options);
|
return UpdateModuleImpl.reloadUpdate(this.context, this.mUiCtx, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setNeedUpdate(options: { hash: string }): Promise<boolean> {
|
async setNeedUpdate(options: { hash: string }): Promise<boolean> {
|
||||||
logger.debug(TAG, `,call setNeedUpdate`);
|
logger.debug(TAG, ',call setNeedUpdate');
|
||||||
return UpdateModuleImpl.setNeedUpdate(this.context, options);
|
return UpdateModuleImpl.setNeedUpdate(this.context, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async markSuccess(): Promise<boolean> {
|
async markSuccess(): Promise<boolean> {
|
||||||
logger.debug(TAG, `,call markSuccess`);
|
logger.debug(TAG, ',call markSuccess');
|
||||||
return UpdateModuleImpl.markSuccess(this.context);
|
return UpdateModuleImpl.markSuccess(this.context);
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadPatchFromPpk(options: { updateUrl: string; hash: string; originHash: string }): Promise<void> {
|
async downloadPatchFromPpk(options: { updateUrl: string; hash: string; originHash: string }): Promise<void> {
|
||||||
logger.debug(TAG, `,call downloadPatchFromPpk`);
|
logger.debug(TAG, ',call downloadPatchFromPpk');
|
||||||
return UpdateModuleImpl.downloadPatchFromPpk(this.context, options);
|
return UpdateModuleImpl.downloadPatchFromPpk(this.context, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadPatchFromPackage(options: { updateUrl: string; hash: string }): Promise<void> {
|
async downloadPatchFromPackage(options: { updateUrl: string; hash: string }): Promise<void> {
|
||||||
logger.debug(TAG, `,call downloadPatchFromPackage`);
|
logger.debug(TAG, ',call downloadPatchFromPackage');
|
||||||
return UpdateModuleImpl.downloadPatchFromPackage(this.context, options);
|
return UpdateModuleImpl.downloadPatchFromPackage(this.context, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadFullUpdate(options: { updateUrl: string; hash: string }): Promise<void> {
|
async downloadFullUpdate(options: { updateUrl: string; hash: string }): Promise<void> {
|
||||||
logger.debug(TAG, `,call downloadFullUpdate`);
|
logger.debug(TAG, ',call downloadFullUpdate');
|
||||||
return UpdateModuleImpl.downloadFullUpdate(this.context, options);
|
return UpdateModuleImpl.downloadFullUpdate(this.context, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadAndInstallApk(options: { url: string; target: string; hash: string }): Promise<void> {
|
async downloadAndInstallApk(options: { url: string; target: string; hash: string }): Promise<void> {
|
||||||
logger.debug(TAG, `,call downloadAndInstallApk`);
|
logger.debug(TAG, ',call downloadAndInstallApk');
|
||||||
return UpdateModuleImpl.downloadAndInstallApk(this.mUiCtx, options);
|
return UpdateModuleImpl.downloadAndInstallApk(this.mUiCtx, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
addListener(eventName: string): void {
|
addListener(eventName: string): void {
|
||||||
logger.debug(TAG, `,call addListener`);
|
logger.debug(TAG, ',call addListener');
|
||||||
}
|
}
|
||||||
|
|
||||||
removeListeners(count: number): void {
|
removeListeners(count: number): void {
|
||||||
logger.debug(TAG, `,call removeListeners`);
|
logger.debug(TAG, ',call removeListeners');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
281
harmony/pushy/src/main/ets/UpdateContext.ts
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
import preferences from '@ohos.data.preferences';
|
||||||
|
import bundleManager from '@ohos.bundle.bundleManager';
|
||||||
|
import fileIo from '@ohos.file.fs';
|
||||||
|
import { DownloadTask } from './DownloadTask';
|
||||||
|
import common from '@ohos.app.ability.common';
|
||||||
|
import { DownloadTaskParams } from './DownloadTaskParams';
|
||||||
|
|
||||||
|
export class UpdateContext {
|
||||||
|
private context: common.UIAbilityContext;
|
||||||
|
private rootDir: string;
|
||||||
|
private preferences: preferences.Preferences;
|
||||||
|
private static DEBUG: boolean = false;
|
||||||
|
private static isUsingBundleUrl: boolean = false;
|
||||||
|
|
||||||
|
constructor(context: common.UIAbilityContext) {
|
||||||
|
this.context = context;
|
||||||
|
this.rootDir = context.filesDir + '/_update';
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!fileIo.accessSync(this.rootDir)) {
|
||||||
|
fileIo.mkdirSync(this.rootDir);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to create root directory:', e);
|
||||||
|
}
|
||||||
|
this.initPreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
private initPreferences() {
|
||||||
|
try {
|
||||||
|
this.preferences = preferences.getPreferencesSync(this.context, {
|
||||||
|
name: 'update',
|
||||||
|
});
|
||||||
|
const packageVersion = this.getPackageVersion();
|
||||||
|
const storedVersion = this.preferences.getSync('packageVersion', '');
|
||||||
|
if (!storedVersion) {
|
||||||
|
this.preferences.putSync('packageVersion', packageVersion);
|
||||||
|
this.preferences.flush();
|
||||||
|
} else if (storedVersion && packageVersion !== storedVersion) {
|
||||||
|
this.preferences.clear();
|
||||||
|
this.preferences.putSync('packageVersion', packageVersion);
|
||||||
|
this.preferences.flush();
|
||||||
|
this.cleanUp();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to init preferences:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public setKv(key: string, value: string): void {
|
||||||
|
this.preferences.putSync(key, value);
|
||||||
|
this.preferences.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public getKv(key: string): string {
|
||||||
|
return this.preferences.getSync(key, '') as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
public isFirstTime(): boolean {
|
||||||
|
return this.preferences.getSync('firstTime', false) as boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
public rolledBackVersion(): string {
|
||||||
|
return this.preferences.getSync('rolledBackVersion', '') as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
public markSuccess(): void {
|
||||||
|
this.preferences.putSync('firstTimeOk', true);
|
||||||
|
const lastVersion = this.preferences.getSync('lastVersion', '') as string;
|
||||||
|
const curVersion = this.preferences.getSync('currentVersion', '') as string;
|
||||||
|
|
||||||
|
if (lastVersion && lastVersion !== curVersion) {
|
||||||
|
this.preferences.deleteSync('lastVersion');
|
||||||
|
this.preferences.deleteSync(`hash_${lastVersion}`);
|
||||||
|
}
|
||||||
|
this.preferences.flush();
|
||||||
|
this.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public clearFirstTime(): void {
|
||||||
|
this.preferences.putSync('firstTime', false);
|
||||||
|
this.preferences.flush();
|
||||||
|
this.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public clearRollbackMark(): void {
|
||||||
|
this.preferences.putSync('rolledBackVersion', null);
|
||||||
|
this.preferences.flush();
|
||||||
|
this.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async downloadFullUpdate(
|
||||||
|
url: string,
|
||||||
|
hash: string,
|
||||||
|
listener: DownloadFileListener,
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
const params = new DownloadTaskParams();
|
||||||
|
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FULL;
|
||||||
|
params.url = url;
|
||||||
|
params.hash = hash;
|
||||||
|
params.listener = listener;
|
||||||
|
params.targetFile = `${this.rootDir}/${hash}.ppk`;
|
||||||
|
const downloadTask = new DownloadTask(this.context);
|
||||||
|
await downloadTask.execute(params);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to download full update:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async downloadFile(
|
||||||
|
url: string,
|
||||||
|
hash: string,
|
||||||
|
fileName: string,
|
||||||
|
listener: DownloadFileListener,
|
||||||
|
): Promise<void> {
|
||||||
|
const params = new DownloadTaskParams();
|
||||||
|
params.type = DownloadTaskParams.TASK_TYPE_PLAIN_DOWNLOAD;
|
||||||
|
params.url = url;
|
||||||
|
params.hash = hash;
|
||||||
|
params.listener = listener;
|
||||||
|
params.targetFile = this.rootDir + '/' + fileName;
|
||||||
|
|
||||||
|
const downloadTask = new DownloadTask(this.context);
|
||||||
|
await downloadTask.execute(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async downloadPatchFromPpk(
|
||||||
|
url: string,
|
||||||
|
hash: string,
|
||||||
|
originHash: string,
|
||||||
|
listener: DownloadFileListener,
|
||||||
|
): Promise<void> {
|
||||||
|
const params = new DownloadTaskParams();
|
||||||
|
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK;
|
||||||
|
params.url = url;
|
||||||
|
params.hash = hash;
|
||||||
|
params.originHash = originHash;
|
||||||
|
params.listener = listener;
|
||||||
|
params.targetFile = `${this.rootDir}/${originHash}_${hash}.ppk.patch`;
|
||||||
|
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
||||||
|
params.originDirectory = `${this.rootDir}/${params.originHash}`;
|
||||||
|
|
||||||
|
const downloadTask = new DownloadTask(this.context);
|
||||||
|
await downloadTask.execute(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async downloadPatchFromPackage(
|
||||||
|
url: string,
|
||||||
|
hash: string,
|
||||||
|
listener: DownloadFileListener,
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
const params = new DownloadTaskParams();
|
||||||
|
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_APP;
|
||||||
|
params.url = url;
|
||||||
|
params.hash = hash;
|
||||||
|
params.listener = listener;
|
||||||
|
params.targetFile = `${this.rootDir}/${hash}.app.patch`;
|
||||||
|
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
||||||
|
|
||||||
|
const downloadTask = new DownloadTask(this.context);
|
||||||
|
return await downloadTask.execute(params);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
console.error('Failed to download APK patch:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public switchVersion(hash: string): void {
|
||||||
|
try {
|
||||||
|
const bundlePath = `${this.rootDir}/${hash}/bundle.harmony.js`;
|
||||||
|
if (!fileIo.accessSync(bundlePath)) {
|
||||||
|
throw Error(`Bundle version ${hash} not found.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastVersion = this.getKv('currentVersion');
|
||||||
|
this.setKv('currentVersion', hash);
|
||||||
|
if (lastVersion && lastVersion !== hash) {
|
||||||
|
this.setKv('lastVersion', lastVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setKv('firstTime', 'true');
|
||||||
|
this.setKv('firstTimeOk', 'false');
|
||||||
|
this.setKv('rolledBackVersion', '');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to switch version:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getBundleUrl(
|
||||||
|
context: common.UIAbilityContext,
|
||||||
|
defaultAssetsUrl?: string,
|
||||||
|
): string {
|
||||||
|
return new UpdateContext(context).getBundleUrl(defaultAssetsUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getBundleUrl(defaultAssetsUrl?: string): string {
|
||||||
|
UpdateContext.isUsingBundleUrl = true;
|
||||||
|
const currentVersion = this.getCurrentVersion();
|
||||||
|
if (!currentVersion) {
|
||||||
|
return defaultAssetsUrl;
|
||||||
|
}
|
||||||
|
if (!this.isFirstTime()) {
|
||||||
|
if (!this.preferences.getSync('firstTimeOk', true)) {
|
||||||
|
return this.rollBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let version = currentVersion;
|
||||||
|
while (version) {
|
||||||
|
const bundleFile = `${this.rootDir}/${version}/bundle.harmony.js`;
|
||||||
|
try {
|
||||||
|
if (!fileIo.accessSync(bundleFile)) {
|
||||||
|
console.error(`Bundle version ${version} not found.`);
|
||||||
|
version = this.rollBack();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return bundleFile;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to access bundle file:', e);
|
||||||
|
version = this.rollBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultAssetsUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPackageVersion(): string {
|
||||||
|
let bundleFlags =
|
||||||
|
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
||||||
|
let packageVersion = '';
|
||||||
|
try {
|
||||||
|
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
|
||||||
|
packageVersion = bundleInfo?.versionName || 'Unknown';
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取包信息失败:', error);
|
||||||
|
}
|
||||||
|
return packageVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getCurrentVersion(): string {
|
||||||
|
const currentVersion = this.getKv('currentVersion');
|
||||||
|
return currentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private rollBack(): string {
|
||||||
|
const lastVersion = this.preferences.getSync('lastVersion', '') as string;
|
||||||
|
const currentVersion = this.preferences.getSync(
|
||||||
|
'currentVersion',
|
||||||
|
'',
|
||||||
|
) as string;
|
||||||
|
if (!lastVersion) {
|
||||||
|
this.preferences.deleteSync('currentVersion');
|
||||||
|
} else {
|
||||||
|
this.preferences.putSync('currentVersion', lastVersion);
|
||||||
|
}
|
||||||
|
this.preferences.putSync('firstTimeOk', true);
|
||||||
|
this.preferences.putSync('firstTime', false);
|
||||||
|
this.preferences.putSync('rolledBackVersion', currentVersion);
|
||||||
|
this.preferences.flush();
|
||||||
|
return lastVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private cleanUp(): void {
|
||||||
|
const params = new DownloadTaskParams();
|
||||||
|
params.type = DownloadTaskParams.TASK_TYPE_CLEANUP;
|
||||||
|
params.hash = this.preferences.getSync('currentVersion', '') as string;
|
||||||
|
params.originHash = this.preferences.getSync('lastVersion', '') as string;
|
||||||
|
params.unzipDirectory = this.rootDir;
|
||||||
|
const downloadTask = new DownloadTask(this.context);
|
||||||
|
downloadTask.execute(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getIsUsingBundleUrl(): boolean {
|
||||||
|
return UpdateContext.isUsingBundleUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DownloadFileListener {
|
||||||
|
onDownloadCompleted(params: DownloadTaskParams): void;
|
||||||
|
onDownloadFailed(error: Error): void;
|
||||||
|
}
|
||||||
@@ -4,14 +4,14 @@ import { UpdateContext } from './UpdateContext';
|
|||||||
import { DownloadTaskParams } from './DownloadTaskParams';
|
import { DownloadTaskParams } from './DownloadTaskParams';
|
||||||
import logger from './Logger';
|
import logger from './Logger';
|
||||||
|
|
||||||
const TAG = "UpdateModuleImpl";
|
const TAG = 'UpdateModuleImpl';
|
||||||
|
|
||||||
export class UpdateModuleImpl {
|
export class UpdateModuleImpl {
|
||||||
static readonly NAME = "Pushy";
|
static readonly NAME = 'Pushy';
|
||||||
|
|
||||||
static async downloadFullUpdate(
|
static async downloadFullUpdate(
|
||||||
updateContext: UpdateContext,
|
updateContext: UpdateContext,
|
||||||
options: { updateUrl: string; hash: string }
|
options: { updateUrl: string; hash: string },
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await updateContext.downloadFullUpdate(options.updateUrl, options.hash, {
|
await updateContext.downloadFullUpdate(options.updateUrl, options.hash, {
|
||||||
@@ -20,7 +20,7 @@ export class UpdateModuleImpl {
|
|||||||
},
|
},
|
||||||
onDownloadFailed: (error: Error) => {
|
onDownloadFailed: (error: Error) => {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(TAG, `downloadFullUpdate failed: ${error}`);
|
logger.error(TAG, `downloadFullUpdate failed: ${error}`);
|
||||||
@@ -30,18 +30,18 @@ export class UpdateModuleImpl {
|
|||||||
|
|
||||||
static async downloadAndInstallApk(
|
static async downloadAndInstallApk(
|
||||||
context: common.UIAbilityContext,
|
context: common.UIAbilityContext,
|
||||||
options: { url: string; hash: string; target: string }
|
options: { url: string; hash: string; target: string },
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const want = {
|
const want = {
|
||||||
action: 'action.system.home',
|
action: 'action.system.home',
|
||||||
parameters: {
|
parameters: {
|
||||||
uri: 'appmarket://details'
|
uri: 'appmarket://details',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!context) {
|
if (!context) {
|
||||||
throw new Error('获取context失败');
|
throw Error('获取context失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
await context.startAbility(want);
|
await context.startAbility(want);
|
||||||
@@ -53,17 +53,21 @@ export class UpdateModuleImpl {
|
|||||||
|
|
||||||
static async downloadPatchFromPackage(
|
static async downloadPatchFromPackage(
|
||||||
updateContext: UpdateContext,
|
updateContext: UpdateContext,
|
||||||
options: { updateUrl: string; hash: string }
|
options: { updateUrl: string; hash: string },
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
return await updateContext.downloadPatchFromPackage(options.updateUrl, options.hash, {
|
return await updateContext.downloadPatchFromPackage(
|
||||||
|
options.updateUrl,
|
||||||
|
options.hash,
|
||||||
|
{
|
||||||
onDownloadCompleted: (params: DownloadTaskParams) => {
|
onDownloadCompleted: (params: DownloadTaskParams) => {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
onDownloadFailed: (error: Error) => {
|
onDownloadFailed: (error: Error) => {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(TAG, `downloadPatchFromPackage failed: ${error}`);
|
logger.error(TAG, `downloadPatchFromPackage failed: ${error}`);
|
||||||
throw error;
|
throw error;
|
||||||
@@ -72,7 +76,7 @@ export class UpdateModuleImpl {
|
|||||||
|
|
||||||
static async downloadPatchFromPpk(
|
static async downloadPatchFromPpk(
|
||||||
updateContext: UpdateContext,
|
updateContext: UpdateContext,
|
||||||
options: { updateUrl: string; hash: string; originHash: string }
|
options: { updateUrl: string; hash: string; originHash: string },
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await updateContext.downloadPatchFromPpk(
|
await updateContext.downloadPatchFromPpk(
|
||||||
@@ -85,49 +89,49 @@ export class UpdateModuleImpl {
|
|||||||
},
|
},
|
||||||
onDownloadFailed: (error: Error) => {
|
onDownloadFailed: (error: Error) => {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(TAG, `downloadPatchFromPpk failed: ${error}`);
|
logger.error(TAG, `downloadPatchFromPpk failed: ${error}`);
|
||||||
throw new Error(`执行报错: ${error.message}`);
|
throw Error(`执行报错: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async reloadUpdate(
|
static async reloadUpdate(
|
||||||
updateContext: UpdateContext,
|
updateContext: UpdateContext,
|
||||||
context: common.UIAbilityContext,
|
context: common.UIAbilityContext,
|
||||||
options: { hash: string }
|
options: { hash: string },
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const hash = options.hash;
|
const hash = options.hash;
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
throw new Error('hash不能为空');
|
throw Error('hash不能为空');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await updateContext.switchVersion(hash);
|
await updateContext.switchVersion(hash);
|
||||||
const bundleInfo = await bundleManager.getBundleInfoForSelf(
|
const bundleInfo = await bundleManager.getBundleInfoForSelf(
|
||||||
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION
|
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION,
|
||||||
);
|
);
|
||||||
await context.terminateSelf();
|
await context.terminateSelf();
|
||||||
const want = {
|
const want = {
|
||||||
bundleName: bundleInfo.name,
|
bundleName: bundleInfo.name,
|
||||||
abilityName: context.abilityInfo?.name
|
abilityName: context.abilityInfo?.name,
|
||||||
};
|
};
|
||||||
await context.startAbility(want);
|
await context.startAbility(want);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(TAG, `reloadUpdate failed: ${error}`);
|
logger.error(TAG, `reloadUpdate failed: ${error}`);
|
||||||
throw new Error(`pushy:switchVersion failed ${error.message}`);
|
throw Error(`pushy:switchVersion failed ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setNeedUpdate(
|
static async setNeedUpdate(
|
||||||
updateContext: UpdateContext,
|
updateContext: UpdateContext,
|
||||||
options: { hash: string }
|
options: { hash: string },
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const hash = options.hash;
|
const hash = options.hash;
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
throw new Error('hash不能为空');
|
throw Error('hash不能为空');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -135,7 +139,7 @@ export class UpdateModuleImpl {
|
|||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(TAG, `setNeedUpdate failed: ${error}`);
|
logger.error(TAG, `setNeedUpdate failed: ${error}`);
|
||||||
throw new Error(`switchVersionLater failed: ${error.message}`);
|
throw Error(`switchVersionLater failed: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,20 +149,20 @@ export class UpdateModuleImpl {
|
|||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(TAG, `markSuccess failed: ${error}`);
|
logger.error(TAG, `markSuccess failed: ${error}`);
|
||||||
throw new Error(`执行报错: ${error.message}`);
|
throw Error(`执行报错: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setUuid(
|
static async setUuid(
|
||||||
updateContext: UpdateContext,
|
updateContext: UpdateContext,
|
||||||
uuid: string
|
uuid: string,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await updateContext.setKv('uuid', uuid);
|
await updateContext.setKv('uuid', uuid);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(TAG, `setUuid failed: ${error}`);
|
logger.error(TAG, `setUuid failed: ${error}`);
|
||||||
throw new Error(`执行报错: ${error.message}`);
|
throw Error(`执行报错: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,27 +175,17 @@ export class UpdateModuleImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setLocalHashInfo(
|
static setLocalHashInfo(
|
||||||
updateContext: UpdateContext,
|
updateContext: UpdateContext,
|
||||||
hash: string,
|
hash: string,
|
||||||
info: string
|
info: string,
|
||||||
): Promise<boolean> {
|
): boolean {
|
||||||
if (!this.checkJson(info)) {
|
updateContext.setKv(`hash_${hash}`, info);
|
||||||
await updateContext.setKv(`hash_${hash}`, info);
|
|
||||||
throw new Error('校验报错:json字符串格式错误');
|
|
||||||
}
|
|
||||||
await updateContext.setKv(`hash_${hash}`, info);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getLocalHashInfo(
|
static getLocalHashInfo(updateContext: UpdateContext, hash: string): string {
|
||||||
updateContext: UpdateContext,
|
const value = updateContext.getKv(`hash_${hash}`);
|
||||||
hash: string
|
|
||||||
): Promise<string> {
|
|
||||||
const value = await updateContext.getKv(`hash_${hash}`);
|
|
||||||
if (!this.checkJson(value)) {
|
|
||||||
throw new Error('校验报错:json字符串格式错误');
|
|
||||||
}
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,254 +0,0 @@
|
|||||||
import preferences from '@ohos.data.preferences';
|
|
||||||
import bundleManager from '@ohos.bundle.bundleManager';
|
|
||||||
import fileIo from '@ohos.file.fs';
|
|
||||||
import { DownloadTask } from './DownloadTask';
|
|
||||||
import common from '@ohos.app.ability.common';
|
|
||||||
import { DownloadTaskParams } from './DownloadTaskParams';
|
|
||||||
|
|
||||||
export class UpdateContext {
|
|
||||||
private context: common.UIAbilityContext;
|
|
||||||
private rootDir: string;
|
|
||||||
private preferences: preferences.Preferences;
|
|
||||||
private static DEBUG: boolean = false;
|
|
||||||
private static isUsingBundleUrl: boolean = false;
|
|
||||||
|
|
||||||
constructor(context: common.UIAbilityContext) {
|
|
||||||
this.context = context;
|
|
||||||
this.rootDir = context.filesDir + '/_update';
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!fileIo.accessSync(this.rootDir)) {
|
|
||||||
fileIo.mkdirSync(this.rootDir);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to create root directory:', e);
|
|
||||||
}
|
|
||||||
this.initPreferences();
|
|
||||||
}
|
|
||||||
|
|
||||||
private initPreferences() {
|
|
||||||
try {
|
|
||||||
this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
|
|
||||||
const packageVersion = this.getPackageVersion();
|
|
||||||
const storedVersion = this.preferences.getSync('packageVersion', '');
|
|
||||||
if(!storedVersion){
|
|
||||||
this.preferences.putSync('packageVersion', packageVersion);
|
|
||||||
this.preferences.flush();
|
|
||||||
} else if (storedVersion && packageVersion !== storedVersion) {
|
|
||||||
this.preferences.clear();
|
|
||||||
this.preferences.putSync('packageVersion', packageVersion);
|
|
||||||
this.preferences.flush();
|
|
||||||
this.cleanUp();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to init preferences:', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public setKv(key: string, value: string): void {
|
|
||||||
this.preferences.putSync(key, value);
|
|
||||||
this.preferences.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public getKv(key: string): string {
|
|
||||||
return this.preferences.getSync(key, '') as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
public isFirstTime(): boolean {
|
|
||||||
return this.preferences.getSync('firstTime', false) as boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
public rolledBackVersion(): string {
|
|
||||||
return this.preferences.getSync('rolledBackVersion', '') as string;
|
|
||||||
}
|
|
||||||
|
|
||||||
public markSuccess(): void {
|
|
||||||
this.preferences.putSync('firstTimeOk', true);
|
|
||||||
const lastVersion = this.preferences.getSync('lastVersion', '') as string;
|
|
||||||
const curVersion = this.preferences.getSync('currentVersion', '') as string;
|
|
||||||
|
|
||||||
if (lastVersion && lastVersion !== curVersion) {
|
|
||||||
this.preferences.deleteSync('lastVersion');
|
|
||||||
this.preferences.deleteSync(`hash_${lastVersion}`);
|
|
||||||
}
|
|
||||||
this.preferences.flush();
|
|
||||||
this.cleanUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public clearFirstTime(): void {
|
|
||||||
this.preferences.putSync('firstTime', false);
|
|
||||||
this.preferences.flush();
|
|
||||||
this.cleanUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public clearRollbackMark(): void {
|
|
||||||
this.preferences.putSync('rolledBackVersion', null);
|
|
||||||
this.preferences.flush();
|
|
||||||
this.cleanUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async downloadFullUpdate(url: string, hash: string, listener: DownloadFileListener): Promise<void> {
|
|
||||||
try {
|
|
||||||
const params = new DownloadTaskParams();
|
|
||||||
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FULL;
|
|
||||||
params.url = url;
|
|
||||||
params.hash = hash;
|
|
||||||
params.listener = listener;
|
|
||||||
params.targetFile = `${this.rootDir}/${hash}.ppk`;
|
|
||||||
const downloadTask = new DownloadTask(this.context);
|
|
||||||
await downloadTask.execute(params);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to download full update:', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async downloadFile(url: string, hash: string, fileName: string, listener: DownloadFileListener): Promise<void> {
|
|
||||||
const params = new DownloadTaskParams();
|
|
||||||
params.type = DownloadTaskParams.TASK_TYPE_PLAIN_DOWNLOAD;
|
|
||||||
params.url = url;
|
|
||||||
params.hash = hash;
|
|
||||||
params.listener = listener;
|
|
||||||
params.targetFile = this.rootDir + '/' + fileName;
|
|
||||||
|
|
||||||
const downloadTask = new DownloadTask(this.context);
|
|
||||||
await downloadTask.execute(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async downloadPatchFromPpk(url: string, hash: string, originHash: string, listener: DownloadFileListener): Promise<void> {
|
|
||||||
const params = new DownloadTaskParams();
|
|
||||||
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK;
|
|
||||||
params.url = url;
|
|
||||||
params.hash = hash;
|
|
||||||
params.originHash = originHash;
|
|
||||||
params.listener = listener;
|
|
||||||
params.targetFile = `${this.rootDir}/${originHash}_${hash}.ppk.patch`;
|
|
||||||
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
|
||||||
params.originDirectory = `${this.rootDir}/${params.originHash}`;
|
|
||||||
|
|
||||||
const downloadTask = new DownloadTask(this.context);
|
|
||||||
await downloadTask.execute(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async downloadPatchFromPackage(url: string, hash: string, listener: DownloadFileListener): Promise<void> {
|
|
||||||
try {
|
|
||||||
const params = new DownloadTaskParams();
|
|
||||||
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_APP;
|
|
||||||
params.url = url;
|
|
||||||
params.hash = hash;
|
|
||||||
params.listener = listener;
|
|
||||||
params.targetFile = `${this.rootDir}/${hash}.app.patch`;
|
|
||||||
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
|
||||||
|
|
||||||
const downloadTask = new DownloadTask(this.context);
|
|
||||||
return await downloadTask.execute(params);
|
|
||||||
} catch (e) {
|
|
||||||
throw e;
|
|
||||||
console.error('Failed to download APK patch:', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public switchVersion(hash: string): void {
|
|
||||||
try {
|
|
||||||
const bundlePath = `${this.rootDir}/${hash}/bundle.harmony.js`;
|
|
||||||
if (!fileIo.accessSync(bundlePath)) {
|
|
||||||
throw new Error(`Bundle version ${hash} not found.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const lastVersion = this.getKv('currentVersion');
|
|
||||||
this.setKv('currentVersion', hash);
|
|
||||||
if (lastVersion && lastVersion !== hash) {
|
|
||||||
this.setKv('lastVersion', lastVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setKv('firstTime', 'true');
|
|
||||||
this.setKv('firstTimeOk', 'false');
|
|
||||||
this.setKv('rolledBackVersion', "");
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to switch version:', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static getBundleUrl(context: common.UIAbilityContext, defaultAssetsUrl?: string): string {
|
|
||||||
return new UpdateContext(context).getBundleUrl(defaultAssetsUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getBundleUrl(defaultAssetsUrl?: string): string {
|
|
||||||
UpdateContext.isUsingBundleUrl = true;
|
|
||||||
const currentVersion = this.getCurrentVersion();
|
|
||||||
if (!currentVersion) {
|
|
||||||
return defaultAssetsUrl;
|
|
||||||
}
|
|
||||||
if (!this.isFirstTime()) {
|
|
||||||
if (!this.preferences.getSync('firstTimeOk', true)) {
|
|
||||||
return this.rollBack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let version = currentVersion;
|
|
||||||
while (version) {
|
|
||||||
const bundleFile = `${this.rootDir}/${version}/bundle.harmony.js`;
|
|
||||||
try {
|
|
||||||
if (!fileIo.accessSync(bundleFile)) {
|
|
||||||
console.error(`Bundle version ${version} not found.`);
|
|
||||||
version = this.rollBack();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return bundleFile;
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to access bundle file:', e);
|
|
||||||
version = this.rollBack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return defaultAssetsUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
getPackageVersion(): string {
|
|
||||||
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
|
||||||
let packageVersion = '';
|
|
||||||
try {
|
|
||||||
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
|
|
||||||
packageVersion = bundleInfo?.versionName || "Unknown";
|
|
||||||
} catch (error) {
|
|
||||||
console.error("获取包信息失败:", error);
|
|
||||||
}
|
|
||||||
return packageVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getCurrentVersion() : string {
|
|
||||||
const currentVersion = this.getKv('currentVersion');
|
|
||||||
return currentVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
private rollBack(): string {
|
|
||||||
const lastVersion = this.preferences.getSync('lastVersion', '') as string;
|
|
||||||
const currentVersion = this.preferences.getSync('currentVersion', '') as string;
|
|
||||||
if (!lastVersion) {
|
|
||||||
this.preferences.deleteSync('currentVersion');
|
|
||||||
} else {
|
|
||||||
this.preferences.putSync('currentVersion', lastVersion);
|
|
||||||
}
|
|
||||||
this.preferences.putSync('firstTimeOk', true);
|
|
||||||
this.preferences.putSync('firstTime', false);
|
|
||||||
this.preferences.putSync('rolledBackVersion', currentVersion);
|
|
||||||
this.preferences.flush();
|
|
||||||
return lastVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
private cleanUp(): void {
|
|
||||||
const params = new DownloadTaskParams();
|
|
||||||
params.type = DownloadTaskParams.TASK_TYPE_CLEANUP;
|
|
||||||
params.hash = this.preferences.getSync('currentVersion', '') as string;
|
|
||||||
params.originHash = this.preferences.getSync('lastVersion', '') as string;
|
|
||||||
params.unzipDirectory = this.rootDir;
|
|
||||||
const downloadTask = new DownloadTask(this.context);
|
|
||||||
downloadTask.execute(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getIsUsingBundleUrl(): boolean {
|
|
||||||
return UpdateContext.isUsingBundleUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DownloadFileListener {
|
|
||||||
onDownloadCompleted(params: DownloadTaskParams): void;
|
|
||||||
onDownloadFailed(error: Error): void;
|
|
||||||
}
|
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
static NSString *const keyPushyInfo = @"REACTNATIVECN_PUSHY_INFO_KEY";
|
static NSString *const keyPushyInfo = @"REACTNATIVECN_PUSHY_INFO_KEY";
|
||||||
static NSString *const paramPackageVersion = @"packageVersion";
|
static NSString *const paramPackageVersion = @"packageVersion";
|
||||||
|
static NSString *const paramBuildTime = @"buildTime";
|
||||||
static NSString *const paramLastVersion = @"lastVersion";
|
static NSString *const paramLastVersion = @"lastVersion";
|
||||||
static NSString *const paramCurrentVersion = @"currentVersion";
|
static NSString *const paramCurrentVersion = @"currentVersion";
|
||||||
static NSString *const paramIsFirstTime = @"isFirstTime";
|
static NSString *const paramIsFirstTime = @"isFirstTime";
|
||||||
@@ -70,20 +71,36 @@ RCT_EXPORT_MODULE(RCTPushy);
|
|||||||
{
|
{
|
||||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
|
||||||
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
|
// Check for version changes first
|
||||||
if (pushyInfo) {
|
|
||||||
NSString *curPackageVersion = [RCTPushy packageVersion];
|
NSString *curPackageVersion = [RCTPushy packageVersion];
|
||||||
NSString *packageVersion = [pushyInfo objectForKey:paramPackageVersion];
|
NSString *curBuildTime = [RCTPushy buildTime];
|
||||||
|
NSString *storedPackageVersion = [defaults stringForKey:paramPackageVersion];
|
||||||
|
NSString *storedBuildTime = [defaults stringForKey:paramBuildTime];
|
||||||
|
|
||||||
BOOL needClearPushyInfo = ![curPackageVersion isEqualToString:packageVersion];
|
// If stored versions don't exist, write current versions first
|
||||||
if (needClearPushyInfo) {
|
if (!storedPackageVersion || !storedBuildTime) {
|
||||||
|
[defaults setObject:curPackageVersion forKey:paramPackageVersion];
|
||||||
|
[defaults setObject:curBuildTime forKey:paramBuildTime];
|
||||||
|
storedPackageVersion = curPackageVersion;
|
||||||
|
storedBuildTime = curBuildTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL packageVersionChanged = ![curPackageVersion isEqualToString:storedPackageVersion];
|
||||||
|
BOOL buildTimeChanged = ![curBuildTime isEqualToString:storedBuildTime];
|
||||||
|
|
||||||
|
if (packageVersionChanged || buildTimeChanged) {
|
||||||
|
// Clear all update data and store new versions
|
||||||
[defaults setObject:nil forKey:keyPushyInfo];
|
[defaults setObject:nil forKey:keyPushyInfo];
|
||||||
[defaults setObject:nil forKey:keyHashInfo];
|
[defaults setObject:nil forKey:keyHashInfo];
|
||||||
[defaults setObject:@(YES) forKey:KeyPackageUpdatedMarked];
|
[defaults setObject:@(YES) forKey:KeyPackageUpdatedMarked];
|
||||||
|
[defaults setObject:curPackageVersion forKey:paramPackageVersion];
|
||||||
|
[defaults setObject:curBuildTime forKey:paramBuildTime];
|
||||||
|
|
||||||
// ...need clear files later
|
// ...need clear files later
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
|
||||||
|
if (pushyInfo) {
|
||||||
NSString *curVersion = pushyInfo[paramCurrentVersion];
|
NSString *curVersion = pushyInfo[paramCurrentVersion];
|
||||||
|
|
||||||
BOOL isFirstTime = [pushyInfo[paramIsFirstTime] boolValue];
|
BOOL isFirstTime = [pushyInfo[paramIsFirstTime] boolValue];
|
||||||
@@ -93,8 +110,7 @@ RCT_EXPORT_MODULE(RCTPushy);
|
|||||||
BOOL needRollback = (!ignoreRollback && isFirstTime == NO && isFirstLoadOK == NO) || loadVersion.length<=0;
|
BOOL needRollback = (!ignoreRollback && isFirstTime == NO && isFirstLoadOK == NO) || loadVersion.length<=0;
|
||||||
if (needRollback) {
|
if (needRollback) {
|
||||||
loadVersion = [self rollback];
|
loadVersion = [self rollback];
|
||||||
}
|
} else if (isFirstTime && !ignoreRollback){
|
||||||
else if (isFirstTime && !ignoreRollback){
|
|
||||||
// bundleURL may be called many times, ignore rollbacks before process restarted again.
|
// bundleURL may be called many times, ignore rollbacks before process restarted again.
|
||||||
ignoreRollback = true;
|
ignoreRollback = true;
|
||||||
|
|
||||||
@@ -117,7 +133,6 @@ RCT_EXPORT_MODULE(RCTPushy);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return [RCTPushy binaryBundleURL];
|
return [RCTPushy binaryBundleURL];
|
||||||
}
|
}
|
||||||
@@ -128,13 +143,11 @@ RCT_EXPORT_MODULE(RCTPushy);
|
|||||||
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
|
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
|
||||||
NSString *lastVersion = pushyInfo[paramLastVersion];
|
NSString *lastVersion = pushyInfo[paramLastVersion];
|
||||||
NSString *curVersion = pushyInfo[paramCurrentVersion];
|
NSString *curVersion = pushyInfo[paramCurrentVersion];
|
||||||
NSString *curPackageVersion = [RCTPushy packageVersion];
|
|
||||||
if (lastVersion.length) {
|
if (lastVersion.length) {
|
||||||
// roll back to last version
|
// roll back to last version
|
||||||
[defaults setObject:@{paramCurrentVersion:lastVersion,
|
[defaults setObject:@{paramCurrentVersion:lastVersion,
|
||||||
paramIsFirstTime:@(NO),
|
paramIsFirstTime:@(NO),
|
||||||
paramIsFirstLoadOk:@(YES),
|
paramIsFirstLoadOk:@(YES)}
|
||||||
paramPackageVersion:curPackageVersion}
|
|
||||||
forKey:keyPushyInfo];
|
forKey:keyPushyInfo];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -163,7 +176,11 @@ RCT_EXPORT_MODULE(RCTPushy);
|
|||||||
ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked];
|
ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked];
|
||||||
ret[@"uuid"] = [defaults objectForKey:keyUuid];
|
ret[@"uuid"] = [defaults objectForKey:keyUuid];
|
||||||
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
|
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
|
||||||
ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion];
|
NSString *currentVersion = [pushyInfo objectForKey:paramCurrentVersion];
|
||||||
|
ret[@"currentVersion"] = currentVersion;
|
||||||
|
if (currentVersion != nil) {
|
||||||
|
ret[@"currentVersionInfo"] = [defaults objectForKey:[keyHashInfo stringByAppendingString:currentVersion]];
|
||||||
|
}
|
||||||
|
|
||||||
// clear isFirstTimemarked
|
// clear isFirstTimemarked
|
||||||
if (ret[@"isFirstTime"]) {
|
if (ret[@"isFirstTime"]) {
|
||||||
@@ -297,7 +314,6 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options
|
|||||||
newInfo[paramLastVersion] = lastVersion;
|
newInfo[paramLastVersion] = lastVersion;
|
||||||
newInfo[paramIsFirstTime] = @(YES);
|
newInfo[paramIsFirstTime] = @(YES);
|
||||||
newInfo[paramIsFirstLoadOk] = @(NO);
|
newInfo[paramIsFirstLoadOk] = @(NO);
|
||||||
newInfo[paramPackageVersion] = [RCTPushy packageVersion];
|
|
||||||
[defaults setObject:newInfo forKey:keyPushyInfo];
|
[defaults setObject:newInfo forKey:keyPushyInfo];
|
||||||
|
|
||||||
|
|
||||||
@@ -314,21 +330,21 @@ RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options
|
|||||||
@try {
|
@try {
|
||||||
NSString *hash = options[@"hash"];
|
NSString *hash = options[@"hash"];
|
||||||
if (hash.length) {
|
if (hash.length) {
|
||||||
[self setNeedUpdate:options resolver:resolve rejecter:reject];
|
// 只在 setNeedUpdate 成功后 resolve
|
||||||
|
[self setNeedUpdate:options resolver:^(id result) {
|
||||||
// reload in earlier version
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self.bridge setValue:[[self class] bundleURL] forKey:@"bundleURL"];
|
|
||||||
[self.bridge reload];
|
|
||||||
});
|
|
||||||
|
|
||||||
#if __has_include("RCTReloadCommand.h")
|
#if __has_include("RCTReloadCommand.h")
|
||||||
// reload 0.62+
|
// reload 0.62+
|
||||||
RCTReloadCommandSetBundleURL([[self class] bundleURL]);
|
RCTReloadCommandSetBundleURL([[self class] bundleURL]);
|
||||||
RCTTriggerReloadCommandListeners(@"pushy reload");
|
RCTTriggerReloadCommandListeners(@"pushy reloadUpdate");
|
||||||
|
#else
|
||||||
|
[self.bridge reload];
|
||||||
#endif
|
#endif
|
||||||
|
});
|
||||||
resolve(@true);
|
resolve(@true);
|
||||||
|
} rejecter:^(NSString *code, NSString *message, NSError *error) {
|
||||||
|
reject(code, message, error);
|
||||||
|
}];
|
||||||
} else {
|
} else {
|
||||||
reject(@"执行报错", nil, nil);
|
reject(@"执行报错", nil, nil);
|
||||||
}
|
}
|
||||||
@@ -343,13 +359,14 @@ RCT_EXPORT_METHOD(restartApp:(RCTPromiseResolveBlock)resolve
|
|||||||
{
|
{
|
||||||
@try {
|
@try {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self.bridge reload];
|
|
||||||
});
|
|
||||||
#if __has_include("RCTReloadCommand.h")
|
#if __has_include("RCTReloadCommand.h")
|
||||||
// reload 0.62+
|
// reload 0.62+
|
||||||
RCTReloadCommandSetBundleURL([[self class] bundleURL]);
|
RCTReloadCommandSetBundleURL([[self class] bundleURL]);
|
||||||
RCTTriggerReloadCommandListeners(@"pushy restartApp");
|
RCTTriggerReloadCommandListeners(@"pushy restartApp");
|
||||||
|
#else
|
||||||
|
[self.bridge reload];
|
||||||
#endif
|
#endif
|
||||||
|
});
|
||||||
|
|
||||||
resolve(@true);
|
resolve(@true);
|
||||||
}
|
}
|
||||||
@@ -361,6 +378,9 @@ RCT_EXPORT_METHOD(restartApp:(RCTPromiseResolveBlock)resolve
|
|||||||
RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
|
RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
|
||||||
rejecter:(RCTPromiseRejectBlock)reject)
|
rejecter:(RCTPromiseRejectBlock)reject)
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
resolve(@true);
|
||||||
|
#else
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
// up package info
|
// up package info
|
||||||
@@ -384,6 +404,7 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
|
|||||||
@catch (NSException *exception) {
|
@catch (NSException *exception) {
|
||||||
reject(@"执行报错", nil, nil);
|
reject(@"执行报错", nil, nil);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -542,8 +563,16 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
|
|||||||
callback([self errorWithMessage:ERROR_HDIFFPATCH]);
|
callback([self errorWithMessage:ERROR_HDIFFPATCH]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@try {
|
||||||
[_fileManager hdiffFileAtPath:bundlePatch fromOrigin:bundleOrigin toDestination:destination completionHandler:completionHandler];
|
[_fileManager hdiffFileAtPath:bundlePatch fromOrigin:bundleOrigin toDestination:destination completionHandler:completionHandler];
|
||||||
}
|
}
|
||||||
|
@catch (NSException *exception) {
|
||||||
|
NSLog(@"Pushy _dopatch error: exception occurred during hdiffFileAtPath: %@, reason: %@",
|
||||||
|
exception.name, exception.reason);
|
||||||
|
callback([self errorWithMessage:ERROR_HDIFFPATCH]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)patch:(NSString *)hash fromBundle:(NSString *)bundleOrigin source:(NSString *)sourceOrigin callback:(void (^)(NSError *error))callback
|
- (void)patch:(NSString *)hash fromBundle:(NSString *)bundleOrigin source:(NSString *)sourceOrigin callback:(void (^)(NSError *error))callback
|
||||||
{
|
{
|
||||||
|
|||||||
48
package.json
@@ -1,29 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update",
|
"name": "react-native-update",
|
||||||
"version": "10.28.5",
|
"version": "10.34.5",
|
||||||
"description": "react-native hot update",
|
"description": "react-native hot update",
|
||||||
"main": "src/index",
|
"main": "src/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "node scripts/check-expo-version.js",
|
"postinstall": "node scripts/check-expo-version.js",
|
||||||
"prepack": "yarn submodule && yarn lint",
|
"prepack": "bun submodule && bun lint",
|
||||||
"lint": "eslint \"src/*.@(ts|tsx|js|jsx)\" && tsc --noEmit",
|
"lint": "eslint \"src/*.@(ts|tsx|js|jsx)\" && tsc --noEmit",
|
||||||
"submodule": "git submodule update --init --recursive",
|
"submodule": "git submodule update --init --recursive",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"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",
|
"build:so": "bun submodule && $ANDROID_HOME/ndk/28.2.13676358/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",
|
||||||
"build:ios-debug": "cd Example/testHotUpdate && yarn && detox build --configuration ios.sim.debug",
|
"build:ios-debug": "cd Example/testHotUpdate && bun && detox build --configuration ios.sim.debug",
|
||||||
"build:ios-release": "cd Example/testHotUpdate && yarn && detox build --configuration ios.sim.release",
|
"build:ios-release": "cd Example/testHotUpdate && bun && detox build --configuration ios.sim.release",
|
||||||
"test:ios-debug": "cd Example/testHotUpdate && detox test --configuration ios.sim.debug",
|
"test:ios-debug": "cd Example/testHotUpdate && detox test --configuration ios.sim.debug",
|
||||||
"test:ios-release": "cd Example/testHotUpdate && yarn detox test --configuration ios.sim.release",
|
"test:ios-release": "cd Example/testHotUpdate && bun detox test --configuration ios.sim.release",
|
||||||
"build:android-debug": "cd Example/testHotUpdate && yarn && detox build --configuration android.emu.debug",
|
"build:android-debug": "cd Example/testHotUpdate && bun && detox build --configuration android.emu.debug",
|
||||||
"build:android-release": "cd Example/testHotUpdate && yarn && detox build --configuration android.emu.release",
|
"build:android-release": "cd Example/testHotUpdate && bun && detox build --configuration android.emu.release",
|
||||||
"test:android-release": "cd Example/testHotUpdate && yarn detox test --configuration android.emu.release --headless --record-logs all",
|
"test:android-release": "cd Example/testHotUpdate && bun detox test --configuration android.emu.release --headless --record-logs all",
|
||||||
"test:android-debug": "cd Example/testHotUpdate && detox test --configuration android.emu.debug --headless --record-logs all",
|
"test:android-debug": "cd Example/testHotUpdate && detox test --configuration android.emu.debug --headless --record-logs all",
|
||||||
"e2e:ios": "npm run build:ios-release && npm run test:ios-release",
|
"e2e:ios": "bun build:ios-release && bun test:ios-release",
|
||||||
"e2e:android": "npm run build:android-release && npm run test:android-release",
|
"e2e:android": "bun build:android-release && bun test:android-release",
|
||||||
"tests:emulator:prepare": "cd .github/workflows/scripts/functions && yarn && yarn build",
|
"tests:emulator:prepare": "cd .github/workflows/scripts/functions && bun && bun build",
|
||||||
"tests:emulator:start-ci": "yarn tests:emulator:prepare && cd ./.github/workflows/scripts && ./start-firebase-emulator.sh",
|
"tests:emulator:start-ci": "bun tests:emulator:prepare && cd ./.github/workflows/scripts && ./start-firebase-emulator.sh",
|
||||||
"tests:packager:jet-ci": "cd Example/testHotUpdate && cross-env TMPDIR=$HOME/.metro REACT_DEBUGGER=\"echo nope\" node_modules/.bin/react-native start --no-interactive",
|
"tests:packager:jet-ci": "cd Example/testHotUpdate && cross-env TMPDIR=$HOME/.metro REACT_DEBUGGER=\"echo nope\" node_modules/.bin/react-native start --no-interactive",
|
||||||
"tests:ios:pod:install": "cd Example/testHotUpdate && yarn && yarn pod-install"
|
"tests:ios:pod:install": "cd Example/testHotUpdate && bun && bun pod-install"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -57,24 +57,20 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.25.8",
|
"@babel/core": "^7.25.8",
|
||||||
"@react-native/babel-preset": "^0.73.21",
|
"@react-native/babel-preset": "^0.73.21",
|
||||||
"@react-native/eslint-config": "^0.73.2",
|
"@react-native/eslint-config": "0.79.1",
|
||||||
"@react-native/typescript-config": "^0.74.0",
|
"@react-native/typescript-config": "0.79.1",
|
||||||
"@types/fs-extra": "^11.0.4",
|
"@types/jest": "^29.5.14",
|
||||||
"@types/jest": "^29.5.13",
|
"@types/node": "^22.15.2",
|
||||||
"@types/node": "^22.7.6",
|
|
||||||
"@types/react": "^18.3.11",
|
"@types/react": "^18.3.11",
|
||||||
"detox": "^20.27.3",
|
"detox": "^20.37.0",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-ft-flow": "^3.0.7",
|
|
||||||
"firebase-tools": "^13.22.1",
|
"firebase-tools": "^13.22.1",
|
||||||
"fs-extra": "^11.2.0",
|
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"pod-install": "^0.2.2",
|
"pod-install": "^0.3.7",
|
||||||
"prettier": "^2",
|
"prettier": "^2",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-native": "0.73",
|
"react-native": "0.73",
|
||||||
"ts-jest": "^29.2.5",
|
"ts-jest": "^29.3.2",
|
||||||
"typescript": "^5.6.3"
|
"typescript": "^5.6.3"
|
||||||
},
|
}
|
||||||
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ podspec_dir = File.dirname(__FILE__)
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
|
|
||||||
is_expo_in_podfile = false
|
is_expo_in_podfile = false
|
||||||
is_version_sufficient = false
|
|
||||||
begin
|
begin
|
||||||
# Check Podfile for use_expo_modules!
|
# Check Podfile for use_expo_modules!
|
||||||
podfile_path = File.join(Pod::Config.instance.installation_root, 'Podfile')
|
podfile_path = File.join(Pod::Config.instance.installation_root, 'Podfile')
|
||||||
@@ -17,24 +16,67 @@ Pod::Spec.new do |s|
|
|||||||
podfile_content = File.read(podfile_path)
|
podfile_content = File.read(podfile_path)
|
||||||
is_expo_in_podfile = podfile_content.include?('use_expo_modules!')
|
is_expo_in_podfile = podfile_content.include?('use_expo_modules!')
|
||||||
end
|
end
|
||||||
# Check root package.json for Expo version >= 50
|
rescue => e
|
||||||
root_package_json_path = File.join(podspec_dir, '..', '..', 'package.json')
|
# Silently ignore errors during check
|
||||||
if File.exist?(root_package_json_path)
|
end
|
||||||
pkg_json = JSON.parse(File.read(root_package_json_path))
|
|
||||||
expo_version_string = pkg_json['dependencies']&.[]('expo') || pkg_json['devDependencies']&.[]('expo')
|
# Determine final validity by checking Podfile presence AND Expo version
|
||||||
if expo_version_string
|
valid_expo_project = false # Default
|
||||||
match = expo_version_string.match(/\d+/)
|
if is_expo_in_podfile
|
||||||
|
# Only check expo version if use_expo_modules! is present
|
||||||
|
is_version_sufficient = false
|
||||||
|
begin
|
||||||
|
expo_version_str = `node --print \"require('expo/package.json').version\"`.strip
|
||||||
|
if expo_version_str && !expo_version_str.empty?
|
||||||
|
match = expo_version_str.match(/^\d+/)
|
||||||
if match
|
if match
|
||||||
major_version = match[0].to_i
|
major_version = match[0].to_i
|
||||||
is_version_sufficient = major_version >= 50
|
is_version_sufficient = major_version >= 50
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
|
# Node command failed, version remains insufficient
|
||||||
|
end
|
||||||
|
|
||||||
|
# Final check
|
||||||
|
valid_expo_project = is_version_sufficient
|
||||||
|
end
|
||||||
|
|
||||||
|
# Set platform based on whether it's a valid Expo project and if we can parse its target
|
||||||
|
final_ios_deployment_target = '11.0' # Default target
|
||||||
|
|
||||||
|
if valid_expo_project
|
||||||
|
# --- Try to find and parse ExpoModulesCore.podspec only if it's an Expo project ---
|
||||||
|
parsed_expo_ios_target = nil
|
||||||
|
expo_modules_core_podspec_path = begin
|
||||||
|
package_json_path = `node -p "require.resolve('expo-modules-core/package.json')"`.strip
|
||||||
|
File.join(File.dirname(package_json_path), 'ExpoModulesCore.podspec') if $?.success? && package_json_path && !package_json_path.empty?
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if expo_modules_core_podspec_path && File.exist?(expo_modules_core_podspec_path)
|
||||||
|
begin
|
||||||
|
content = File.read(expo_modules_core_podspec_path)
|
||||||
|
match = content.match(/s\.platforms\s*=\s*\{[\s\S]*?:ios\s*=>\s*'([^\']+)'/) # Match within s.platforms hash
|
||||||
|
if match && match[1]
|
||||||
|
parsed_expo_ios_target = match[1]
|
||||||
|
else
|
||||||
|
match = content.match(/s\.platform\s*=\s*:ios,\s*'([^\']+)'/) # Fallback to s.platform = :ios, 'version'
|
||||||
|
if match && match[1]
|
||||||
|
parsed_expo_ios_target = match[1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
# Silently ignore errors during check
|
# Pod::UI.warn "Failed to read or parse ExpoModulesCore.podspec content: #{e.message}"
|
||||||
end
|
end
|
||||||
# Determine final validity
|
end
|
||||||
valid_expo_project = is_expo_in_podfile && is_version_sufficient
|
if parsed_expo_ios_target
|
||||||
|
final_ios_deployment_target = parsed_expo_ios_target
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
s.platforms = { :ios => final_ios_deployment_target }
|
||||||
|
|
||||||
s.name = package['name']
|
s.name = package['name']
|
||||||
s.version = package['version']
|
s.version = package['version']
|
||||||
@@ -45,16 +87,8 @@ Pod::Spec.new do |s|
|
|||||||
s.homepage = package['homepage']
|
s.homepage = package['homepage']
|
||||||
|
|
||||||
s.cocoapods_version = '>= 1.6.0'
|
s.cocoapods_version = '>= 1.6.0'
|
||||||
s.platform = :ios, "8.0"
|
|
||||||
s.platforms = { :ios => "11.0" }
|
|
||||||
s.source = { :git => 'https://github.com/reactnativecn/react-native-update.git', :tag => '#{s.version}' }
|
|
||||||
|
|
||||||
# Conditionally set source files
|
s.source = { :git => 'https://github.com/reactnativecn/react-native-update.git', :tag => '#{s.version}' }
|
||||||
if valid_expo_project
|
|
||||||
s.source_files = Dir.glob("ios/**/*.{h,m,mm,swift}") # Include Expo files
|
|
||||||
else
|
|
||||||
s.source_files = Dir.glob("ios/**/*.{h,m,mm,swift}").reject { |f| f.start_with?("ios/Expo/") } # Exclude Expo files
|
|
||||||
end
|
|
||||||
|
|
||||||
s.libraries = 'bz2', 'z'
|
s.libraries = 'bz2', 'z'
|
||||||
s.vendored_libraries = 'RCTPushy/libRCTPushy.a'
|
s.vendored_libraries = 'RCTPushy/libRCTPushy.a'
|
||||||
@@ -75,38 +109,39 @@ Pod::Spec.new do |s|
|
|||||||
end
|
end
|
||||||
|
|
||||||
s.subspec 'RCTPushy' do |ss|
|
s.subspec 'RCTPushy' do |ss|
|
||||||
ss.source_files = 'ios/RCTPushy/*.{h,m,mm,swift}'
|
ss.source_files = ['ios/RCTPushy/**/*.{h,m,mm,c}',
|
||||||
ss.public_header_files = ['ios/RCTPushy/*.h']
|
|
||||||
end
|
|
||||||
|
|
||||||
s.subspec 'HDiffPatch' do |ss|
|
|
||||||
ss.source_files = ['ios/RCTPushy/HDiffPatch/**/*.{h,m,c}',
|
|
||||||
'android/jni/hpatch.{h,c}',
|
'android/jni/hpatch.{h,c}',
|
||||||
'android/jni/HDiffPatch/libHDiffPatch/HPatch/*.{h,c}',
|
'android/jni/HDiffPatch/libHDiffPatch/HPatch/*.{h,c}',
|
||||||
'android/jni/HDiffPatch/file_for_patch.{h,c}',
|
'android/jni/HDiffPatch/file_for_patch.{h,c}',
|
||||||
'android/jni/lzma/C/LzmaDec.{h,c}',
|
'android/jni/lzma/C/LzmaDec.{h,c}',
|
||||||
'android/jni/lzma/C/Lzma2Dec.{h,c}']
|
'android/jni/lzma/C/Lzma2Dec.{h,c}']
|
||||||
ss.public_header_files = 'ios/RCTPushy/HDiffPatch/**/*.h'
|
ss.public_header_files = ['ios/RCTPushy/**/*.h']
|
||||||
end
|
end
|
||||||
|
|
||||||
# Conditionally add Expo subspec and check ExpoModulesCore version
|
# Conditionally add Expo subspec and check ExpoModulesCore version
|
||||||
if valid_expo_project
|
if valid_expo_project
|
||||||
supports_bundle_url_final = false # Default
|
supports_bundle_url_final = false # Default
|
||||||
|
|
||||||
|
# 1. Try executing node to get the version string
|
||||||
|
expo_modules_core_version_str = begin
|
||||||
|
# Use node to directly require expo-modules-core/package.json and get its version
|
||||||
|
`node --print \"require('expo-modules-core/package.json').version\"` # Execute, keep raw output
|
||||||
|
rescue
|
||||||
|
# Node command failed (e.g., node not found, package not found). Return empty string.
|
||||||
|
''
|
||||||
|
end
|
||||||
|
|
||||||
|
# 2. Process the obtained version string (if not empty)
|
||||||
|
if expo_modules_core_version_str && !expo_modules_core_version_str.empty?
|
||||||
begin
|
begin
|
||||||
# Check installed ExpoModulesCore version for bundle URL support
|
# Compare versions using Gem::Version (handles trailing newline)
|
||||||
expo_core_package_json_path = File.join(podspec_dir, '..', 'expo-modules-core', 'package.json')
|
installed_version = Gem::Version.new(expo_modules_core_version_str)
|
||||||
if File.exist?(expo_core_package_json_path)
|
|
||||||
core_package_json = JSON.parse(File.read(expo_core_package_json_path))
|
|
||||||
installed_version_str = core_package_json['version']
|
|
||||||
if installed_version_str
|
|
||||||
installed_version = Gem::Version.new(installed_version_str)
|
|
||||||
target_version = Gem::Version.new('1.12.0')
|
target_version = Gem::Version.new('1.12.0')
|
||||||
supports_bundle_url_final = installed_version >= target_version
|
supports_bundle_url_final = installed_version >= target_version
|
||||||
|
rescue ArgumentError
|
||||||
|
# If Gem::Version fails parsing, supports_bundle_url_final remains false.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue JSON::ParserError, Errno::ENOENT, ArgumentError, StandardError => e
|
|
||||||
# Pod::UI.warn "Could not check ExpoModulesCore version: #{e.message}"
|
|
||||||
end
|
|
||||||
|
|
||||||
s.subspec 'Expo' do |ss|
|
s.subspec 'Expo' do |ss|
|
||||||
ss.source_files = 'ios/Expo/**/*.{h,m,mm,swift}'
|
ss.source_files = 'ios/Expo/**/*.{h,m,mm,swift}'
|
||||||
|
|||||||
1
react-native.config.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = {};
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
|
const ownPackageJson = require('../package.json');
|
||||||
|
|
||||||
|
if (process.env.npm_package_name === ownPackageJson.name) {
|
||||||
|
console.log('Skipping postinstall during local development.');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export interface Spec extends TurboModule {
|
|||||||
buildTime: string;
|
buildTime: string;
|
||||||
uuid: string;
|
uuid: string;
|
||||||
isUsingBundleUrl: boolean;
|
isUsingBundleUrl: boolean;
|
||||||
|
currentVersionInfo: string;
|
||||||
};
|
};
|
||||||
setLocalHashInfo(hash: string, info: string): Promise<void>;
|
setLocalHashInfo(hash: string, info: string): Promise<void>;
|
||||||
getLocalHashInfo(hash: string): Promise<string>;
|
getLocalHashInfo(hash: string): Promise<string>;
|
||||||
|
|||||||