fix: custom client, option to bool (#8303)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
32ab56f864
commit
9ab5512bfa
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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(() {});
|
||||
|
@ -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;
|
||||
});
|
||||
|
@ -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 ||
|
||||
|
@ -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.v
|
||||
|
@ -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/8031
|
||||
if !cfg!(windows) || !v["username"].as_str().unwrap_or_default().is_empty() {
|
||||
v["version"] = json!(crate::VERSION);
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user