2022-08-29 18:48:12 +08:00
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
|
|
import '../consts.dart';
|
2022-09-07 12:20:53 +08:00
|
|
|
|
|
|
|
// TODO: A lot of dup code.
|
2022-08-29 18:48:12 +08:00
|
|
|
|
|
|
|
class PrivacyModeState {
|
|
|
|
static String tag(String id) => 'privacy_mode_$id';
|
|
|
|
|
|
|
|
static void init(String id) {
|
2022-09-03 10:39:33 +08:00
|
|
|
final key = tag(id);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final RxBool state = false.obs;
|
|
|
|
Get.put(state, tag: key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
2023-03-03 11:51:33 +08:00
|
|
|
} else {
|
|
|
|
Get.find<RxBool>(tag: key).value = false;
|
2022-09-03 10:39:33 +08:00
|
|
|
}
|
2022-08-29 18:48:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static RxBool find(String id) => Get.find<RxBool>(tag: tag(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
class BlockInputState {
|
|
|
|
static String tag(String id) => 'block_input_$id';
|
|
|
|
|
|
|
|
static void init(String id) {
|
2022-09-03 10:39:33 +08:00
|
|
|
final key = tag(id);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final RxBool state = false.obs;
|
|
|
|
Get.put(state, tag: key);
|
2023-03-03 11:51:33 +08:00
|
|
|
} else {
|
|
|
|
Get.find<RxBool>(tag: key).value = false;
|
2022-09-03 10:39:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
2022-08-29 18:48:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static RxBool find(String id) => Get.find<RxBool>(tag: tag(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
class CurrentDisplayState {
|
|
|
|
static String tag(String id) => 'current_display_$id';
|
|
|
|
|
|
|
|
static void init(String id) {
|
2022-09-03 10:39:33 +08:00
|
|
|
final key = tag(id);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final RxInt state = RxInt(0);
|
|
|
|
Get.put(state, tag: key);
|
2023-03-03 11:51:33 +08:00
|
|
|
} else {
|
|
|
|
Get.find<RxInt>(tag: key).value = 0;
|
2022-09-03 10:39:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
2022-08-29 18:48:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static RxInt find(String id) => Get.find<RxInt>(tag: tag(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConnectionType {
|
|
|
|
final Rx<String> _secure = kInvalidValueStr.obs;
|
|
|
|
final Rx<String> _direct = kInvalidValueStr.obs;
|
|
|
|
|
|
|
|
Rx<String> get secure => _secure;
|
|
|
|
Rx<String> get direct => _direct;
|
|
|
|
|
2022-08-29 22:46:19 +08:00
|
|
|
static String get strSecure => 'secure';
|
|
|
|
static String get strInsecure => 'insecure';
|
|
|
|
static String get strDirect => '';
|
|
|
|
static String get strIndirect => '_relay';
|
|
|
|
|
2022-08-29 18:48:12 +08:00
|
|
|
void setSecure(bool v) {
|
2022-08-29 22:46:19 +08:00
|
|
|
_secure.value = v ? strSecure : strInsecure;
|
2022-08-29 18:48:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setDirect(bool v) {
|
2022-08-29 22:46:19 +08:00
|
|
|
_direct.value = v ? strDirect : strIndirect;
|
2022-08-29 18:48:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() {
|
|
|
|
return _secure.value != kInvalidValueStr &&
|
|
|
|
_direct.value != kInvalidValueStr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConnectionTypeState {
|
|
|
|
static String tag(String id) => 'connection_type_$id';
|
|
|
|
|
|
|
|
static void init(String id) {
|
2022-08-29 22:46:19 +08:00
|
|
|
final key = tag(id);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final ConnectionType collectionType = ConnectionType();
|
|
|
|
Get.put(collectionType, tag: key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
2022-08-29 18:48:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static ConnectionType find(String id) =>
|
|
|
|
Get.find<ConnectionType>(tag: tag(id));
|
|
|
|
}
|
2022-09-03 10:39:33 +08:00
|
|
|
|
2023-04-19 14:39:22 +08:00
|
|
|
class FingerprintState {
|
|
|
|
static String tag(String id) => 'fingerprint_$id';
|
|
|
|
|
|
|
|
static void init(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final RxString state = ''.obs;
|
|
|
|
Get.put(state, tag: key);
|
|
|
|
} else {
|
|
|
|
Get.find<RxString>(tag: key).value = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static RxString find(String id) => Get.find<RxString>(tag: tag(id));
|
|
|
|
}
|
|
|
|
|
2022-09-03 10:39:33 +08:00
|
|
|
class ShowRemoteCursorState {
|
|
|
|
static String tag(String id) => 'show_remote_cursor_$id';
|
|
|
|
|
|
|
|
static void init(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final RxBool state = false.obs;
|
|
|
|
Get.put(state, tag: key);
|
2023-03-03 11:51:33 +08:00
|
|
|
} else {
|
|
|
|
Get.find<RxBool>(tag: key).value = false;
|
2022-09-03 10:39:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static RxBool find(String id) => Get.find<RxBool>(tag: tag(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
class KeyboardEnabledState {
|
|
|
|
static String tag(String id) => 'keyboard_enabled_$id';
|
|
|
|
|
|
|
|
static void init(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
// Server side, default true
|
|
|
|
final RxBool state = true.obs;
|
|
|
|
Get.put(state, tag: key);
|
2023-03-03 11:51:33 +08:00
|
|
|
} else {
|
|
|
|
Get.find<RxBool>(tag: key).value = true;
|
2022-09-03 10:39:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static RxBool find(String id) => Get.find<RxBool>(tag: tag(id));
|
|
|
|
}
|
2022-09-07 12:20:53 +08:00
|
|
|
|
|
|
|
class RemoteCursorMovedState {
|
|
|
|
static String tag(String id) => 'remote_cursor_moved_$id';
|
|
|
|
|
|
|
|
static void init(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final RxBool state = false.obs;
|
|
|
|
Get.put(state, tag: key);
|
2023-03-03 11:51:33 +08:00
|
|
|
} else {
|
|
|
|
Get.find<RxBool>(tag: key).value = false;
|
2022-09-07 12:20:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id) {
|
|
|
|
final key = tag(id);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static RxBool find(String id) => Get.find<RxBool>(tag: tag(id));
|
|
|
|
}
|
2022-10-08 17:27:30 +08:00
|
|
|
|
|
|
|
class RemoteCountState {
|
|
|
|
static String tag() => 'remote_count_';
|
|
|
|
|
|
|
|
static void init() {
|
|
|
|
final key = tag();
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final RxInt state = 1.obs;
|
|
|
|
Get.put(state, tag: key);
|
2023-03-03 11:51:33 +08:00
|
|
|
} else {
|
|
|
|
Get.find<RxInt>(tag: key).value = 1;
|
2022-10-08 17:27:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete() {
|
|
|
|
final key = tag();
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static RxInt find() => Get.find<RxInt>(tag: tag());
|
|
|
|
}
|
2022-11-12 22:33:10 +08:00
|
|
|
|
2022-11-16 18:07:58 +08:00
|
|
|
class PeerBoolOption {
|
|
|
|
static String tag(String id, String opt) => 'peer_{$opt}_$id';
|
|
|
|
|
|
|
|
static void init(String id, String opt, bool Function() init_getter) {
|
|
|
|
final key = tag(id, opt);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final RxBool value = RxBool(init_getter());
|
|
|
|
Get.put(value, tag: key);
|
2023-03-03 11:51:33 +08:00
|
|
|
} else {
|
|
|
|
Get.find<RxBool>(tag: key).value = init_getter();
|
2022-11-16 18:07:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id, String opt) {
|
|
|
|
final key = tag(id, opt);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static RxBool find(String id, String opt) =>
|
|
|
|
Get.find<RxBool>(tag: tag(id, opt));
|
|
|
|
}
|
|
|
|
|
2022-11-12 22:33:10 +08:00
|
|
|
class PeerStringOption {
|
|
|
|
static String tag(String id, String opt) => 'peer_{$opt}_$id';
|
|
|
|
|
|
|
|
static void init(String id, String opt, String Function() init_getter) {
|
|
|
|
final key = tag(id, opt);
|
|
|
|
if (!Get.isRegistered(tag: key)) {
|
|
|
|
final RxString value = RxString(init_getter());
|
|
|
|
Get.put(value, tag: key);
|
2023-03-03 11:51:33 +08:00
|
|
|
} else {
|
|
|
|
Get.find<RxString>(tag: key).value = init_getter();
|
2022-11-12 22:33:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete(String id, String opt) {
|
|
|
|
final key = tag(id, opt);
|
|
|
|
if (Get.isRegistered(tag: key)) {
|
|
|
|
Get.delete(tag: key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static RxString find(String id, String opt) =>
|
|
|
|
Get.find<RxString>(tag: tag(id, opt));
|
|
|
|
}
|
2023-04-12 09:41:13 +08:00
|
|
|
|
|
|
|
initSharedStates(String id) {
|
|
|
|
PrivacyModeState.init(id);
|
|
|
|
BlockInputState.init(id);
|
|
|
|
CurrentDisplayState.init(id);
|
|
|
|
KeyboardEnabledState.init(id);
|
|
|
|
ShowRemoteCursorState.init(id);
|
|
|
|
RemoteCursorMovedState.init(id);
|
2023-04-19 14:39:22 +08:00
|
|
|
FingerprintState.init(id);
|
2023-04-12 09:41:13 +08:00
|
|
|
PeerBoolOption.init(id, 'zoom-cursor', () => false);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeSharedStates(String id) {
|
|
|
|
PrivacyModeState.delete(id);
|
|
|
|
BlockInputState.delete(id);
|
|
|
|
CurrentDisplayState.delete(id);
|
|
|
|
ShowRemoteCursorState.delete(id);
|
|
|
|
KeyboardEnabledState.delete(id);
|
|
|
|
RemoteCursorMovedState.delete(id);
|
2023-04-19 14:39:22 +08:00
|
|
|
FingerprintState.delete(id);
|
2023-04-12 09:41:13 +08:00
|
|
|
PeerBoolOption.delete(id, 'zoom-cursor');
|
|
|
|
}
|