other bool default display settings

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-02-02 09:39:14 +08:00
parent 359f19af02
commit 92145eeb71
36 changed files with 159 additions and 41 deletions

View File

@ -1072,6 +1072,7 @@ class _DisplayState extends State<_Display> {
scrollStyle(context),
imageQuality(context),
codec(context),
other(context),
]).marginOnly(bottom: _kListViewBottomMargin));
}
@ -1256,6 +1257,39 @@ class _DisplayState extends State<_Display> {
onChanged: onChanged),
]);
}
Widget otherRow(String label, String key) {
final value = bind.mainGetUserDefaultOption(key: key) == 'Y';
onChanged(bool b) async {
await bind.mainSetUserDefaultOption(key: key, value: b ? 'Y' : '');
setState(() {});
}
return GestureDetector(
child: Row(
children: [
Checkbox(value: value, onChanged: (_) => onChanged(!value))
.marginOnly(right: 5),
Expanded(
child: Text(translate(label)),
)
],
).marginOnly(left: _kCheckBoxLeftMargin),
onTap: () => onChanged(!value));
}
Widget other(BuildContext context) {
return _Card(title: 'Other Default Options', children: [
otherRow('Show remote cursor', 'show_remote_cursor'),
otherRow('Zoom cursor', 'zoom-cursor'),
otherRow('Show quality monitor', 'show_quality_monitor'),
otherRow('Mute', 'disable_audio'),
otherRow('Allow file copy and paste', 'enable_file_transfer'),
otherRow('Disable clipboard', 'disable_clipboard'),
otherRow('Lock after session end', 'lock_after_session_end'),
otherRow('Privacy mode', 'privacy_mode'),
]);
}
}
class _Account extends StatefulWidget {

View File

@ -115,6 +115,26 @@ macro_rules! serde_field_string {
};
}
macro_rules! serde_field_bool {
($struct_name: ident, $field_name: literal, $func: ident) => {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct $struct_name {
#[serde(rename = $field_name)]
pub v: bool,
}
impl Default for $struct_name {
fn default() -> Self {
Self { v: Self::$func() }
}
}
impl $struct_name {
pub fn $func() -> bool {
UserDefaultConfig::load().get($field_name) == "Y"
}
}
};
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum NetworkType {
Direct,
@ -197,24 +217,24 @@ pub struct PeerConfig {
deserialize_with = "PeerConfig::deserialize_custom_image_quality"
)]
pub custom_image_quality: Vec<i32>,
#[serde(default)]
pub show_remote_cursor: bool,
#[serde(default)]
pub lock_after_session_end: bool,
#[serde(default)]
pub privacy_mode: bool,
#[serde(flatten)]
pub show_remote_cursor: ShowRemoteCursor,
#[serde(flatten)]
pub lock_after_session_end: LockAfterSessionEnd,
#[serde(flatten)]
pub privacy_mode: PrivacyMode,
#[serde(default)]
pub port_forwards: Vec<(i32, String, i32)>,
#[serde(default)]
pub direct_failures: i32,
#[serde(default)]
pub disable_audio: bool,
#[serde(default)]
pub disable_clipboard: bool,
#[serde(default)]
pub enable_file_transfer: bool,
#[serde(default)]
pub show_quality_monitor: bool,
#[serde(flatten)]
pub disable_audio: DisableAudio,
#[serde(flatten)]
pub disable_clipboard: DisableClipboard,
#[serde(flatten)]
pub enable_file_transfer: EnableFileTransfer,
#[serde(flatten)]
pub show_quality_monitor: ShowQualityMonitor,
#[serde(default)]
pub keyboard_mode: String,
@ -1010,10 +1030,42 @@ impl PeerConfig {
if !mp.contains_key(key) {
mp.insert(key.to_owned(), UserDefaultConfig::load().get(key));
}
key = "zoom-cursor";
if !mp.contains_key(key) {
mp.insert(key.to_owned(), UserDefaultConfig::load().get(key));
}
Ok(mp)
}
}
serde_field_bool!(
ShowRemoteCursor,
"show_remote_cursor",
default_show_remote_cursor
);
serde_field_bool!(
ShowQualityMonitor,
"show_quality_monitor",
default_show_quality_monitor
);
serde_field_bool!(DisableAudio, "disable_audio", default_disable_audio);
serde_field_bool!(
EnableFileTransfer,
"enable_file_transfer",
default_enable_file_transfer
);
serde_field_bool!(
DisableClipboard,
"disable_clipboard",
default_disable_clipboard
);
serde_field_bool!(
LockAfterSessionEnd,
"lock_after_session_end",
default_lock_after_session_end
);
serde_field_bool!(PrivacyMode, "privacy_mode", default_privacy_mode);
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct LocalConfig {
#[serde(default)]

View File

@ -956,7 +956,7 @@ impl LoginConfigHandler {
/// Check if the client should auto login.
/// Return password if the client should auto login, otherwise return empty string.
pub fn should_auto_login(&self) -> String {
let l = self.lock_after_session_end;
let l = self.lock_after_session_end.v;
let a = !self.get_option("auto-login").is_empty();
let p = self.get_option("os-password");
if !p.is_empty() && l && a {
@ -1063,32 +1063,32 @@ impl LoginConfigHandler {
let mut option = OptionMessage::default();
let mut config = self.load_config();
if name == "show-remote-cursor" {
config.show_remote_cursor = !config.show_remote_cursor;
option.show_remote_cursor = (if config.show_remote_cursor {
config.show_remote_cursor.v = !config.show_remote_cursor.v;
option.show_remote_cursor = (if config.show_remote_cursor.v {
BoolOption::Yes
} else {
BoolOption::No
})
.into();
} else if name == "disable-audio" {
config.disable_audio = !config.disable_audio;
option.disable_audio = (if config.disable_audio {
config.disable_audio.v = !config.disable_audio.v;
option.disable_audio = (if config.disable_audio.v {
BoolOption::Yes
} else {
BoolOption::No
})
.into();
} else if name == "disable-clipboard" {
config.disable_clipboard = !config.disable_clipboard;
option.disable_clipboard = (if config.disable_clipboard {
config.disable_clipboard.v = !config.disable_clipboard.v;
option.disable_clipboard = (if config.disable_clipboard.v {
BoolOption::Yes
} else {
BoolOption::No
})
.into();
} else if name == "lock-after-session-end" {
config.lock_after_session_end = !config.lock_after_session_end;
option.lock_after_session_end = (if config.lock_after_session_end {
config.lock_after_session_end.v = !config.lock_after_session_end.v;
option.lock_after_session_end = (if config.lock_after_session_end.v {
BoolOption::Yes
} else {
BoolOption::No
@ -1096,15 +1096,15 @@ impl LoginConfigHandler {
.into();
} else if name == "privacy-mode" {
// try toggle privacy mode
option.privacy_mode = (if config.privacy_mode {
option.privacy_mode = (if config.privacy_mode.v {
BoolOption::No
} else {
BoolOption::Yes
})
.into();
} else if name == "enable-file-transfer" {
config.enable_file_transfer = !config.enable_file_transfer;
option.enable_file_transfer = (if config.enable_file_transfer {
config.enable_file_transfer.v = !config.enable_file_transfer.v;
option.enable_file_transfer = (if config.enable_file_transfer.v {
BoolOption::Yes
} else {
BoolOption::No
@ -1115,7 +1115,7 @@ impl LoginConfigHandler {
} else if name == "unblock-input" {
option.block_input = BoolOption::No.into();
} else if name == "show-quality-monitor" {
config.show_quality_monitor = !config.show_quality_monitor;
config.show_quality_monitor.v = !config.show_quality_monitor.v;
} else {
let v = self.options.get(&name).is_some();
if v {
@ -1252,19 +1252,19 @@ impl LoginConfigHandler {
/// * `name` - The name of the toggle option.
pub fn get_toggle_option(&self, name: &str) -> bool {
if name == "show-remote-cursor" {
self.config.show_remote_cursor
self.config.show_remote_cursor.v
} else if name == "lock-after-session-end" {
self.config.lock_after_session_end
self.config.lock_after_session_end.v
} else if name == "privacy-mode" {
self.config.privacy_mode
self.config.privacy_mode.v
} else if name == "enable-file-transfer" {
self.config.enable_file_transfer
self.config.enable_file_transfer.v
} else if name == "disable-audio" {
self.config.disable_audio
self.config.disable_audio.v
} else if name == "disable-clipboard" {
self.config.disable_clipboard
self.config.disable_clipboard.v
} else if name == "show-quality-monitor" {
self.config.show_quality_monitor
self.config.show_quality_monitor.v
} else {
!self.get_option(name).is_empty()
}

View File

@ -277,7 +277,7 @@ impl<T: InvokeUiSession> Remote<T> {
}
if !SERVER_CLIPBOARD_ENABLED.load(Ordering::SeqCst)
|| !SERVER_KEYBOARD_ENABLED.load(Ordering::SeqCst)
|| lc.read().unwrap().disable_clipboard
|| lc.read().unwrap().disable_clipboard.v
{
continue;
}
@ -778,7 +778,7 @@ impl<T: InvokeUiSession> Remote<T> {
|| self.handler.is_port_forward()
|| !SERVER_CLIPBOARD_ENABLED.load(Ordering::SeqCst)
|| !SERVER_KEYBOARD_ENABLED.load(Ordering::SeqCst)
|| self.handler.lc.read().unwrap().disable_clipboard)
|| self.handler.lc.read().unwrap().disable_clipboard.v)
{
let txt = self.old_clipboard.lock().unwrap().clone();
if !txt.is_empty() {
@ -808,7 +808,7 @@ impl<T: InvokeUiSession> Remote<T> {
self.handler.set_cursor_position(cp);
}
Some(message::Union::Clipboard(cb)) => {
if !self.handler.lc.read().unwrap().disable_clipboard {
if !self.handler.lc.read().unwrap().disable_clipboard.v {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
update_clipboard(cb, Some(&self.old_clipboard));
#[cfg(any(target_os = "android", target_os = "ios"))]
@ -1121,7 +1121,7 @@ impl<T: InvokeUiSession> Remote<T> {
self.handler.handle_test_delay(t, peer).await;
}
Some(message::Union::AudioFrame(frame)) => {
if !self.handler.lc.read().unwrap().disable_audio {
if !self.handler.lc.read().unwrap().disable_audio.v {
self.audio_sender.send(MediaData::AudioFrame(frame)).ok();
}
}
@ -1204,7 +1204,7 @@ impl<T: InvokeUiSession> Remote<T> {
#[inline(always)]
fn update_privacy_mode(&mut self, on: bool) {
let mut config = self.handler.load_config();
config.privacy_mode = on;
config.privacy_mode.v = on;
self.handler.save_config(config);
self.handler.update_privacy_mode();
@ -1278,14 +1278,14 @@ impl<T: InvokeUiSession> Remote<T> {
#[cfg(windows)]
{
let enabled = SERVER_FILE_TRANSFER_ENABLED.load(Ordering::SeqCst)
&& self.handler.lc.read().unwrap().enable_file_transfer;
&& self.handler.lc.read().unwrap().enable_file_transfer.v;
ContextSend::enable(enabled);
}
}
#[cfg(windows)]
fn handle_cliprdr_msg(&self, clip: hbb_common::message_proto::Cliprdr) {
if !self.handler.lc.read().unwrap().disable_clipboard {
if !self.handler.lc.read().unwrap().disable_clipboard.v {
#[cfg(feature = "flutter")]
if let Some(hbb_common::message_proto::cliprdr::Union::FormatList(_)) = &clip.union {
if self.client_conn_id

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", "波特率"),
("FPS", "帧率"),
("Auto", "自动"),
("Other Default Options", "其它默认选项"),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", "波特率"),
("FPS", "幀率"),
("Auto", "自動"),
("Other Default Options", "其它默認選項"),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}

View File

@ -444,5 +444,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Bitrate", ""),
("FPS", ""),
("Auto", ""),
("Other Default Options", ""),
].iter().cloned().collect();
}