autoupdate
This commit is contained in:
3
build.py
3
build.py
@@ -71,7 +71,8 @@ def update_version_in_expo(version: str):
|
||||
|
||||
|
||||
def main():
|
||||
API_URL = 'http://192.168.1.101:5000/application'
|
||||
#API_URL = 'http://192.168.1.101:5000/application'
|
||||
API_URL = 'https://assemblr.denco.store/application'
|
||||
API_KEY = 'AF9A20DD9264C134CDA0ADACED834368'
|
||||
APPLICATION_NAME = 'assemblr'
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ import * as SecureStore from 'expo-secure-store';
|
||||
import {useDispatch} from "react-redux";
|
||||
import {logout} from "../features/auth/authSlice";
|
||||
import {store} from "../redux/store";
|
||||
|
||||
export const baseUrl = 'https://assemblr.denco.store';
|
||||
// export const baseUrl = 'http://192.168.1.101:5000';
|
||||
const apiClient = axios.create({
|
||||
// baseURL: 'https://assemblr.denco.store',
|
||||
baseURL: 'http://192.168.1.101:5000',
|
||||
baseURL: baseUrl
|
||||
});
|
||||
|
||||
apiClient.interceptors.request.use(async (config) => {
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import apiClient from "./apiClient";
|
||||
import apiClient, {baseUrl} from "./apiClient";
|
||||
import * as FileSystem from 'expo-file-system';
|
||||
import {
|
||||
DownloadProgressData,
|
||||
FileSystemDownloadResult,
|
||||
FileSystemNetworkTaskProgressCallback
|
||||
} from "expo-file-system";
|
||||
|
||||
|
||||
const router = '/application';
|
||||
const api_key = 'AF9A20DD9264C134CDA0ADACED834368';
|
||||
@@ -7,12 +14,8 @@ const applicationApi = {
|
||||
let response = await apiClient.get(`${router}/${name}/version`, {headers: {Authorization: api_key}});
|
||||
return response.data;
|
||||
},
|
||||
download: async (name: string, version: string): Promise<ArrayBuffer> => {
|
||||
let response = await apiClient.get(`${router}/${name}/download/${version}`, {
|
||||
headers: {Authorization: api_key},
|
||||
responseType: "arraybuffer"
|
||||
});
|
||||
return response.data;
|
||||
download: async (fileUri: string, name: string, version: string, callback: FileSystemNetworkTaskProgressCallback<DownloadProgressData>): Promise<FileSystemDownloadResult | undefined> => {
|
||||
return FileSystem.createDownloadResumable(`${baseUrl}${router}/${name}/download/${version}`, fileUri, {headers: {Authorization: api_key}}, callback).downloadAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,19 +10,20 @@ import * as Progress from 'react-native-progress';
|
||||
import {RFPercentage} from "react-native-responsive-fontsize";
|
||||
|
||||
const LoadingModal: FC = () => {
|
||||
const isVisible = useSelector((state: RootState) => state.loadingModal.isVisible);
|
||||
const loadingText = useSelector((state: RootState) => state.loadingModal.loadingText);
|
||||
const state = useSelector((state: RootState) => state.loadingModal);
|
||||
const [ch, sCh] = useState(false);
|
||||
return (
|
||||
<Modal isVisible={true}>
|
||||
<Modal isVisible={state.isVisible}>
|
||||
<View style={styles.container}>
|
||||
<DTitle style={{textAlign: "center"}}>{loadingText}</DTitle>
|
||||
<DTitle style={{textAlign: "center"}}>{state.loadingText}</DTitle>
|
||||
<View style={styles.progressBarWrapper}>
|
||||
<Progress.Circle size={RFPercentage(20)}
|
||||
color={blue}
|
||||
indeterminate={true}
|
||||
indeterminate={state.indeterminate}
|
||||
progress={state.progress}
|
||||
style={styles.progressBar}
|
||||
borderWidth={responsiveWidth(1)}
|
||||
borderWidth={state.indeterminate ? responsiveWidth(1) : 0}
|
||||
thickness={responsiveWidth(1)}
|
||||
/>
|
||||
</View>
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import {createSlice} from "@reduxjs/toolkit";
|
||||
import {createSlice, PayloadAction} from "@reduxjs/toolkit";
|
||||
|
||||
export interface LoadingModalState {
|
||||
isVisible: boolean;
|
||||
loadingText: string
|
||||
loadingText: string;
|
||||
indeterminate: boolean;
|
||||
progress: number;
|
||||
}
|
||||
|
||||
const initialState: LoadingModalState = {
|
||||
isVisible: false,
|
||||
loadingText: "Подождите..."
|
||||
loadingText: "Подождите...",
|
||||
indeterminate: true,
|
||||
progress: 0
|
||||
}
|
||||
|
||||
export const loadingModalSlice = createSlice({
|
||||
@@ -22,9 +26,24 @@ export const loadingModalSlice = createSlice({
|
||||
},
|
||||
setLoadingText: (state, action) => {
|
||||
state.loadingText = action.payload;
|
||||
},
|
||||
setProgress: (state, action: PayloadAction<number>) => {
|
||||
state.progress = action.payload;
|
||||
},
|
||||
setIndeterminate: (state, action: PayloadAction<boolean>) => {
|
||||
state.indeterminate = action.payload;
|
||||
},
|
||||
reset: (state) => {
|
||||
state = initialState;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const {openLoadingModal, closeLoadingModal, setLoadingText} = loadingModalSlice.actions;
|
||||
export const {
|
||||
openLoadingModal,
|
||||
closeLoadingModal,
|
||||
setLoadingText,
|
||||
setProgress,
|
||||
setIndeterminate
|
||||
} = loadingModalSlice.actions;
|
||||
export default loadingModalSlice.reducer;
|
||||
@@ -23,6 +23,13 @@ import * as FileSystem from 'expo-file-system';
|
||||
import applicationApi from "../../api/applicationApi";
|
||||
import {ActivityAction, startActivityAsync} from "expo-intent-launcher";
|
||||
import {RenderTargetOptions} from "@shopify/flash-list";
|
||||
import KeyEvent from 'react-native-keyevent';
|
||||
import {
|
||||
openLoadingModal,
|
||||
setIndeterminate,
|
||||
setLoadingText,
|
||||
setProgress
|
||||
} from "../../features/loadingModal/loadingModalSlice";
|
||||
|
||||
function CommonPage() {
|
||||
const dim = useSelector((state: RootState) => state.interface.dim);
|
||||
@@ -56,54 +63,33 @@ function CommonPage() {
|
||||
|
||||
|
||||
const checkUpdates = async () => {
|
||||
|
||||
return;
|
||||
// //
|
||||
// let packageName = Constants.manifest2?.extra?.expoClient?.android?.package; // Замените на имя пакета вашего приложения
|
||||
// const uri = `package:${packageName}`;
|
||||
// startActivityAsync('android.settings.MANAGE_UNKNOWN_APP_SOURCES', {
|
||||
// data: uri
|
||||
// }).then(result => {
|
||||
// console.log(result);
|
||||
// }).catch(error => {
|
||||
// console.log(error);
|
||||
// });
|
||||
// return
|
||||
const currentVersion = Constants.manifest2?.extra?.expoClient?.version;
|
||||
const currentVersion = Constants.manifest2?.extra?.expoClient?.version
|
||||
applicationApi.getVersion('assemblr').then(({latest_version}) => {
|
||||
if (currentVersion == latest_version) return;
|
||||
dispatch(setIndeterminate(false));
|
||||
dispatch(setLoadingText("Загрузка обновления..."));
|
||||
dispatch(setProgress(0));
|
||||
dispatch(openLoadingModal());
|
||||
|
||||
const apkPath = FileSystem.documentDirectory + "test.apk";
|
||||
FileSystem.downloadAsync('http://192.168.1.101:5000/application/assemblr/download/1.1.8', apkPath).then(downloadResult => {
|
||||
applicationApi.download(apkPath, 'assemblr', latest_version, data => {
|
||||
dispatch(setProgress(data.totalBytesWritten / data.totalBytesExpectedToWrite));
|
||||
}).then(() => {
|
||||
FileSystem.getContentUriAsync(apkPath).then(localUri => {
|
||||
try {
|
||||
startActivityAsync('android.intent.action.INSTALL_PACKAGE', {
|
||||
data: localUri,
|
||||
flags: 1
|
||||
}).then(result => {
|
||||
console.log(result);
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
}
|
||||
|
||||
startActivityAsync('android.intent.action.INSTALL_PACKAGE', {
|
||||
data: localUri,
|
||||
flags: 1
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
useEffect(() => {
|
||||
checkUpdates();
|
||||
//initialize();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
||||
<View style={styles.main}>
|
||||
|
||||
|
||||
{isAuthorized ? <MainScreen/> : <LoginScreen/>}
|
||||
<View style={[styles.overlay, {display: dim ? 'flex' : 'none'}]}/>
|
||||
<LoadingModal/>
|
||||
|
||||
@@ -11,6 +11,7 @@ import {useDispatch} from "react-redux";
|
||||
import {login} from "../../features/auth/authSlice";
|
||||
import Toast from "react-native-toast-message";
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
import KeyEvent from "react-native-keyevent";
|
||||
|
||||
function LoginScreen() {
|
||||
const dispatch = useAppDispatch();
|
||||
@@ -33,6 +34,8 @@ function LoginScreen() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
}, []);
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user