From e23a9da1a8f1a79fe7906cfd7d8db1f29504fd32 Mon Sep 17 00:00:00 2001 From: 21pages Date: Tue, 18 Jun 2024 08:29:10 +0800 Subject: [PATCH] sync get option in android setting (#8393) Signed-off-by: 21pages --- flutter/ios_arm64.sh | 2 +- .../desktop/pages/desktop_setting_page.dart | 4 +- flutter/lib/mobile/pages/settings_page.dart | 106 ++++-------------- src/flutter_ffi.rs | 4 +- 4 files changed, 28 insertions(+), 88 deletions(-) diff --git a/flutter/ios_arm64.sh b/flutter/ios_arm64.sh index 5a6291755..579baaa6d 100755 --- a/flutter/ios_arm64.sh +++ b/flutter/ios_arm64.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -cargo build --features flutter --release --target aarch64-apple-ios --lib +cargo build --features flutter,hwcodec --release --target aarch64-apple-ios --lib diff --git a/flutter/lib/desktop/pages/desktop_setting_page.dart b/flutter/lib/desktop/pages/desktop_setting_page.dart index 6cb2b2329..04385ce50 100644 --- a/flutter/lib/desktop/pages/desktop_setting_page.dart +++ b/flutter/lib/desktop/pages/desktop_setting_page.dart @@ -504,9 +504,9 @@ class _GeneralState extends State<_General> { Widget record(BuildContext context) { final showRootDir = isWindows && bind.mainIsInstalled(); return futureBuilder(future: () async { - String user_dir = await bind.mainVideoSaveDirectory(root: false); + String user_dir = bind.mainVideoSaveDirectory(root: false); String root_dir = - showRootDir ? await bind.mainVideoSaveDirectory(root: true) : ''; + showRootDir ? bind.mainVideoSaveDirectory(root: true) : ''; bool user_dir_exists = await Directory(user_dir).exists(); bool root_dir_exists = showRootDir ? await Directory(root_dir).exists() : false; diff --git a/flutter/lib/mobile/pages/settings_page.dart b/flutter/lib/mobile/pages/settings_page.dart index 3610b94e1..d1e2ff55a 100644 --- a/flutter/lib/mobile/pages/settings_page.dart +++ b/flutter/lib/mobile/pages/settings_page.dart @@ -89,6 +89,27 @@ class _SettingsState extends State with WidgetsBindingObserver { super.initState(); WidgetsBinding.instance.addObserver(this); + _enableAbr = option2bool( + kOptionEnableAbr, bind.mainGetOptionSync(key: kOptionEnableAbr)); + _denyLANDiscovery = !option2bool(kOptionEnableLanDiscovery, + bind.mainGetOptionSync(key: kOptionEnableLanDiscovery)); + _onlyWhiteList = (bind.mainGetOptionSync(key: kOptionWhitelist)) != + defaultOptionWhitelist; + _enableDirectIPAccess = option2bool( + kOptionDirectServer, bind.mainGetOptionSync(key: kOptionDirectServer)); + _enableRecordSession = option2bool(kOptionEnableRecordSession, + bind.mainGetOptionSync(key: kOptionEnableRecordSession)); + _enableHardwareCodec = option2bool(kOptionEnableHwcodec, + bind.mainGetOptionSync(key: kOptionEnableHwcodec)); + _autoRecordIncomingSession = option2bool(kOptionAllowAutoRecordIncoming, + bind.mainGetOptionSync(key: kOptionAllowAutoRecordIncoming)); + _localIP = bind.mainGetOptionSync(key: 'local-ip-addr'); + _directAccessPort = bind.mainGetOptionSync(key: kOptionDirectAccessPort); + _allowAutoDisconnect = option2bool(kOptionAllowAutoDisconnect, + bind.mainGetOptionSync(key: kOptionAllowAutoDisconnect)); + _autoDisconnectTimeout = + bind.mainGetOptionSync(key: kOptionAutoDisconnectTimeout); + () async { var update = false; @@ -134,69 +155,6 @@ class _SettingsState extends State with WidgetsBindingObserver { _keepScreenOn = keepScreenOn; } - final enableAbrRes = option2bool( - kOptionEnableAbr, await bind.mainGetOption(key: kOptionEnableAbr)); - if (enableAbrRes != _enableAbr) { - update = true; - _enableAbr = enableAbrRes; - } - - final denyLanDiscovery = !option2bool(kOptionEnableLanDiscovery, - await bind.mainGetOption(key: kOptionEnableLanDiscovery)); - if (denyLanDiscovery != _denyLANDiscovery) { - update = true; - _denyLANDiscovery = denyLanDiscovery; - } - - final onlyWhiteList = (await bind.mainGetOption(key: kOptionWhitelist)) != - defaultOptionWhitelist; - if (onlyWhiteList != _onlyWhiteList) { - update = true; - _onlyWhiteList = onlyWhiteList; - } - - final enableDirectIPAccess = option2bool(kOptionDirectServer, - await bind.mainGetOption(key: kOptionDirectServer)); - if (enableDirectIPAccess != _enableDirectIPAccess) { - update = true; - _enableDirectIPAccess = enableDirectIPAccess; - } - - final enableRecordSession = option2bool(kOptionEnableRecordSession, - await bind.mainGetOption(key: kOptionEnableRecordSession)); - if (enableRecordSession != _enableRecordSession) { - update = true; - _enableRecordSession = enableRecordSession; - } - - final enableHardwareCodec = option2bool(kOptionEnableHwcodec, - await bind.mainGetOption(key: kOptionEnableHwcodec)); - if (_enableHardwareCodec != enableHardwareCodec) { - update = true; - _enableHardwareCodec = enableHardwareCodec; - } - - final autoRecordIncomingSession = option2bool( - kOptionAllowAutoRecordIncoming, - await bind.mainGetOption(key: kOptionAllowAutoRecordIncoming)); - if (autoRecordIncomingSession != _autoRecordIncomingSession) { - update = true; - _autoRecordIncomingSession = autoRecordIncomingSession; - } - - final localIP = await bind.mainGetOption(key: 'local-ip-addr'); - if (localIP != _localIP) { - update = true; - _localIP = localIP; - } - - final directAccessPort = - await bind.mainGetOption(key: kOptionDirectAccessPort); - if (directAccessPort != _directAccessPort) { - update = true; - _directAccessPort = directAccessPort; - } - final fingerprint = await bind.mainGetFingerprint(); if (_fingerprint != fingerprint) { update = true; @@ -208,21 +166,6 @@ class _SettingsState extends State with WidgetsBindingObserver { update = true; _buildDate = buildDate; } - - final allowAutoDisconnect = option2bool(kOptionAllowAutoDisconnect, - await bind.mainGetOption(key: kOptionAllowAutoDisconnect)); - if (allowAutoDisconnect != _allowAutoDisconnect) { - update = true; - _allowAutoDisconnect = allowAutoDisconnect; - } - - final autoDisconnectTimeout = - await bind.mainGetOption(key: kOptionAutoDisconnectTimeout); - if (autoDisconnectTimeout != _autoDisconnectTimeout) { - update = true; - _autoDisconnectTimeout = autoDisconnectTimeout; - } - if (update) { setState(() {}); } @@ -661,11 +604,8 @@ class _SettingsState extends State with WidgetsBindingObserver { title: Text(translate('Automatically record incoming sessions')), leading: Icon(Icons.videocam), - description: FutureBuilder( - builder: (ctx, data) => Offstage( - offstage: !data.hasData, - child: Text("${translate("Directory")}: ${data.data}")), - future: bind.mainVideoSaveDirectory(root: false)), + description: Text( + "${translate("Directory")}: ${bind.mainVideoSaveDirectory(root: false)}"), initialValue: _autoRecordIncomingSession, onToggle: isOptionFixed(kOptionAllowAutoRecordIncoming) ? null diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index a44c3d095..d34ecb14d 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -1194,8 +1194,8 @@ pub fn main_change_language(lang: String) { send_to_cm(&crate::ipc::Data::Language(lang)); } -pub fn main_video_save_directory(root: bool) -> String { - video_save_directory(root) +pub fn main_video_save_directory(root: bool) -> SyncReturn { + SyncReturn(video_save_directory(root)) } pub fn main_set_user_default_option(key: String, value: String) {