mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-28 01:37:56 +03:00
improve HTTPS server warning
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {useModalStyles} from "../utils/ModalStyles";
|
||||
import {Card, Paragraph, useTheme} from "react-native-paper";
|
||||
import {useCallback, useEffect, useLayoutEffect, useState} from "react";
|
||||
import {Platform, TextInput, TouchableOpacity, View} from "react-native";
|
||||
import {Alert, Platform, TextInput, TouchableOpacity, View} from "react-native";
|
||||
|
||||
import RealmContext from "../models/RealmContext";
|
||||
import {AMServer} from "../models/AMServer";
|
||||
@@ -34,25 +34,48 @@ export default function ServerAddModal({route, navigation}) {
|
||||
let urlValid = false;
|
||||
|
||||
try {
|
||||
new URL(serverAddress);
|
||||
urlValid = true;
|
||||
const protocol = new URL(serverAddress).protocol;
|
||||
urlValid = protocol.localeCompare("http:", undefined, {sensitivity: "case"}) === 0 || protocol.localeCompare("https:", undefined, {sensitivity: "case"}) === 0;
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const themeOptions = urlValid ? modalStyles.headerText : {color: theme.colors.outline};
|
||||
navigation.setOptions({
|
||||
headerRight: () => <TouchableOpacity disabled={!urlValid} onPress={() => saveServer()}>
|
||||
headerRight: () => <TouchableOpacity disabled={!urlValid} onPress={() => saveServer(serverAddress)}>
|
||||
<Paragraph style={{...themeOptions, fontWeight: "600"}}>Save</Paragraph>
|
||||
</TouchableOpacity>
|
||||
})
|
||||
}, [navigation, modalStyles, serverAddress]);
|
||||
|
||||
const saveServer = useCallback(() => {
|
||||
let serverObject = realm.objects<AMServer>("server").find(x => x.serverAddress == serverAddress);
|
||||
const saveServer = useCallback(async (address: string) => {
|
||||
if (address.startsWith("https:")) {
|
||||
await new Promise<void>(done => {
|
||||
Alert.alert(
|
||||
"HTTPS Warning",
|
||||
"By default, AMNet doesn't support HTTPS without advanced configuration. It's highly likely you won't be able to connect.",
|
||||
[
|
||||
{
|
||||
text: "Keep HTTPS",
|
||||
style: "destructive",
|
||||
onPress: () => done()
|
||||
},
|
||||
{
|
||||
text: "Change to HTTP",
|
||||
isPreferred: true,
|
||||
onPress: () => {
|
||||
address = address.replace(/^https:/i, "http:");
|
||||
done();
|
||||
}
|
||||
},
|
||||
]);
|
||||
})
|
||||
}
|
||||
|
||||
let serverObject = realm.objects<AMServer>("server").find(x => x.serverAddress == address);
|
||||
if (!serverObject) {
|
||||
realm.write(() => {
|
||||
serverObject = realm.create<AMServer>("server", AMServer.generate(serverAddress));
|
||||
serverObject = realm.create<AMServer>("server", AMServer.generate(address));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,7 +83,7 @@ export default function ServerAddModal({route, navigation}) {
|
||||
setTimeout(() => navigation.navigate('server', {
|
||||
serverId: serverObject._id.toHexString()
|
||||
}), 500);
|
||||
}, [serverAddress, realm]);
|
||||
}, [realm]);
|
||||
|
||||
return (<View style={{display: "flex", gap: 10, justifyContent: "center", paddingHorizontal: 15, paddingTop: 25}}>
|
||||
<Card mode="contained">
|
||||
@@ -85,7 +108,7 @@ export default function ServerAddModal({route, navigation}) {
|
||||
</Card>
|
||||
|
||||
<Paragraph style={modalStyles.formFootnote}>
|
||||
If you're using HTTPS, ensure a trusted certificate has been configured via HTTP.SYS
|
||||
AMNet uses HTTP by default. Unless has been configured to work with HTTP.SYS, HTTPS will not work.
|
||||
</Paragraph>
|
||||
</View>)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user