This commit is contained in:
2023-11-21 00:58:33 +03:00
parent 098eba64a6
commit ca519b4ce5
11 changed files with 95 additions and 21 deletions

1
.gitignore vendored
View File

@@ -35,3 +35,4 @@ yarn-error.*
# typescript # typescript
*.tsbuildinfo *.tsbuildinfo
yarn.lock yarn.lock
package-lock.json

View File

@@ -34,7 +34,10 @@
}, },
"package": "com.anonymous.Assemblr", "package": "com.anonymous.Assemblr",
"permissions": [ "permissions": [
"INTERNET" "INTERNET",
"REQUEST_INSTALL_PACKAGES",
"READ_EXTERNAL_STORAGE",
"WRITE_EXTERNAL_STORAGE"
] ]
}, },
"web": { "web": {

View File

@@ -26,7 +26,7 @@ class ApplicationApi:
def upload(self, version: str, file_path: str): def upload(self, version: str, file_path: str):
data = {'version': version} data = {'version': version}
files = {'file': file_path} files = {'file': open(file_path, 'rb')}
return self.method('POST', 'upload', data=data, files=files) return self.method('POST', 'upload', data=data, files=files)

View File

@@ -25,7 +25,9 @@
"axios": "^1.5.0", "axios": "^1.5.0",
"babel-plugin-module-resolver": "^5.0.0", "babel-plugin-module-resolver": "^5.0.0",
"expo": "~49.0.8", "expo": "~49.0.8",
"expo-application": "~5.3.0",
"expo-build-properties": "~0.8.3", "expo-build-properties": "~0.8.3",
"expo-constants": "~14.4.2",
"expo-secure-store": "~12.3.1", "expo-secure-store": "~12.3.1",
"expo-splash-screen": "~0.20.5", "expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0", "expo-status-bar": "~1.6.0",
@@ -38,6 +40,8 @@
"react-native-keyevent-expo-config-plugin": "^1.0.49", "react-native-keyevent-expo-config-plugin": "^1.0.49",
"react-native-modal": "^13.0.1", "react-native-modal": "^13.0.1",
"react-native-paper": "^5.10.6", "react-native-paper": "^5.10.6",
"react-native-progress": "^5.0.1",
"react-native-progress-circle-updated": "^2.2.1",
"react-native-radio-buttons-group": "^3.0.5", "react-native-radio-buttons-group": "^3.0.5",
"react-native-reanimated": "3.3.0", "react-native-reanimated": "3.3.0",
"react-native-responsive-dimensions": "^3.1.1", "react-native-responsive-dimensions": "^3.1.1",
@@ -51,7 +55,9 @@
"react-native-webview": "13.2.2", "react-native-webview": "13.2.2",
"react-redux": "^8.1.2", "react-redux": "^8.1.2",
"redux": "^4.2.1", "redux": "^4.2.1",
"rn-openapp": "^2.1.2" "rn-openapp": "^2.1.2",
"expo-file-system": "~15.4.4",
"expo-intent-launcher": "~10.7.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.20.0", "@babel/core": "^7.20.0",

View File

@@ -8,12 +8,13 @@ import CommonPage from "./screens/CommonPage/CommonPage";
import {BottomSheetModalProvider} from "@gorhom/bottom-sheet"; import {BottomSheetModalProvider} from "@gorhom/bottom-sheet";
import {GestureHandlerRootView} from "react-native-gesture-handler"; import {GestureHandlerRootView} from "react-native-gesture-handler";
import Toast from "react-native-toast-message"; import Toast from "react-native-toast-message";
import Constants from "expo-constants";
export default function App() { export default function App() {
let [fontsLoading] = useFonts({ let [fontsLoading] = useFonts({
// 'SF Pro Text': require('./assets/fonts/SF-Pro-Text-Regular.otf') // 'SF Pro Text': require('./assets/fonts/SF-Pro-Text-Regular.otf')
}) })
if (!fontsLoading) if (!fontsLoading)
return <View><Text>Loading...</Text></View> return <View><Text>Loading...</Text></View>
return ( return (

View File

@@ -5,8 +5,8 @@ import {logout} from "../features/auth/authSlice";
import {store} from "../redux/store"; import {store} from "../redux/store";
const apiClient = axios.create({ const apiClient = axios.create({
baseURL: 'https://assemblr.denco.store', // baseURL: 'https://assemblr.denco.store',
// baseURL: 'http://192.168.1.101:5000', baseURL: 'http://192.168.1.101:5000',
}); });
apiClient.interceptors.request.use(async (config) => { apiClient.interceptors.request.use(async (config) => {
@@ -27,12 +27,6 @@ apiClient.interceptors.request.use(async (config) => {
return config; return config;
}, function (error) { }, function (error) {
console.log("очко")
if (error.response && error.response.status === 401) {
console.log("очко")
}
}); });

19
src/api/applicationApi.ts Normal file
View File

@@ -0,0 +1,19 @@
import apiClient from "./apiClient";
const router = '/application';
const api_key = 'AF9A20DD9264C134CDA0ADACED834368';
const applicationApi = {
getVersion: async (name: string): Promise<{ 'latest_version': string }> => {
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;
}
}
export default applicationApi;

View File

@@ -5,5 +5,6 @@ const userApi = {
let response = await apiClient.post('/auth/login', {login, password}); let response = await apiClient.post('/auth/login', {login, password});
return response.data; return response.data;
}, },
} }
export default userApi; export default userApi;

View File

@@ -3,19 +3,27 @@ import {StyleSheet, View} from "react-native";
import {useSelector} from "react-redux"; import {useSelector} from "react-redux";
import {RootState} from "../../../redux/store"; import {RootState} from "../../../redux/store";
import Modal from "react-native-modal"; import Modal from "react-native-modal";
import {background} from "../../../css/colors"; import {background, blue} from "../../../css/colors";
import {responsiveHeight, responsiveWidth} from "react-native-responsive-dimensions"; import {responsiveHeight, responsiveWidth} from "react-native-responsive-dimensions";
import DTitle from "../../DTitle/DTitle"; import DTitle from "../../DTitle/DTitle";
import * as Progress from 'react-native-progress';
import {RFPercentage} from "react-native-responsive-fontsize";
const LoadingModal: FC = () => { const LoadingModal: FC = () => {
const isVisible = useSelector((state: RootState) => state.loadingModal.isVisible); const isVisible = useSelector((state: RootState) => state.loadingModal.isVisible);
const loadingText = useSelector((state: RootState) => state.loadingModal.loadingText); const loadingText = useSelector((state: RootState) => state.loadingModal.loadingText);
const [ch, sCh] = useState(false); const [ch, sCh] = useState(false);
return ( return (
<Modal isVisible={isVisible}> <Modal isVisible={true}>
<View style={styles.container}> <View style={styles.container}>
<DTitle style={{textAlign: "center"}}>{loadingText}</DTitle> <DTitle style={{textAlign: "center"}}>{loadingText}</DTitle>
<View style={styles.progressBarWrapper}> <View style={styles.progressBarWrapper}>
<Progress.Circle size={RFPercentage(20)}
color={blue}
indeterminate={true}
style={styles.progressBar}
borderWidth={responsiveWidth(1)}
/>
</View> </View>
</View> </View>

View File

@@ -1,7 +1,6 @@
import {SafeAreaView, StyleSheet, View} from "react-native"; import {Linking, StyleSheet, View} from "react-native";
import LoginScreen from "../LoginScreen/LoginScreen"; import LoginScreen from "../LoginScreen/LoginScreen";
import MainScreen from "../MainScreen/MainScreen"; import MainScreen from "../MainScreen/MainScreen";
import SearchBar from "../../components/SearchBar/SearchBar";
import React, {useEffect} from "react"; import React, {useEffect} from "react";
import {background} from "../../css/colors"; import {background} from "../../css/colors";
import {useDispatch, useSelector} from "react-redux"; import {useDispatch, useSelector} from "react-redux";
@@ -11,16 +10,19 @@ import * as SecureStore from 'expo-secure-store';
import Toast from "react-native-toast-message"; import Toast from "react-native-toast-message";
import toastConfig from "../../components/Toast/Toast"; import toastConfig from "../../components/Toast/Toast";
import ScanModal from "../../components/SearchBar/ScanModal"; import ScanModal from "../../components/SearchBar/ScanModal";
import {closeScanModal, setScannedData} from "../../features/scanModal/scanModalSlice";
import LoadingModal from "../../components/Modals/LoadingModal/LoadingModal"; import LoadingModal from "../../components/Modals/LoadingModal/LoadingModal";
import ReprintModal from "../../components/Modals/ReprintModal/ReprintModal"; import ReprintModal from "../../components/Modals/ReprintModal/ReprintModal";
import assemblyApi from "../../api/assemblyApi"; import assemblyApi from "../../api/assemblyApi";
import {assembly, setAssembly, setLocalState, setOrder} from "../../features/assembly/assemblySlice"; import {setAssembly, setLocalState, setOrder} from "../../features/assembly/assemblySlice";
import ordersApi from "../../api/ordersApi"; import ordersApi from "../../api/ordersApi";
import ImageZoomModal from "../../components/Modals/ImageZoomModal/ImageZoomModal"; import ImageZoomModal from "../../components/Modals/ImageZoomModal/ImageZoomModal";
import SortingModal from "../../components/Modals/SortingModal/SortingModal"; import SortingModal from "../../components/Modals/SortingModal/SortingModal";
import {setLoadingText} from "../../features/loadingModal/loadingModalSlice";
import {ASSEMBLY_STATE} from "../../types/assembly"; import {ASSEMBLY_STATE} from "../../types/assembly";
import Constants from "expo-constants";
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";
function CommonPage() { function CommonPage() {
const dim = useSelector((state: RootState) => state.interface.dim); const dim = useSelector((state: RootState) => state.interface.dim);
@@ -33,7 +35,6 @@ function CommonPage() {
dispatch(login({accessToken: token})); dispatch(login({accessToken: token}));
return true; return true;
} }
const loadAssembly = async () => { const loadAssembly = async () => {
assemblyApi.hasActive().then(({has}) => { assemblyApi.hasActive().then(({has}) => {
if (!has) return; if (!has) return;
@@ -54,13 +55,53 @@ function CommonPage() {
} }
const checkUpdates = async () => {
//
// 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}) => {
const apkPath = FileSystem.documentDirectory + "test.apk";
FileSystem.downloadAsync('http://192.168.1.101:5000/application/assemblr/download/1.1.8', apkPath).then(downloadResult => {
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);
}
})
})
});
}
useEffect(() => { useEffect(() => {
initialize(); 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/>