feat: ios widget supports alternate server URLs
This commit is contained in:
@@ -118,10 +118,8 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
}) async {
|
||||
await _apiService.setAccessToken(accessToken);
|
||||
|
||||
await _widgetService.writeCredentials(
|
||||
Store.get(StoreKey.serverEndpoint),
|
||||
accessToken,
|
||||
);
|
||||
await _widgetService.writeSessionKey(accessToken);
|
||||
await _widgetService.writeServerList();
|
||||
|
||||
// Get the deviceid from the store if it exists, otherwise generate a new one
|
||||
String deviceId =
|
||||
@@ -190,6 +188,7 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
|
||||
Future<void> saveLocalEndpoint(String url) async {
|
||||
await Store.put(StoreKey.localEndpoint, url);
|
||||
await _widgetService.writeServerList();
|
||||
}
|
||||
|
||||
String? getSavedWifiName() {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/constants/constants.dart';
|
||||
import 'package:immich_mobile/domain/models/store.model.dart';
|
||||
import 'package:immich_mobile/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/models/auth/auxilary_endpoint.model.dart';
|
||||
import 'package:immich_mobile/repositories/widget.repository.dart';
|
||||
|
||||
final widgetServiceProvider = Provider((ref) {
|
||||
@@ -13,15 +18,48 @@ class WidgetService {
|
||||
|
||||
WidgetService(this._repository);
|
||||
|
||||
Future<void> writeCredentials(String serverURL, String sessionKey) async {
|
||||
Future<void> writeSessionKey(
|
||||
String sessionKey,
|
||||
) async {
|
||||
await _repository.setAppGroupId(appShareGroupId);
|
||||
await _repository.saveData(kWidgetServerEndpoint, serverURL);
|
||||
await _repository.saveData(kWidgetAuthToken, sessionKey);
|
||||
|
||||
// wait 3 seconds to ensure the widget is updated, dont block
|
||||
Future.delayed(const Duration(seconds: 3), refreshWidgets);
|
||||
}
|
||||
|
||||
Future<void> writeServerList() async {
|
||||
await _repository.setAppGroupId(appShareGroupId);
|
||||
|
||||
// create json string from serverURLS
|
||||
final serverURLSString = jsonEncode(_buildServerList());
|
||||
|
||||
await _repository.saveData(kWidgetServerEndpoint, serverURLSString);
|
||||
Future.delayed(const Duration(seconds: 3), refreshWidgets);
|
||||
}
|
||||
|
||||
List<String> _buildServerList() {
|
||||
final List<dynamic> jsonList =
|
||||
jsonDecode(Store.tryGet(StoreKey.externalEndpointList) ?? "[]");
|
||||
final endpointList =
|
||||
jsonList.map((e) => AuxilaryEndpoint.fromJson(e)).toList();
|
||||
|
||||
final String? localEndpoint = Store.tryGet(StoreKey.localEndpoint);
|
||||
final String? serverUrl = Store.tryGet(StoreKey.serverUrl);
|
||||
|
||||
final List<dynamic> serverUrlList = endpointList.map((e) => e.url).toList();
|
||||
|
||||
if (localEndpoint != null) {
|
||||
serverUrlList.insert(0, localEndpoint);
|
||||
}
|
||||
|
||||
if (serverUrl != null && serverUrl != localEndpoint) {
|
||||
serverUrlList.insert(0, serverUrl);
|
||||
}
|
||||
|
||||
return serverUrlList.cast<String>();
|
||||
}
|
||||
|
||||
Future<void> clearCredentials() async {
|
||||
await _repository.setAppGroupId(appShareGroupId);
|
||||
await _repository.saveData(kWidgetServerEndpoint, "");
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:immich_mobile/domain/models/store.model.dart';
|
||||
import 'package:immich_mobile/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||
import 'package:immich_mobile/models/auth/auxilary_endpoint.model.dart';
|
||||
import 'package:immich_mobile/services/widget.service.dart';
|
||||
import 'package:immich_mobile/widgets/settings/networking_settings/endpoint_input.dart';
|
||||
|
||||
class ExternalNetworkPreference extends HookConsumerWidget {
|
||||
@@ -35,6 +36,8 @@ class ExternalNetworkPreference extends HookConsumerWidget {
|
||||
StoreKey.externalEndpointList,
|
||||
jsonString,
|
||||
);
|
||||
|
||||
ref.read(widgetServiceProvider).writeServerList();
|
||||
}
|
||||
|
||||
updateValidationStatus(String url, int index, AuxCheckStatus status) {
|
||||
|
||||
Reference in New Issue
Block a user