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