Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trinko committed Jan 13, 2025
1 parent aae8e78 commit a831f0d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const appName = "giua@school/app";
const appVersion = "3.1.1";
const appVersion = "3.1.2";

export default {
"expo": {
Expand Down
36 changes: 27 additions & 9 deletions app/connect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Constants from 'expo-constants';
import { Stack, useRouter } from 'expo-router';
import * as SecureStore from 'expo-secure-store';
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { Text, View } from 'react-native';
import { WebView } from 'react-native-webview';
import Pressable from '../components/PressableComponent';
Expand All @@ -27,15 +27,22 @@ export default function ConnectScreen() {
const [web, setWeb] = useState('');
const [stage, setStage] = useState(0);
const [error, setError] = useState('');
const [currentUrl, setCurrentUrl] = useState('');
const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 ' + Constants.expoConfig.extra.version;
const router = useRouter();
const webViewRef = useRef(null);
const timerRef = useRef(null);

// gestione cambio pagina
const navigationChanged = (event) => {
const url = event.url + (event.url.endsWith('/') ? '' : '/');
if (url == web) {
// login effettuato con successo
setStage(2);
const url = event.nativeEvent.url + (event.nativeEvent.url.endsWith('/') ? '' : '/');
if (event.nativeEvent.data == 'CLOCK' && !event.nativeEvent.loading && url != currentUrl) {
setCurrentUrl(url);
if (url == web) {
// login effettuato con successo
clearInterval(timerRef.current);
setStage(2);
}
}
};

Expand Down Expand Up @@ -93,6 +100,16 @@ export default function ConnectScreen() {
}
}

// inizia la procedura di registrazione
const start = () => {
setStage(1);
// imposta il timer per inviare un segnale dalla WebView all'app
timerRef.current = setInterval(() => {
webViewRef.current.injectJavaScript(`window.ReactNativeWebView.postMessage('CLOCK'); true;`);
}, 100);
return () => clearInterval(timerRef.current);
};

// eseguito solo al primo render
useEffect(() => {
// legge dati dalla memoria
Expand Down Expand Up @@ -123,12 +140,12 @@ export default function ConnectScreen() {
</Text>
<Text style={styles.text}>
Dovrai ora effettuare il normale accesso al registro elettronico:
subito dopo, l'applicazione prenderà il controllo per eseguire
la registrazione del tuo dispositivo.
successivamente non fare niente, ma rimani in attesa che l'applicazione prenda il controllo
per eseguire la registrazione del tuo dispositivo.
</Text>
<Pressable
style={styles.buttonContainer}
onPress={() => setStage(1)}>
onPress={start}>
<Text style={styles.buttonPrimary}>Associa il dispositivo</Text>
</Pressable>
</View>
Expand All @@ -144,12 +161,13 @@ export default function ConnectScreen() {
setError('Errore di connessione\n' + event.nativeEvent.description);
setStage(9);
}}
onNavigationStateChange={navigationChanged}
onMessage={navigationChanged}
startInLoadingState={true}
domStorageEnabled={true}
javaScriptEnabled={true}
userAgent={userAgent}
renderLoading={() => <Waiting />}
ref={webViewRef}
/>
)}
{stage == 2 && (
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "giuaschool-app",
"version": "3.1.1",
"version": "3.1.2",
"main": "expo-router/entry",
"scripts": {
"start": "expo start",
Expand Down

0 comments on commit a831f0d

Please sign in to comment.