feat: ios widget supports alternate server URLs
This commit is contained in:
@@ -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, "");
|
||||
|
||||
Reference in New Issue
Block a user