import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../data/config_repository.dart'; import '../domain/models.dart'; class AppConfigController extends StateNotifier { AppConfigController(this._repository, AppConfig initial) : super(initial.copyWith(minimizeToTray: false, startMinimized: false)); final ConfigRepository _repository; Future updateConfig(AppConfig config) async { state = config; await _repository.saveConfig(state); } Future setLastWallet(WalletInfo? wallet) async { await updateConfig(state.copyWith(lastWallet: wallet)); } Future setNodeConfig(NodeConfig nodeConfig) async { await updateConfig(state.copyWith(nodeConfig: nodeConfig)); } Future setMinimizeToTray(bool value) async { await updateConfig(state.copyWith(minimizeToTray: value)); } Future setStartMinimized(bool value) async { await updateConfig(state.copyWith(startMinimized: value)); } Future setAutoSync(bool value) async { await updateConfig(state.copyWith(autoSync: value)); } Future setAutoSyncInterval(Duration interval) async { await updateConfig(state.copyWith(autoSyncInterval: interval)); } Future setLanguage(LanguagePreference preference) async { await updateConfig(state.copyWith(languagePreference: preference)); } Future setLocalNodeArgs(List args) async { await updateConfig(state.copyWith(localNodeArgs: args)); } Future setMiningConfig(MiningConfig config) async { await updateConfig(state.copyWith(miningConfig: config)); } Future setMiningMode(MiningMode mode) async { await updateConfig( state.copyWith(miningConfig: state.miningConfig.copyWith(mode: mode)), ); } Future setMiningCpuThreads(int value) async { await updateConfig( state.copyWith( miningConfig: state.miningConfig.copyWith(cpuThreads: value), ), ); } Future setMiningPoolHost(String value) async { await updateConfig( state.copyWith( miningConfig: state.miningConfig.copyWith(poolHost: value), ), ); } Future setMiningPoolPort(int value) async { await updateConfig( state.copyWith( miningConfig: state.miningConfig.copyWith(poolPort: value), ), ); } Future setMiningApiPort(int value) async { await updateConfig( state.copyWith( miningConfig: state.miningConfig.copyWith(apiPort: value), ), ); } Future setP2poolStratum(String value) async { await updateConfig(state.copyWith(p2poolStratum: value)); } Future setP2poolP2p(String value) async { await updateConfig(state.copyWith(p2poolP2p: value)); } Future setP2poolStartMining(bool value) async { await updateConfig(state.copyWith(p2poolStartMining: value)); } Future setP2poolMiningThreads(int value) async { await updateConfig(state.copyWith(p2poolMiningThreads: value)); } Future hideSubaddress({ required String walletPath, required String address, }) async { if (walletPath.isEmpty || address.isEmpty) { return; } final updated = Map>.from(state.hiddenSubaddresses); final current = Set.from(updated[walletPath] ?? const []); current.add(address); updated[walletPath] = current.toList(); await updateConfig(state.copyWith(hiddenSubaddresses: updated)); } Future unhideSubaddress({ required String walletPath, required String address, }) async { if (walletPath.isEmpty || address.isEmpty) { return; } final updated = Map>.from(state.hiddenSubaddresses); final current = Set.from(updated[walletPath] ?? const []); if (!current.remove(address)) { return; } if (current.isEmpty) { updated.remove(walletPath); } else { updated[walletPath] = current.toList(); } await updateConfig(state.copyWith(hiddenSubaddresses: updated)); } Future setHiddenSubaddresses({ required String walletPath, required List addresses, }) async { if (walletPath.isEmpty) { return; } final updated = Map>.from(state.hiddenSubaddresses); if (addresses.isEmpty) { updated.remove(walletPath); } else { updated[walletPath] = addresses; } await updateConfig(state.copyWith(hiddenSubaddresses: updated)); } }