Skip to content

An open-source cross-platform alternative to AirDrop

refactor: inject persistence into settings service

Tien Do Namfe6ab3e43146
diff --git a/app/lib/provider/settings_provider.dart b/app/lib/provider/settings_provider.dart
index 343f9de3..12934741 100644
--- a/app/lib/provider/settings_provider.dart
+++ b/app/lib/provider/settings_provider.dart
@@ -8,177 +8,174 @@ import 'package:localsend_app/provider/persistence_provider.dart';
import 'package:refena_flutter/refena_flutter.dart';
final settingsProvider = NotifierProvider<SettingsService, SettingsState>((ref) {
- return SettingsService();
+ return SettingsService(ref.read(persistenceProvider));
});
-class SettingsService extends Notifier<SettingsState> {
- late PersistenceService _service;
+class SettingsService extends PureNotifier<SettingsState> {
+ final PersistenceService _persistence;
- SettingsService();
+ SettingsService(this._persistence);
@override
- SettingsState init() {
- _service = ref.read(persistenceProvider);
- return SettingsState(
- showToken: _service.getShowToken(),
- alias: _service.getAlias(),
- theme: _service.getTheme(),
- colorMode: _service.getColorMode(),
- locale: _service.getLocale(),
- port: _service.getPort(),
- multicastGroup: _service.getMulticastGroup(),
- destination: _service.getDestination(),
- saveToGallery: _service.isSaveToGallery(),
- saveToHistory: _service.isSaveToHistory(),
- quickSave: _service.isQuickSave(),
- autoFinish: _service.isAutoFinish(),
- minimizeToTray: _service.isMinimizeToTray(),
- launchAtStartup: _service.isLaunchAtStartup(),
- autoStartLaunchMinimized: _service.isAutoStartLaunchMinimized(),
- https: _service.isHttps(),
- sendMode: _service.getSendMode(),
- saveWindowPlacement: _service.getSaveWindowPlacement(),
- enableAnimations: _service.getEnableAnimations(),
- deviceType: _service.getDeviceType(),
- deviceModel: _service.getDeviceModel(),
- );
- }
+ SettingsState init() => SettingsState(
+ showToken: _persistence.getShowToken(),
+ alias: _persistence.getAlias(),
+ theme: _persistence.getTheme(),
+ colorMode: _persistence.getColorMode(),
+ locale: _persistence.getLocale(),
+ port: _persistence.getPort(),
+ multicastGroup: _persistence.getMulticastGroup(),
+ destination: _persistence.getDestination(),
+ saveToGallery: _persistence.isSaveToGallery(),
+ saveToHistory: _persistence.isSaveToHistory(),
+ quickSave: _persistence.isQuickSave(),
+ autoFinish: _persistence.isAutoFinish(),
+ minimizeToTray: _persistence.isMinimizeToTray(),
+ launchAtStartup: _persistence.isLaunchAtStartup(),
+ autoStartLaunchMinimized: _persistence.isAutoStartLaunchMinimized(),
+ https: _persistence.isHttps(),
+ sendMode: _persistence.getSendMode(),
+ saveWindowPlacement: _persistence.getSaveWindowPlacement(),
+ enableAnimations: _persistence.getEnableAnimations(),
+ deviceType: _persistence.getDeviceType(),
+ deviceModel: _persistence.getDeviceModel(),
+ );
Future<void> setAlias(String alias) async {
- await _service.setAlias(alias);
+ await _persistence.setAlias(alias);
state = state.copyWith(
alias: alias,
);
}
Future<void> setTheme(ThemeMode theme) async {
- await _service.setTheme(theme);
+ await _persistence.setTheme(theme);
state = state.copyWith(
theme: theme,
);
}
Future<void> setColorMode(ColorMode mode) async {
- await _service.setColorMode(mode);
+ await _persistence.setColorMode(mode);
state = state.copyWith(
colorMode: mode,
);
}
Future<void> setLocale(AppLocale? locale) async {
- await _service.setLocale(locale);
+ await _persistence.setLocale(locale);
state = state.copyWith(
locale: locale,
);
}
Future<void> setPort(int port) async {
- await _service.setPort(port);
+ await _persistence.setPort(port);
state = state.copyWith(
port: port,
);
}
Future<void> setMulticastGroup(String group) async {
- await _service.setMulticastGroup(group);
+ await _persistence.setMulticastGroup(group);
state = state.copyWith(
multicastGroup: group,
);
}
Future<void> setDestination(String? destination) async {
- await _service.setDestination(destination);
+ await _persistence.setDestination(destination);
state = state.copyWith(
destination: destination,
);
}
Future<void> setSaveToGallery(bool saveToGallery) async {
- await _service.setSaveToGallery(saveToGallery);
+ await _persistence.setSaveToGallery(saveToGallery);
state = state.copyWith(
saveToGallery: saveToGallery,
);
}
Future<void> setSaveToHistory(bool saveToHistory) async {
- await _service.setSaveToHistory(saveToHistory);
+ await _persistence.setSaveToHistory(saveToHistory);
state = state.copyWith(
saveToHistory: saveToHistory,
);
}
Future<void> setQuickSave(bool quickSave) async {
- await _service.setQuickSave(quickSave);
+ await _persistence.setQuickSave(quickSave);
state = state.copyWith(
quickSave: quickSave,
);
}
Future<void> setAutoFinish(bool autoFinish) async {
- await _service.setAutoFinish(autoFinish);
+ await _persistence.setAutoFinish(autoFinish);
state = state.copyWith(
autoFinish: autoFinish,
);
}
Future<void> setMinimizeToTray(bool minimizeToTray) async {
- await _service.setMinimizeToTray(minimizeToTray);
+ await _persistence.setMinimizeToTray(minimizeToTray);
state = state.copyWith(
minimizeToTray: minimizeToTray,
);
}
Future<void> setLaunchAtStartup(bool launchAtStartup) async {
- await _service.setLaunchAtStartup(launchAtStartup);
+ await _persistence.setLaunchAtStartup(launchAtStartup);
state = state.copyWith(
launchAtStartup: launchAtStartup,
);
}
Future<void> setAutoStartLaunchMinimized(bool launchMinimized) async {
- await _service.setAutoStartLaunchMinimized(launchMinimized);
+ await _persistence.setAutoStartLaunchMinimized(launchMinimized);
state = state.copyWith(
autoStartLaunchMinimized: launchMinimized,
);
}
Future<void> setHttps(bool https) async {
- await _service.setHttps(https);
+ await _persistence.setHttps(https);
state = state.copyWith(
https: https,
);
}
Future<void> setSendMode(SendMode mode) async {
- await _service.setSendMode(mode);
+ await _persistence.setSendMode(mode);
state = state.copyWith(
sendMode: mode,
);
}
Future<void> setSaveWindowPlacement(bool savePlacement) async {
- await _service.setSaveWindowPlacement(savePlacement);
+ await _persistence.setSaveWindowPlacement(savePlacement);
state = state.copyWith(
saveWindowPlacement: savePlacement,
);
}
Future<void> setEnableAnimations(bool enableAnimations) async {
- await _service.setEnableAnimations(enableAnimations);
+ await _persistence.setEnableAnimations(enableAnimations);
state = state.copyWith(
enableAnimations: enableAnimations,
);
}
Future<void> setDeviceType(DeviceType deviceType) async {
- await _service.setDeviceType(deviceType);
+ await _persistence.setDeviceType(deviceType);
state = state.copyWith(
deviceType: deviceType,
);
}
Future<void> setDeviceModel(String deviceModel) async {
- await _service.setDeviceModel(deviceModel);
+ await _persistence.setDeviceModel(deviceModel);
state = state.copyWith(
deviceModel: deviceModel,
);