This commit is contained in:
2026-02-27 21:12:56 +08:00
commit a878084cbb
233 changed files with 22988 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../../../../backend/api/commands.dart' as commands;
part 'settings_controller.g.dart';
class SettingsState {
const SettingsState({
required this.hostname,
required this.savePath,
required this.autoAccept,
required this.saveHistory,
required this.enableTls,
});
final String hostname;
final String savePath;
final bool autoAccept;
final bool saveHistory;
final bool enableTls;
SettingsState copyWith({
String? hostname,
String? savePath,
bool? autoAccept,
bool? saveHistory,
bool? enableTls,
}) {
return SettingsState(
hostname: hostname ?? this.hostname,
savePath: savePath ?? this.savePath,
autoAccept: autoAccept ?? this.autoAccept,
saveHistory: saveHistory ?? this.saveHistory,
enableTls: enableTls ?? this.enableTls,
);
}
}
@riverpod
class SettingsController extends _$SettingsController {
@override
Future<SettingsState> build() async {
final values = await Future.wait([
commands.getHostname(),
commands.getSavePath(),
commands.getAutoAccept(),
commands.getSaveHistory(),
commands.getEnableTls(),
]);
return SettingsState(
hostname: values[0] as String,
savePath: values[1] as String,
autoAccept: values[2] as bool,
saveHistory: values[3] as bool,
enableTls: values[4] as bool,
);
}
Future<void> updateHostname(String value) async {
await commands.setHostname(hostname: value);
final current = state.value;
if (current != null) {
state = AsyncData(current.copyWith(hostname: value));
}
}
Future<void> updateSavePath(String value) async {
await commands.setSavePath(savePath: value);
final current = state.value;
if (current != null) {
state = AsyncData(current.copyWith(savePath: value));
}
}
Future<void> updateAutoAccept(bool value) async {
await commands.setAutoAccept(autoAccept: value);
final current = state.value;
if (current != null) {
state = AsyncData(current.copyWith(autoAccept: value));
}
}
Future<void> updateSaveHistory(bool value) async {
await commands.setSaveHistory(saveHistory: value);
final current = state.value;
if (current != null) {
state = AsyncData(current.copyWith(saveHistory: value));
}
}
Future<void> updateEnableTls(bool value) async {
await commands.setEnableTls(enableTls: value);
final current = state.value;
if (current != null) {
state = AsyncData(current.copyWith(enableTls: value));
}
}
}