fix, settings on main window

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-07-23 17:07:30 +08:00
parent d49dd9377e
commit b80051bb35
3 changed files with 347 additions and 356 deletions

@ -1269,6 +1269,19 @@ String bool2option(String option, bool b) {
return res;
}
mainSetBoolOption(String key, bool value) async {
String v = bool2option(key, value);
await bind.mainSetOption(key: key, value: v);
}
Future<bool> mainGetBoolOption(String key) async {
return option2bool(key, await bind.mainGetOption(key: key));
}
bool mainGetBoolOptionSync(String key) {
return option2bool(key, bind.mainGetOptionSync(key: key));
}
Future<bool> matchPeer(String searchText, Peer peer) async {
if (searchText.isEmpty) {
return true;

@ -385,20 +385,17 @@ class _GeneralState extends State<_General> {
Widget record(BuildContext context) {
return futureBuilder(future: () async {
String customDirectory =
await bind.mainGetOption(key: 'video-save-directory');
String defaultDirectory = await bind.mainDefaultVideoSaveDirectory();
String dir;
if (customDirectory.isNotEmpty) {
dir = customDirectory;
} else {
dir = defaultDirectory;
}
// canLaunchUrl blocked on windows portable, user SYSTEM
return {'dir': dir, 'canlaunch': true};
return {'dir': defaultDirectory, 'canlaunch': true};
}(), hasData: (data) {
Map<String, dynamic> map = data as Map<String, dynamic>;
String dir = map['dir']!;
String customDirectory =
bind.mainGetOptionSync(key: 'video-save-directory');
if (customDirectory.isNotEmpty) {
dir = customDirectory;
}
bool canlaunch = map['canlaunch']! as bool;
return _Card(title: 'Recording', children: [
@ -444,8 +441,7 @@ class _GeneralState extends State<_General> {
Widget language() {
return futureBuilder(future: () async {
String langs = await bind.mainGetLangs();
String lang = bind.mainGetLocalOption(key: kCommConfKeyLang);
return {'langs': langs, 'lang': lang};
return {'langs': langs};
}(), hasData: (res) {
Map<String, String> data = res as Map<String, String>;
List<dynamic> langsList = jsonDecode(data['langs']!);
@ -454,7 +450,7 @@ class _GeneralState extends State<_General> {
List<String> values = langsMap.values.toList();
keys.insert(0, '');
values.insert(0, translate('Default'));
String currentKey = data['lang']!;
String currentKey = bind.mainGetLocalOption(key: kCommConfKeyLang);
if (!keys.contains(currentKey)) {
currentKey = '';
}
@ -529,10 +525,7 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
Widget permissions(context) {
bool enabled = !locked;
return futureBuilder(future: () async {
return await bind.mainGetOption(key: 'access-mode');
}(), hasData: (data) {
String accessMode = data! as String;
String accessMode = bind.mainGetOptionSync(key: 'access-mode');
_AccessMode mode;
if (accessMode == 'full') {
mode = _AccessMode.full;
@ -601,7 +594,6 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
],
),
]);
});
}
Widget password(BuildContext context) {
@ -759,17 +751,11 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
return [
_OptionCheckBox(context, 'Enable Direct IP Access', 'direct-server',
update: update, enabled: !locked),
futureBuilder(
future: () async {
String enabled = await bind.mainGetOption(key: 'direct-server');
String port = await bind.mainGetOption(key: 'direct-access-port');
return {'enabled': enabled, 'port': port};
}(),
hasData: (data) {
bool enabled =
option2bool('direct-server', data['enabled'].toString());
() {
bool enabled = option2bool(
'direct-server', bind.mainGetOptionSync(key: 'direct-server'));
if (!enabled) applyEnabled.value = false;
controller.text = data['port'].toString();
controller.text = bind.mainGetOptionSync(key: 'direct-access-port');
return Offstage(
offstage: !enabled,
child: _SubLabeledWidget(
@ -810,20 +796,16 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
enabled: enabled && !locked,
),
);
},
),
}(),
];
}
Widget whitelist() {
bool enabled = !locked;
return futureBuilder(future: () async {
return await bind.mainGetOption(key: 'whitelist');
}(), hasData: (data) {
RxBool hasWhitelist = (data as String).isNotEmpty.obs;
RxBool hasWhitelist =
bind.mainGetOptionSync(key: 'whitelist').isNotEmpty.obs;
update() async {
hasWhitelist.value =
(await bind.mainGetOption(key: 'whitelist')).isNotEmpty;
hasWhitelist.value = bind.mainGetOptionSync(key: 'whitelist').isNotEmpty;
}
onChanged(bool? checked) async {
@ -848,8 +830,7 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
Expanded(
child: Text(
translate('Use IP Whitelisting'),
style:
TextStyle(color: _disabledTextColor(context, enabled)),
style: TextStyle(color: _disabledTextColor(context, enabled)),
))
],
)),
@ -858,7 +839,6 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
onChanged(!hasWhitelist.value);
},
).marginOnly(left: _kCheckBoxLeftMargin);
});
}
Widget hide_cm(bool enabled) {
@ -943,11 +923,9 @@ class _NetworkState extends State<_Network> with AutomaticKeepAliveClientMixin {
}
server(bool enabled) {
return futureBuilder(future: () async {
return await bind.mainGetOptions();
}(), hasData: (data) {
// Setting page is not modal, oldOptions should only be used when getting options, never when setting.
Map<String, dynamic> oldOptions = jsonDecode(data! as String);
Map<String, dynamic> oldOptions =
jsonDecode(bind.mainGetOptionsSync() as String);
old(String key) {
return (oldOptions[key] ?? '').trim();
}
@ -1077,12 +1055,11 @@ class _NetworkState extends State<_Network> with AutomaticKeepAliveClientMixin {
children: [
Obx(() => _LabeledTextField(context, 'ID Server', idController,
idErrMsg.value, enabled, secure)),
Obx(() => _LabeledTextField(context, 'Relay Server',
relayController, relayErrMsg.value, enabled, secure)),
Obx(() => _LabeledTextField(context, 'Relay Server', relayController,
relayErrMsg.value, enabled, secure)),
Obx(() => _LabeledTextField(context, 'API Server', apiController,
apiErrMsg.value, enabled, secure)),
_LabeledTextField(
context, 'Key', keyController, '', enabled, secure),
_LabeledTextField(context, 'Key', keyController, '', enabled, secure),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [_Button('Apply', submit, enabled: enabled)],
@ -1090,7 +1067,6 @@ class _NetworkState extends State<_Network> with AutomaticKeepAliveClientMixin {
],
)
]);
});
}
}
@ -1662,18 +1638,14 @@ Widget _OptionCheckBox(BuildContext context, String label, String key,
bool enabled = true,
Icon? checkedIcon,
bool? fakeValue}) {
return futureBuilder(
future: bind.mainGetOption(key: key),
hasData: (data) {
bool value = option2bool(key, data.toString());
bool value = mainGetBoolOptionSync(key);
if (reverse) value = !value;
var ref = value.obs;
onChanged(option) async {
if (option != null) {
ref.value = option;
if (reverse) option = !option;
String value = bool2option(key, option);
await bind.mainSetOption(key: key, value: value);
await mainSetBoolOption(key, option);
ref.value = mainGetBoolOptionSync(key);
update?.call();
}
}
@ -1687,8 +1659,7 @@ Widget _OptionCheckBox(BuildContext context, String label, String key,
child: Obx(
() => Row(
children: [
Checkbox(
value: ref.value, onChanged: enabled ? onChanged : null)
Checkbox(value: ref.value, onChanged: enabled ? onChanged : null)
.marginOnly(right: 5),
Offstage(
offstage: !ref.value || checkedIcon == null,
@ -1708,7 +1679,6 @@ Widget _OptionCheckBox(BuildContext context, String label, String key,
}
: null,
);
});
}
// ignore: non_constant_identifier_names

@ -606,6 +606,10 @@ pub fn main_get_option(key: String) -> String {
get_option(key)
}
pub fn main_get_option_sync(key: String) -> SyncReturn<String> {
SyncReturn(get_option(key))
}
pub fn main_get_error() -> String {
get_error()
}
@ -626,6 +630,10 @@ pub fn main_get_options() -> String {
get_options()
}
pub fn main_get_options_sync() -> SyncReturn<String> {
SyncReturn(get_options())
}
pub fn main_set_options(json: String) {
let map: HashMap<String, String> = serde_json::from_str(&json).unwrap_or(HashMap::new());
if !map.is_empty() {