An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.
Rust androidanydeskdartflatpakflutterflutter-appsioslinuxmacosp2prdpremote-controlremote-desktoprustrust-langteamviewervncwaylandwindows
fix: custom client, option to bool (#8303)
fufesou9ab5512bfa07
diff --git a/flutter/lib/common.dart b/flutter/lib/common.dartindex c41eda690..d75805fe9 100644--- a/flutter/lib/common.dart+++ b/flutter/lib/common.dart@@ -1430,7 +1430,7 @@ bool option2bool(String option, String value) {if (option.startsWith("enable-")) {res = value != "N";} else if (option.startsWith("allow-") ||- option == "stop-service" ||+ option == kOptionStopService ||option == kOptionDirectServer ||option == "stop-rendezvous-service" ||option == kOptionForceAlwaysRelay) {@@ -1447,7 +1447,7 @@ String bool2option(String option, bool b) {if (option.startsWith('enable-')) {res = b ? defaultOptionYes : 'N';} else if (option.startsWith('allow-') ||- option == "stop-service" ||+ option == kOptionStopService ||option == kOptionDirectServer ||option == "stop-rendezvous-service" ||option == kOptionForceAlwaysRelay) {@@ -1485,9 +1485,9 @@ bool mainGetPeerBoolOptionSync(String id, String key) {return option2bool(key, bind.mainGetPeerOptionSync(id: id, key: key));}-mainSetPeerBoolOptionSync(String id, String key, bool v) {- bind.mainSetPeerOptionSync(id: id, key: key, value: bool2option(key, v));-}+// Don't use `option2bool()` and `bool2option()` to convert the session option.+// Use `sessionGetToggleOption()` and `sessionToggleOption()` instead.+// Because all session options use `Y` and `<Empty>` as values.Future<bool> matchPeer(String searchText, Peer peer) async {if (searchText.isEmpty) {@@ -2672,7 +2672,7 @@ Future<void> start_service(bool is_start) async {!isMacOS ||await callMainCheckSuperUserPermission();if (checked) {- bind.mainSetOption(key: "stop-service", value: is_start ? "" : "Y");+ mainSetBoolOption(kOptionStopService, !is_start);}}diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dartindex 2d194613f..ae3aef0b9 100644--- a/flutter/lib/consts.dart+++ b/flutter/lib/consts.dart@@ -133,6 +133,7 @@ const String kOptionAllowAlwaysSoftwareRender = "allow-always-software-render";const String kOptionEnableCheckUpdate = "enable-check-update";const String kOptionAllowLinuxHeadless = "allow-linux-headless";const String kOptionAllowRemoveWallpaper = "allow-remove-wallpaper";+const String kOptionStopService = "stop-service";const String kOptionToggleViewOnly = "view-only";diff --git a/flutter/lib/desktop/pages/desktop_home_page.dart b/flutter/lib/desktop/pages/desktop_home_page.dartindex fa065e049..54fae3e99 100644--- a/flutter/lib/desktop/pages/desktop_home_page.dart+++ b/flutter/lib/desktop/pages/desktop_home_page.dart@@ -671,7 +671,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>systemError = error;setState(() {});}- final v = await bind.mainGetOption(key: "stop-service") == "Y";+ final v = await mainGetBoolOption(kOptionStopService);if (v != svcStopped.value) {svcStopped.value = v;setState(() {});diff --git a/flutter/lib/mobile/pages/settings_page.dart b/flutter/lib/mobile/pages/settings_page.dartindex 418bd78c6..1b402f6a1 100644--- a/flutter/lib/mobile/pages/settings_page.dart+++ b/flutter/lib/mobile/pages/settings_page.dart@@ -103,8 +103,8 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {_enableAbr = enableAbrRes;}- final denyLanDiscovery = !option2bool('enable-lan-discovery',- await bind.mainGetOption(key: 'enable-lan-discovery'));+ final denyLanDiscovery = !option2bool(kOptionEnableLanDiscovery,+ await bind.mainGetOption(key: kOptionEnableLanDiscovery));if (denyLanDiscovery != _denyLANDiscovery) {update = true;_denyLANDiscovery = denyLanDiscovery;@@ -311,10 +311,8 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {onToggle: isOptionFixed(kOptionEnableAbr)? null: (v) async {- await bind.mainSetOption(- key: kOptionEnableAbr, value: v ? defaultOptionYes : "N");- final newValue =- await bind.mainGetOption(key: kOptionEnableAbr) != "N";+ await mainSetBoolOption(kOptionEnableAbr, v);+ final newValue = await mainGetBoolOption(kOptionEnableAbr);setState(() {_enableAbr = newValue;});@@ -326,12 +324,9 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {onToggle: isOptionFixed(kOptionEnableRecordSession)? null: (v) async {- await bind.mainSetOption(- key: kOptionEnableRecordSession,- value: v ? defaultOptionYes : "N");+ await mainSetBoolOption(kOptionEnableRecordSession, v);final newValue =- await bind.mainGetOption(key: kOptionEnableRecordSession) !=- "N";+ await mainGetBoolOption(kOptionEnableRecordSession);setState(() {_enableRecordSession = newValue;});@@ -587,12 +582,9 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {onToggle: isOptionFixed(kOptionEnableHwcodec)? null: (v) async {- await bind.mainSetOption(- key: kOptionEnableHwcodec,- value: v ? defaultOptionYes : "N");+ await mainSetBoolOption(kOptionEnableHwcodec, v);final newValue =- await bind.mainGetOption(key: kOptionEnableHwcodec) !=- "N";+ await mainGetBoolOption(kOptionEnableHwcodec);setState(() {_enableHardwareCodec = newValue;});diff --git a/flutter/lib/models/server_model.dart b/flutter/lib/models/server_model.dartindex 245663d04..2aa961cec 100644--- a/flutter/lib/models/server_model.dart+++ b/flutter/lib/models/server_model.dart@@ -226,8 +226,7 @@ class ServerModel with ChangeNotifier {_approveMode = approveMode;update = true;}- var stopped = option2bool(- "stop-service", await bind.mainGetOption(key: "stop-service"));+ var stopped = await mainGetBoolOption(kOptionStopService);final oldPwdText = _serverPasswd.text;if (stopped ||verificationMethod == kUsePermanentPassword ||diff --git a/src/client.rs b/src/client.rsindex 0072935f1..b3f790d67 100644--- a/src/client.rs+++ b/src/client.rs@@ -1286,7 +1286,9 @@ impl LoginConfigHandler {self.session_id = sid;self.supported_encoding = Default::default();self.restarting_remote_device = false;- self.force_relay = !self.get_option("force-always-relay").is_empty() || force_relay;+ self.force_relay =+ config::option2bool("force-always-relay", &self.get_option("force-always-relay"))+ || force_relay;if let Some((real_id, server, key)) = &self.other_server {let other_server_key = self.get_option("other-server-key");if !other_server_key.is_empty() && key.is_empty() {@@ -1451,6 +1453,10 @@ impl LoginConfigHandler {/// # Arguments////// * `name` - The name of the option to toggle.+ ///+ // It's Ok to check the option empty in this function.+ // `toggle_option()` is only called in a session.+ // Custom client advanced settings will not affact this function.pub fn toggle_option(&mut self, name: String) -> Option<Message> {let mut option = OptionMessage::default();let mut config = self.load_config();@@ -1707,6 +1713,10 @@ impl LoginConfigHandler {/// # Arguments////// * `name` - The name of the toggle option.+ ///+ // It's Ok to check the option empty in this function.+ // `get_toggle_option()` is only called in a session.+ // Custom client advanced settings will not affact this function.pub fn get_toggle_option(&self, name: &str) -> bool {if name == "show-remote-cursor" {self.config.show_remote_cursor.vdiff --git a/src/hbbs_http/sync.rs b/src/hbbs_http/sync.rsindex 8da2e641b..f92d3b387 100644--- a/src/hbbs_http/sync.rs+++ b/src/hbbs_http/sync.rs@@ -67,7 +67,7 @@ async fn start_hbbs_sync_async() {*PRO.lock().unwrap() = false;continue;}- if !Config::get_option("stop-service").is_empty() {+ if hbb_common::config::option2bool("stop-service", &Config::get_option("stop-service")) {continue;}let conns = Connection::alive_conns();@@ -77,7 +77,7 @@ async fn start_hbbs_sync_async() {}if !info_uploaded.0 && info_uploaded.2.map(|x| x.elapsed() >= UPLOAD_SYSINFO_TIMEOUT).unwrap_or(true) {let mut v = crate::get_sysinfo();- // username is empty in login screen of windows, but here we only upload sysinfo once, causing+ // username is empty in login screen of windows, but here we only upload sysinfo once, causing// real user name not uploaded after login screen. https://github.com/rustdesk/rustdesk/discussions/8031if !cfg!(windows) || !v["username"].as_str().unwrap_or_default().is_empty() {v["version"] = json!(crate::VERSION);diff --git a/src/rendezvous_mediator.rs b/src/rendezvous_mediator.rsindex 7527035ba..a27f95315 100644--- a/src/rendezvous_mediator.rs+++ b/src/rendezvous_mediator.rs@@ -75,7 +75,7 @@ impl RendezvousMediator {crate::test_nat_type();nat_tested = true;}- if !Config::get_option("stop-service").is_empty() {+ if config::option2bool("stop-service", &Config::get_option("stop-service")) {crate::test_rendezvous_server();}let server_cloned = server.clone();@@ -96,7 +96,7 @@ impl RendezvousMediator {loop {let conn_start_time = Instant::now();*SOLVING_PK_MISMATCH.lock().await = "".to_owned();- if Config::get_option("stop-service").is_empty()+ if !config::option2bool("stop-service", &Config::get_option("stop-service"))&& !crate::platform::installing_service(){if !nat_tested {