feat(mobile): Auto switching server URLs (#14437)

This commit is contained in:
Alex 2024-12-05 09:11:48 -06:00 committed by GitHub
parent 3c38851d50
commit 055f1fc72f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 1828 additions and 108 deletions

View file

@ -45,6 +45,17 @@ class AuthNotifier extends StateNotifier<AuthState> {
return _authService.validateServerUrl(url);
}
/// Validating the url is the alternative connecting server url without
/// saving the infomation to the local database
Future<bool> validateAuxilaryServerUrl(String url) async {
try {
final validEndpoint = await _apiService.resolveEndpoint(url);
return await _authService.validateAuxilaryServerUrl(validEndpoint);
} catch (_) {
return false;
}
}
Future<LoginResponse> login(String email, String password) async {
final response = await _authService.login(email, password);
await saveAuthInfo(accessToken: response.accessToken);
@ -161,4 +172,34 @@ class AuthNotifier extends StateNotifier<AuthState> {
return true;
}
Future<void> saveWifiName(String wifiName) {
return Store.put(StoreKey.preferredWifiName, wifiName);
}
Future<void> saveLocalEndpoint(String url) {
return Store.put(StoreKey.localEndpoint, url);
}
String? getSavedWifiName() {
return Store.tryGet(StoreKey.preferredWifiName);
}
String? getSavedLocalEndpoint() {
return Store.tryGet(StoreKey.localEndpoint);
}
/// Returns the current server endpoint (with /api) URL from the store
String? getServerEndpoint() {
return Store.tryGet(StoreKey.serverEndpoint);
}
/// Returns the current server URL (input by the user) from the store
String? getServerUrl() {
return Store.tryGet(StoreKey.serverUrl);
}
Future<String?> setOpenApiServiceEndpoint() {
return _authService.setOpenApiServiceEndpoint();
}
}