diff --git a/app/lib/controller/pref_controller.dart b/app/lib/controller/pref_controller.dart index bf09b499..ebeaf473 100644 --- a/app/lib/controller/pref_controller.dart +++ b/app/lib/controller/pref_controller.dart @@ -20,85 +20,85 @@ part 'pref_controller.g.dart'; class PrefController { PrefController(this._c); - Future setAppLanguage(AppLanguage value) => _set( + Future setAppLanguage(AppLanguage value) => _set( controller: _languageController, setter: (pref, value) => pref.setLanguage(value.langId), value: value, ); - Future setHomePhotosZoomLevel(int value) => _set( + Future setHomePhotosZoomLevel(int value) => _set( controller: _homePhotosZoomLevelController, setter: (pref, value) => pref.setHomePhotosZoomLevel(value), value: value, ); - Future setAlbumBrowserZoomLevel(int value) => _set( + Future setAlbumBrowserZoomLevel(int value) => _set( controller: _albumBrowserZoomLevelController, setter: (pref, value) => pref.setAlbumBrowserZoomLevel(value), value: value, ); - Future setHomeAlbumsSort(int value) => _set( + Future setHomeAlbumsSort(int value) => _set( controller: _homeAlbumsSortController, setter: (pref, value) => pref.setHomeAlbumsSort(value), value: value, ); - Future setEnableExif(bool value) => _set( + Future setEnableExif(bool value) => _set( controller: _isEnableExifController, setter: (pref, value) => pref.setEnableExif(value), value: value, ); - Future setProcessExifWifiOnly(bool value) => _set( + Future setProcessExifWifiOnly(bool value) => _set( controller: _shouldProcessExifWifiOnlyController, setter: (pref, value) => pref.setProcessExifWifiOnly(value), value: value, ); - Future setMemoriesRange(int value) => _set( + Future setMemoriesRange(int value) => _set( controller: _memoriesRangeController, setter: (pref, value) => pref.setMemoriesRange(value), value: value, ); - Future setViewerScreenBrightness(int value) => _set( + Future setViewerScreenBrightness(int value) => _set( controller: _viewerScreenBrightnessController, setter: (pref, value) => pref.setViewerScreenBrightness(value), value: value, ); - Future setViewerForceRotation(bool value) => _set( + Future setViewerForceRotation(bool value) => _set( controller: _isViewerForceRotationController, setter: (pref, value) => pref.setViewerForceRotation(value), value: value, ); - Future setGpsMapProvider(GpsMapProvider value) => _set( + Future setGpsMapProvider(GpsMapProvider value) => _set( controller: _gpsMapProviderController, setter: (pref, value) => pref.setGpsMapProvider(value.index), value: value, ); - Future setAlbumBrowserShowDate(bool value) => _set( + Future setAlbumBrowserShowDate(bool value) => _set( controller: _isAlbumBrowserShowDateController, setter: (pref, value) => pref.setAlbumBrowserShowDate(value), value: value, ); - Future setDoubleTapExit(bool value) => _set( + Future setDoubleTapExit(bool value) => _set( controller: _isDoubleTapExitController, setter: (pref, value) => pref.setDoubleTapExit(value), value: value, ); - Future setSaveEditResultToServer(bool value) => _set( + Future setSaveEditResultToServer(bool value) => _set( controller: _isSaveEditResultToServerController, setter: (pref, value) => pref.setSaveEditResultToServer(value), value: value, ); - Future setEnhanceMaxSize(SizeInt value) => _set( + Future setEnhanceMaxSize(SizeInt value) => _set( controller: _enhanceMaxSizeController, setter: (pref, value) async { return (await Future.wait([ @@ -110,32 +110,32 @@ class PrefController { value: value, ); - Future setDarkTheme(bool value) => _set( + Future setDarkTheme(bool value) => _set( controller: _isDarkThemeController, setter: (pref, value) => pref.setDarkTheme(value), value: value, ); - Future setFollowSystemTheme(bool value) => _set( + Future setFollowSystemTheme(bool value) => _set( controller: _isFollowSystemThemeController, setter: (pref, value) => pref.setFollowSystemTheme(value), value: value, ); - Future setUseBlackInDarkTheme(bool value) => _set( + Future setUseBlackInDarkTheme(bool value) => _set( controller: _isUseBlackInDarkThemeController, setter: (pref, value) => pref.setUseBlackInDarkTheme(value), value: value, ); - Future setSeedColor(Color? value) => _setOrRemove( + Future setSeedColor(Color? value) => _setOrRemove( controller: _seedColorController, setter: (pref, value) => pref.setSeedColor(value.withAlpha(0xFF).value), remover: (pref) => pref.setSeedColor(null), value: value, ); - Future setSecondarySeedColor(Color? value) => _setOrRemove( + Future setSecondarySeedColor(Color? value) => _setOrRemove( controller: _secondarySeedColorController, setter: (pref, value) => pref.setSecondarySeedColor(value.withAlpha(0xFF).value), @@ -143,7 +143,7 @@ class PrefController { value: value, ); - Future _set({ + Future _set({ required BehaviorSubject controller, required Future Function(Pref pref, T value) setter, required T value, @@ -155,7 +155,7 @@ class PrefController { value: value, ); - Future _setOrRemove({ + Future _setOrRemove({ required BehaviorSubject controller, required Future Function(Pref pref, T value) setter, required Future Function(Pref pref) remover, @@ -243,7 +243,7 @@ class PrefController { class SecurePrefController { SecurePrefController(this._c); - Future setProtectedPageAuthType(ProtectedPageAuthType? value) => + Future setProtectedPageAuthType(ProtectedPageAuthType? value) => _setOrRemove( controller: _protectedPageAuthTypeController, setter: (pref, value) => pref.setProtectedPageAuthType(value.index), @@ -251,7 +251,7 @@ class SecurePrefController { value: value, ); - Future setProtectedPageAuthPin(CiString? value) => + Future setProtectedPageAuthPin(CiString? value) => _setOrRemove( controller: _protectedPageAuthPinController, setter: (pref, value) => @@ -260,7 +260,7 @@ class SecurePrefController { value: value, ); - Future setProtectedPageAuthPassword(CiString? value) => + Future setProtectedPageAuthPassword(CiString? value) => _setOrRemove( controller: _protectedPageAuthPasswordController, setter: (pref, value) => @@ -270,7 +270,7 @@ class SecurePrefController { ); // ignore: unused_element - Future _set({ + Future _set({ required BehaviorSubject controller, required Future Function(Pref pref, T value) setter, required T value, @@ -283,7 +283,7 @@ class SecurePrefController { ); // ignore: unused_element - Future _setOrRemove({ + Future _setOrRemove({ required BehaviorSubject controller, required Future Function(Pref pref, T value) setter, required Future Function(Pref pref) remover, @@ -313,7 +313,7 @@ class SecurePrefController { _c.securePref.getProtectedPageAuthPassword()?.toCi()); } -Future _doSet({ +Future _doSet({ required Pref pref, required BehaviorSubject controller, required Future Function(Pref pref, T value) setter, @@ -325,15 +325,17 @@ Future _doSet({ if (!await setter(pref, value)) { throw StateError("Unknown error"); } + return true; } catch (e, stackTrace) { _$__NpLog.log.severe("[_doSet] Failed setting preference", e, stackTrace); controller ..addError(e, stackTrace) ..add(backup); + return false; } } -Future _doSetOrRemove({ +Future _doSetOrRemove({ required Pref pref, required BehaviorSubject controller, required Future Function(Pref pref, T value) setter, @@ -353,12 +355,14 @@ Future _doSetOrRemove({ throw StateError("Unknown error"); } } + return true; } catch (e, stackTrace) { _$__NpLog.log .severe("[_doSetOrRemove] Failed setting preference", e, stackTrace); controller ..addError(e, stackTrace) ..add(backup); + return false; } }