mirror of
https://github.com/immich-app/immich.git
synced 2025-08-11 09:16:31 -04:00
* chore: bump dart sdk to 3.8 * chore: make build * make pigeon * chore: format files --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
38 lines
1.3 KiB
Dart
38 lines
1.3 KiB
Dart
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/constants/constants.dart';
|
|
import 'package:immich_mobile/repositories/widget.repository.dart';
|
|
|
|
final widgetServiceProvider = Provider((ref) {
|
|
return WidgetService(ref.watch(widgetRepositoryProvider));
|
|
});
|
|
|
|
class WidgetService {
|
|
final WidgetRepository _repository;
|
|
|
|
const WidgetService(this._repository);
|
|
|
|
Future<void> writeCredentials(String serverURL, 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> clearCredentials() async {
|
|
await _repository.setAppGroupId(appShareGroupId);
|
|
await _repository.saveData(kWidgetServerEndpoint, "");
|
|
await _repository.saveData(kWidgetAuthToken, "");
|
|
|
|
// wait 3 seconds to ensure the widget is updated, dont block
|
|
Future.delayed(const Duration(seconds: 3), refreshWidgets);
|
|
}
|
|
|
|
Future<void> refreshWidgets() async {
|
|
for (final (iOSName, androidName) in kWidgetNames) {
|
|
await _repository.refresh(iOSName, androidName);
|
|
}
|
|
}
|
|
}
|