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-")) {
|
if (option.startsWith("enable-")) {
|
||||||
res = value != "N";
|
res = value != "N";
|
||||||
} else if (option.startsWith("allow-") ||
|
} else if (option.startsWith("allow-") ||
|
||||||
option == "stop-service" ||
|
option == kOptionStopService ||
|
||||||
option == kOptionDirectServer ||
|
option == kOptionDirectServer ||
|
||||||
option == "stop-rendezvous-service" ||
|
option == "stop-rendezvous-service" ||
|
||||||
option == kOptionForceAlwaysRelay) {
|
option == kOptionForceAlwaysRelay) {
|
||||||
@ -1447,7 +1447,7 @@ String bool2option(String option, bool b) {
|
|||||||
if (option.startsWith('enable-')) {
|
if (option.startsWith('enable-')) {
|
||||||
res = b ? defaultOptionYes : 'N';
|
res = b ? defaultOptionYes : 'N';
|
||||||
} else if (option.startsWith('allow-') ||
|
} else if (option.startsWith('allow-') ||
|
||||||
option == "stop-service" ||
|
option == kOptionStopService ||
|
||||||
option == kOptionDirectServer ||
|
option == kOptionDirectServer ||
|
||||||
option == "stop-rendezvous-service" ||
|
option == "stop-rendezvous-service" ||
|
||||||
option == kOptionForceAlwaysRelay) {
|
option == kOptionForceAlwaysRelay) {
|
||||||
@ -1485,9 +1485,9 @@ bool mainGetPeerBoolOptionSync(String id, String key) {
|
|||||||
return option2bool(key, bind.mainGetPeerOptionSync(id: id, key: key));
|
return option2bool(key, bind.mainGetPeerOptionSync(id: id, key: key));
|
||||||
}
|
}
|
||||||
|
|
||||||
mainSetPeerBoolOptionSync(String id, String key, bool v) {
|
// Don't use `option2bool()` and `bool2option()` to convert the session option.
|
||||||
bind.mainSetPeerOptionSync(id: id, key: key, value: bool2option(key, v));
|
// Use `sessionGetToggleOption()` and `sessionToggleOption()` instead.
|
||||||
}
|
// Because all session options use `Y` and `<Empty>` as values.
|
||||||
|
|
||||||
Future<bool> matchPeer(String searchText, Peer peer) async {
|
Future<bool> matchPeer(String searchText, Peer peer) async {
|
||||||
if (searchText.isEmpty) {
|
if (searchText.isEmpty) {
|
||||||
@ -2672,7 +2672,7 @@ Future<void> start_service(bool is_start) async {
|
|||||||
!isMacOS ||
|
!isMacOS ||
|
||||||
await callMainCheckSuperUserPermission();
|
await callMainCheckSuperUserPermission();
|
||||||
if (checked) {
|
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 kOptionEnableCheckUpdate = "enable-check-update";
|
||||||
const String kOptionAllowLinuxHeadless = "allow-linux-headless";
|
const String kOptionAllowLinuxHeadless = "allow-linux-headless";
|
||||||
const String kOptionAllowRemoveWallpaper = "allow-remove-wallpaper";
|
const String kOptionAllowRemoveWallpaper = "allow-remove-wallpaper";
|
||||||
|
const String kOptionStopService = "stop-service";
|
||||||
|
|
||||||
const String kOptionToggleViewOnly = "view-only";
|
const String kOptionToggleViewOnly = "view-only";
|
||||||
|
|
||||||
|
@ -671,7 +671,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
|
|||||||
systemError = error;
|
systemError = error;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
final v = await bind.mainGetOption(key: "stop-service") == "Y";
|
final v = await mainGetBoolOption(kOptionStopService);
|
||||||
if (v != svcStopped.value) {
|
if (v != svcStopped.value) {
|
||||||
svcStopped.value = v;
|
svcStopped.value = v;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
@ -103,8 +103,8 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
|||||||
_enableAbr = enableAbrRes;
|
_enableAbr = enableAbrRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
final denyLanDiscovery = !option2bool('enable-lan-discovery',
|
final denyLanDiscovery = !option2bool(kOptionEnableLanDiscovery,
|
||||||
await bind.mainGetOption(key: 'enable-lan-discovery'));
|
await bind.mainGetOption(key: kOptionEnableLanDiscovery));
|
||||||
if (denyLanDiscovery != _denyLANDiscovery) {
|
if (denyLanDiscovery != _denyLANDiscovery) {
|
||||||
update = true;
|
update = true;
|
||||||
_denyLANDiscovery = denyLanDiscovery;
|
_denyLANDiscovery = denyLanDiscovery;
|
||||||
@ -311,10 +311,8 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
|||||||
onToggle: isOptionFixed(kOptionEnableAbr)
|
onToggle: isOptionFixed(kOptionEnableAbr)
|
||||||
? null
|
? null
|
||||||
: (v) async {
|
: (v) async {
|
||||||
await bind.mainSetOption(
|
await mainSetBoolOption(kOptionEnableAbr, v);
|
||||||
key: kOptionEnableAbr, value: v ? defaultOptionYes : "N");
|
final newValue = await mainGetBoolOption(kOptionEnableAbr);
|
||||||
final newValue =
|
|
||||||
await bind.mainGetOption(key: kOptionEnableAbr) != "N";
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_enableAbr = newValue;
|
_enableAbr = newValue;
|
||||||
});
|
});
|
||||||
@ -326,12 +324,9 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
|||||||
onToggle: isOptionFixed(kOptionEnableRecordSession)
|
onToggle: isOptionFixed(kOptionEnableRecordSession)
|
||||||
? null
|
? null
|
||||||
: (v) async {
|
: (v) async {
|
||||||
await bind.mainSetOption(
|
await mainSetBoolOption(kOptionEnableRecordSession, v);
|
||||||
key: kOptionEnableRecordSession,
|
|
||||||
value: v ? defaultOptionYes : "N");
|
|
||||||
final newValue =
|
final newValue =
|
||||||
await bind.mainGetOption(key: kOptionEnableRecordSession) !=
|
await mainGetBoolOption(kOptionEnableRecordSession);
|
||||||
"N";
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_enableRecordSession = newValue;
|
_enableRecordSession = newValue;
|
||||||
});
|
});
|
||||||
@ -587,12 +582,9 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
|
|||||||
onToggle: isOptionFixed(kOptionEnableHwcodec)
|
onToggle: isOptionFixed(kOptionEnableHwcodec)
|
||||||
? null
|
? null
|
||||||
: (v) async {
|
: (v) async {
|
||||||
await bind.mainSetOption(
|
await mainSetBoolOption(kOptionEnableHwcodec, v);
|
||||||
key: kOptionEnableHwcodec,
|
|
||||||
value: v ? defaultOptionYes : "N");
|
|
||||||
final newValue =
|
final newValue =
|
||||||
await bind.mainGetOption(key: kOptionEnableHwcodec) !=
|
await mainGetBoolOption(kOptionEnableHwcodec);
|
||||||
"N";
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_enableHardwareCodec = newValue;
|
_enableHardwareCodec = newValue;
|
||||||
});
|
});
|
||||||
|
@ -226,8 +226,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
_approveMode = approveMode;
|
_approveMode = approveMode;
|
||||||
update = true;
|
update = true;
|
||||||
}
|
}
|
||||||
var stopped = option2bool(
|
var stopped = await mainGetBoolOption(kOptionStopService);
|
||||||
"stop-service", await bind.mainGetOption(key: "stop-service"));
|
|
||||||
final oldPwdText = _serverPasswd.text;
|
final oldPwdText = _serverPasswd.text;
|
||||||
if (stopped ||
|
if (stopped ||
|
||||||
verificationMethod == kUsePermanentPassword ||
|
verificationMethod == kUsePermanentPassword ||
|
||||||
|
@ -1286,7 +1286,9 @@ impl LoginConfigHandler {
|
|||||||
self.session_id = sid;
|
self.session_id = sid;
|
||||||
self.supported_encoding = Default::default();
|
self.supported_encoding = Default::default();
|
||||||
self.restarting_remote_device = false;
|
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 {
|
if let Some((real_id, server, key)) = &self.other_server {
|
||||||
let other_server_key = self.get_option("other-server-key");
|
let other_server_key = self.get_option("other-server-key");
|
||||||
if !other_server_key.is_empty() && key.is_empty() {
|
if !other_server_key.is_empty() && key.is_empty() {
|
||||||
@ -1451,6 +1453,10 @@ impl LoginConfigHandler {
|
|||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `name` - The name of the option to toggle.
|
/// * `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> {
|
pub fn toggle_option(&mut self, name: String) -> Option<Message> {
|
||||||
let mut option = OptionMessage::default();
|
let mut option = OptionMessage::default();
|
||||||
let mut config = self.load_config();
|
let mut config = self.load_config();
|
||||||
@ -1707,6 +1713,10 @@ impl LoginConfigHandler {
|
|||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `name` - The name of the toggle option.
|
/// * `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 {
|
pub fn get_toggle_option(&self, name: &str) -> bool {
|
||||||
if name == "show-remote-cursor" {
|
if name == "show-remote-cursor" {
|
||||||
self.config.show_remote_cursor.v
|
self.config.show_remote_cursor.v
|
||||||
|
@ -67,7 +67,7 @@ async fn start_hbbs_sync_async() {
|
|||||||
*PRO.lock().unwrap() = false;
|
*PRO.lock().unwrap() = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if !Config::get_option("stop-service").is_empty() {
|
if hbb_common::config::option2bool("stop-service", &Config::get_option("stop-service")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let conns = Connection::alive_conns();
|
let conns = Connection::alive_conns();
|
||||||
|
@ -75,7 +75,7 @@ impl RendezvousMediator {
|
|||||||
crate::test_nat_type();
|
crate::test_nat_type();
|
||||||
nat_tested = true;
|
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();
|
crate::test_rendezvous_server();
|
||||||
}
|
}
|
||||||
let server_cloned = server.clone();
|
let server_cloned = server.clone();
|
||||||
@ -96,7 +96,7 @@ impl RendezvousMediator {
|
|||||||
loop {
|
loop {
|
||||||
let conn_start_time = Instant::now();
|
let conn_start_time = Instant::now();
|
||||||
*SOLVING_PK_MISMATCH.lock().await = "".to_owned();
|
*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()
|
&& !crate::platform::installing_service()
|
||||||
{
|
{
|
||||||
if !nat_tested {
|
if !nat_tested {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user