mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-13 03:02:22 +01:00
47 lines
1.9 KiB
Dart
47 lines
1.9 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:fluent_ui/fluent_ui.dart' hide showDialog;
|
|
import 'package:get/get.dart';
|
|
import 'package:get_storage/get_storage.dart';
|
|
import 'package:reboot_common/common.dart';
|
|
|
|
const String kDefaultServerName = "Reboot Game Server";
|
|
const String kDefaultDescription = "Just another server";
|
|
|
|
class HostingController extends GetxController {
|
|
late final GetStorage _storage;
|
|
late final TextEditingController name;
|
|
late final TextEditingController description;
|
|
late final TextEditingController password;
|
|
late final RxBool showPassword;
|
|
late final RxBool discoverable;
|
|
late final RxBool started;
|
|
late final Rxn<GameInstance> instance;
|
|
|
|
HostingController() {
|
|
_storage = GetStorage("reboot_hosting");
|
|
name = TextEditingController(text: _storage.read("name") ?? kDefaultServerName);
|
|
name.addListener(() => _storage.write("name", name.text));
|
|
description = TextEditingController(text: _storage.read("description") ?? kDefaultDescription);
|
|
description.addListener(() => _storage.write("description", description.text));
|
|
password = TextEditingController(text: _storage.read("password") ?? "");
|
|
password.addListener(() => _storage.write("password", password.text));
|
|
discoverable = RxBool(_storage.read("discoverable") ?? true);
|
|
discoverable.listen((value) => _storage.write("discoverable", value));
|
|
started = RxBool(false);
|
|
showPassword = RxBool(false);
|
|
var serializedInstance = _storage.read("instance");
|
|
instance = Rxn(serializedInstance != null ? GameInstance.fromJson(jsonDecode(serializedInstance)) : null);
|
|
instance.listen((value) => _storage.write("instance", jsonEncode(value?.toJson())));
|
|
}
|
|
|
|
void reset() {
|
|
name.text = kDefaultServerName;
|
|
description.text = kDefaultDescription;
|
|
showPassword.value = false;
|
|
discoverable.value = false;
|
|
started.value = false;
|
|
instance.value = null;
|
|
}
|
|
}
|