diff --git a/AGENTS.md b/AGENTS.md index d4971fa..9197a5d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -211,6 +211,11 @@ started a second full host server instead, so check that a subcommand exists in - SystemMetrics (Message 13): GeneralMetric `2 system_sound_support` is an enum, **2 = supported** (1 = not supported); SettingMetric 1 keep_mute, 2 mute_permanent, 3 auto_lock, 5 file_transfer_save_location, 8/9/10 permission states (2 = allow). +- 防窥 (privacy screen): RpcRequest 7 `PrivateScreenSettingRequest {1 enable, 2 privacy_type, 3 setting_source}` → + RpcResponse 3 `{1 error_code, 2 req_privacy_type, 3 cur_privacy_type}`; PrivateScreenType 1 NOT_SET, 2 NORMAL, + 3 ENHANCED (wallpaper). Declared on X11 only: FeatureFlag `4 ff_private_screen=1`, `3 ff_system_metrics=3`; + SettingMetric 4 private_screen, 7 private_screen_type (`src/privacy_screen.rs`, xrandr brightness 0, saved + gamma restored on session end / SIGTERM / next start). Not yet accepted with an official viewer. - Security menu: 静音运行 on → SimpleAction 14 + 18, off → 16. 远程结束后自动锁屏 → SimpleAction 19 with `value` (field 5) **2 = on, 1 = off**. The viewer sends these only when toggled, so the host persists them. - Auto unlock: host reports `SystemStateChange{1 SecureDesktopState{1 is_locked, 5 is_support_auto_logon}}`; diff --git a/README.en.md b/README.en.md index b5094d5..b8f6f44 100644 --- a/README.en.md +++ b/README.en.md @@ -144,7 +144,7 @@ On niri, `niri msg --json outputs` enumerates enabled monitors. Normal and 90/18 | True color (4:4:4) | Supported (v0.1.15): the default FFmpeg pipeline with NVENC / libx264 encodes H.264 High 4:4:4; `inproc-av` native NVENC encodes H.264 High 4:4:4 / HEVC FRExt; VAAPI stays 4:2:0 and reports that to the client | | HDR | Not implemented | | Super screen / virtual display | Not implemented | -| Privacy screen on the host | Not implemented | +| Privacy screen on the host | 🧪 Experimental, X11 only: output brightness (gamma) is set to 0 so the physical monitors go black while the remote picture stays normal; normal privacy (black) only, no wallpaper mode; not on Wayland. Restored when the session ends or the service stops/restarts. Overrides custom gamma such as night light; local mouse/keyboard stay active | | Microphone (viewer audio played on the host) | Not implemented (needs a virtual sound card) | | Plugins such as the WoW queue notifier | Not supported; the client is told that no plugins exist | | Linux login screen | The system login screen (before anyone logs in to the Linux desktop) cannot be controlled yet; use headless mode or a virtual desktop (see below). This is about the Linux login: **without a UU account** the host can now be used through remote assistance | diff --git a/README.md b/README.md index 48250a0..cc65064 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ niri 会话通过 `niri msg --json outputs` 枚举已启用的显示器。普通 | 真彩(4:4:4) | 支持(v0.1.15):NVENC / libx264 的默认 FFmpeg 管线输出 H.264 High 4:4:4;`inproc-av` 原生 NVENC 输出 H.264 High 4:4:4 / HEVC FRExt;VAAPI 管线仍为 4:2:0,并如实回报给客户端 | | HDR | 未实现 | | 超级屏 / 虚拟显示器 | 未实现 | -| 被控端防窥模式 | 未实现 | +| 被控端防窥模式 | 🧪 实验性,仅 X11:把显示器输出的亮度(gamma)调为 0,物理屏幕变黑,远程画面照常;只支持「普通防窥」(黑屏),不支持壁纸防窥;Wayland 未实现。连接断开、服务退出或重启时恢复屏幕。会改写夜间模式等自定义 gamma,本地鼠标键盘不会被禁用 | | 麦克风(控制端声音传到被控端) | 未实现(需要虚拟声卡) | | 魔兽世界排队提醒等插件 | 不支持,会明确告诉客户端「无插件」 | | Linux 系统登录界面 | 还不支持控制开机后的系统登录界面(还没有人登录 Linux 桌面时);这种情况可以用无头模式或虚拟桌面(见下文)。注意:这里说的是 Linux 系统登录,**不登录 UU 账号**现在可以通过「远程协助」使用 | diff --git a/src/control_protocol.rs b/src/control_protocol.rs index 6f9962f..fce3dc1 100644 --- a/src/control_protocol.rs +++ b/src/control_protocol.rs @@ -180,8 +180,11 @@ pub fn encode_echo_response_with_clipboard(seq: u64, timestamp: u64, request_seq // FeatureFlag: 1 ff_capture_setting = CUSTOM_BITRATE (fps/quality/bitrate RPCs), // 2 ff_simple_action = AUTO_LOCK (mute + lock after session), 3 ff_system_metrics = SETTING_AUTO_LOCK, // 6 ff_file_transfer_ftp = LIST_COMPRESS (zlib dir_data), 8 ff_clipboard = SUPPORT_TEXT_CHANGE. - let mut flags = vec![8, crate::capture_setting::FEATURE_VERSION as u8, - 16, crate::system_actions::FF_SIMPLE_ACTION, 24, crate::system_actions::FF_SYSTEM_METRICS, 48, 2]; + // On X11: 3 ff_system_metrics = SETTING_PRIVATE_SCREEN (3), 4 ff_private_screen = INIT_VERION (normal privacy). + let mut flags = vec![8, crate::capture_setting::FEATURE_VERSION as u8, 16, crate::system_actions::FF_SIMPLE_ACTION]; + if crate::privacy_screen::supported() { flags.extend_from_slice(&[24, 3, 32, crate::privacy_screen::FF_PRIVATE_SCREEN]); } + else { flags.extend_from_slice(&[24, crate::system_actions::FF_SYSTEM_METRICS]); } + flags.extend_from_slice(&[48, 2]); if clipboard { flags.extend_from_slice(&[64, 3]); } action.push(34); action.push(flags.len() as u8); diff --git a/src/main.rs b/src/main.rs index 9169f38..3de9539 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,7 @@ mod capture_setting; mod audio; mod virtual_audio; mod system_actions; +mod privacy_screen; mod capability; mod protocol; mod control_protocol; @@ -656,6 +657,7 @@ async fn main() -> Result<(), Box> { let input = Arc::new(InputInjector::new()); input.bind_portal(capture.portal.clone()); input.release_held(); // recover stale input before accepting any peer + privacy_screen::recover(); // monitors a previous run left black let _pointer_worker = input.start_pointer_worker(); let (shutdown_tx, mut shutdown) = tokio::sync::watch::channel(false); let shutdown_input = input.clone(); @@ -668,6 +670,7 @@ async fn main() -> Result<(), Box> { } #[cfg(not(target_os="linux"))] let _ = tokio::signal::ctrl_c().await; + let _ = tokio::task::spawn_blocking(privacy_screen::disable).await; if !assist_enabled { shutdown_input.shutdown(); virtual_audio::disable(); terminal::shutdown_all(); std::process::exit(0); } let _ = signal_tx.send(true); }); diff --git a/src/privacy_screen.rs b/src/privacy_screen.rs new file mode 100644 index 0000000..942d01d --- /dev/null +++ b/src/privacy_screen.rs @@ -0,0 +1,228 @@ +//! 防窥模式 (privacy screen) on X11: the physical monitors go black while the stream keeps +//! showing the desktop. Official protocol (Mac UURemoteServer / Windows GameViewerServer maps): +//! Message 21 RpcRequest field 7 PrivateScreenSettingRequest { 1 enable, 2 privacy_type, 3 setting_source } +//! -> Message 22 RpcResponse field 3 PrivateScreenSettingResponse { 1 error_code, 2 req_privacy_type, +//! 3 cur_privacy_type }; PrivateScreenType 1 NOT_SET, 2 NORMAL_PRIVACY, 3 ENHANCED_PRIVACY (wallpaper). +//! Declared through FeatureFlag 4 ff_private_screen = INIT_VERION (1, normal privacy only) and +//! ff_system_metrics = SETTING_PRIVATE_SCREEN (3); SettingMetric 4 private_screen, 7 private_screen_type. +//! The official host answers cur_privacy_type from its saved type (NORMAL/ENHANCED, else NOT_SET). +//! +//! Linux has no capture-excluded overlay window, so the CRTC gamma ramps are zeroed instead +//! (`xrandr --brightness 0`): scanout turns black, the framebuffer the capture reads is unchanged. +//! The previous gamma/brightness is saved to a file first, so a restart restores a screen a crash left black. + +use std::process::Command; +use std::sync::Mutex; + +pub const FF_PRIVATE_SCREEN: u8 = 1; +pub const PS_NOT_SET: u64 = 1; +pub const PS_NORMAL: u64 = 2; +const PS_ENHANCED: u64 = 3; +const ERROR_FAILED: u64 = 1; + +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +struct Output { name: String, gamma: String, brightness: String } + +#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)] +struct Saved { display: String, outputs: Vec } + +static ACTIVE: Mutex> = Mutex::new(None); + +fn saved_path() -> std::path::PathBuf { crate::config::path().with_file_name("privacy_screen.json") } + +/// Only the X11 engine can black out scanout without blacking out the capture. +pub fn supported() -> bool { + !cfg!(test) && !crate::desktop_backend::headless() + && matches!(crate::desktop_backend::detect(), Ok(crate::desktop_backend::DesktopBackend::X11)) + && crate::capture::x11_display().is_some() +} + +pub fn active() -> bool { ACTIVE.lock().map(|a| a.is_some()).unwrap_or(false) } + +/// The saved type the viewer shows: NORMAL once privacy was used or chosen, else NOT_SET. +pub fn current_type() -> u64 { + if crate::system_actions::load_settings().privacy_screen_type == PS_NORMAL { PS_NORMAL } else { PS_NOT_SET } +} + +fn xrandr(display: &str, args: &[String]) -> Result { + let output = Command::new("xrandr").arg("--display").arg(display).args(args).output() + .map_err(|e| format!("xrandr unavailable: {}", e.kind()))?; + if !output.status.success() { return Err(format!("xrandr exited with {}", output.status)); } + Ok(String::from_utf8_lossy(&output.stdout).into_owned()) +} + +/// Connected outputs that drive a CRTC (geometry WxH+X+Y on the header line), with their gamma. +fn parse_outputs(verbose: &str) -> Vec { + let mut outputs: Vec = Vec::new(); + let mut current: Option = None; + for line in verbose.lines() { + if !line.starts_with([' ', '\t']) { + current = None; + let mut words = line.split_whitespace(); + let (Some(name), Some("connected")) = (words.next(), words.next()) else { continue }; + if words.take(2).any(|w| w.contains('x') && w.contains('+')) { + outputs.push(Output { name: name.into(), gamma: "1.0:1.0:1.0".into(), brightness: "1.0".into() }); + current = Some(outputs.len() - 1); + } + } else if let Some(i) = current { + let line = line.trim(); + if let Some(v) = line.strip_prefix("Gamma:") { outputs[i].gamma = v.trim().into(); } + if let Some(v) = line.strip_prefix("Brightness:") { outputs[i].brightness = v.trim().into(); } + } + } + // A black screen saved by a crashed run must not become the value restored later. + for output in &mut outputs { + if output.brightness.parse::().map_or(true, |b| !(b > 0.0)) { output.brightness = "1.0".into(); } + } + outputs +} + +fn black_args(outputs: &[Output]) -> Vec { + outputs.iter().flat_map(|o| ["--output".into(), o.name.clone(), "--brightness".into(), "0".into()]).collect() +} + +fn restore_args(outputs: &[Output]) -> Vec { + outputs.iter().flat_map(|o| ["--output".into(), o.name.clone(), "--gamma".into(), o.gamma.clone(), + "--brightness".into(), o.brightness.clone()]).collect() +} + +fn turn_on() -> Result<(), String> { + let mut active = ACTIVE.lock().map_err(|_| "privacy state poisoned")?; + if active.is_some() { return Ok(()); } + let display = crate::capture::x11_display().ok_or("X11 display not open")?; + let outputs = parse_outputs(&xrandr(&display, &["--verbose".into()])?); + if outputs.is_empty() { return Err("no active output".into()); } + let saved = Saved { display, outputs }; + std::fs::write(saved_path(), serde_json::to_vec(&saved).map_err(|e| e.to_string())?).map_err(|e| e.kind().to_string())?; + if let Err(e) = xrandr(&saved.display, &black_args(&saved.outputs)) { + let _ = xrandr(&saved.display, &restore_args(&saved.outputs)); + let _ = std::fs::remove_file(saved_path()); + return Err(e); + } + log::info!("Privacy screen on: outputs={}", saved.outputs.len()); + *active = Some(saved); + Ok(()) +} + +/// Restores the monitors; also used on session end and shutdown. Blocking. +pub fn disable() { + let Ok(mut active) = ACTIVE.lock() else { return }; + let Some(saved) = active.take() else { return }; + match xrandr(&saved.display, &restore_args(&saved.outputs)) { + Ok(_) => { let _ = std::fs::remove_file(saved_path()); log::info!("Privacy screen off"); } + Err(e) => log::warn!("Privacy screen restore failed: {e}"), + } +} + +/// At startup: a previous run that ended while private left the monitors black. +pub fn recover() { + let Ok(bytes) = std::fs::read(saved_path()) else { return }; + match serde_json::from_slice::(&bytes) { + Ok(saved) => match xrandr(&saved.display, &restore_args(&saved.outputs)) { + Ok(_) => { let _ = std::fs::remove_file(saved_path()); log::info!("Privacy screen left by a previous run restored"); } + Err(e) => log::warn!("Privacy screen left by a previous run not restored: {e}"), + }, + Err(_) => { let _ = std::fs::remove_file(saved_path()); } + } +} + +/// RpcRequest field 7 -> RpcResponse { 1 header, 3 PrivateScreenSettingResponse }. Blocking (xrandr). +pub fn rpc_response(rpc: &[crate::protocol::WireField]) -> Option> { + use crate::protocol::{decode_wire, WireValue}; + let body = |n: u32| rpc.iter().find_map(|f| match (f.number, &f.value) { (x, WireValue::Bytes(b)) if x == n => Some(*b), _ => None }); + let request = decode_wire(body(7)?).ok()?; + let varint = |n: u32| request.iter().find_map(|f| match (f.number, &f.value) { (x, WireValue::Varint(v)) if x == n => Some(*v), _ => None }); + let (enable, requested) = (varint(1).unwrap_or(0) != 0, varint(2).unwrap_or(0)); + let result = if requested == PS_ENHANCED { + Err("enhanced privacy (wallpaper) is not supported".to_owned()) + } else if !supported() { + Err("privacy screen needs the X11 desktop".to_owned()) + } else { + if requested == PS_NORMAL || enable { + if let Err(e) = crate::system_actions::merge_save(|s| s.privacy_screen_type = PS_NORMAL) { log::warn!("Privacy type not saved: {e}"); } + } + if enable { turn_on() } else { disable(); Ok(()) } + }; + let error = match result { + Ok(()) => 0, + Err(e) => { log::warn!("Privacy screen request failed: enable={enable} type={requested}: {e}"); ERROR_FAILED } + }; + log::info!("Privacy screen request: enable={} type={} source={:?} error={}", enable, requested, varint(3), error); + let mut payload = Vec::new(); + if error != 0 { payload.extend_from_slice(&[8, error as u8]); } + if requested != 0 { payload.push(16); varint_into(requested, &mut payload); } + payload.push(24); varint_into(current_type(), &mut payload); + let header = body(1).unwrap_or(&[]); + let mut out = vec![10]; + varint_into(header.len() as u64, &mut out); + out.extend_from_slice(header); + out.push(26); + varint_into(payload.len() as u64, &mut out); + out.extend_from_slice(&payload); + Some(out) +} + +pub fn is_request(rpc: &[crate::protocol::WireField]) -> bool { rpc.iter().any(|f| f.number == 7) } + +fn varint_into(mut v: u64, out: &mut Vec) { + while v >= 128 { out.push((v as u8 & 127) | 128); v >>= 7; } + out.push(v as u8); +} + +#[cfg(test)] +mod tests { + use super::*; + + const VERBOSE: &str = "Screen 0: minimum 8 x 8, current 4480 x 1440, maximum 32767 x 32767 +HDMI-1 connected primary 2560x1440+0+0 (0x46) normal (normal left inverted right x axis y axis) 597mm x 336mm +\tIdentifier: 0x42 +\tGamma: 1.0:1.0:1.0 +\tBrightness: 1.0 + 2560x1440 (0x46) 241.500MHz +HSync -VSync *current +preferred +DP-1 connected 1920x1080+2560+0 (0x50) normal (normal left inverted right x axis y axis) 527mm x 296mm +\tGamma: 1.0:0.9:0.8 +\tBrightness: 0.0 +DP-2 connected (normal left inverted right x axis y axis) +\tGamma: 1.0:1.0:1.0 +HDMI-2 disconnected (normal left inverted right x axis y axis) +"; + + #[test] + fn active_outputs_keep_gamma_and_a_black_brightness_is_not_saved() { + let outputs = parse_outputs(VERBOSE); + assert_eq!(outputs, vec![ + Output { name: "HDMI-1".into(), gamma: "1.0:1.0:1.0".into(), brightness: "1.0".into() }, + Output { name: "DP-1".into(), gamma: "1.0:0.9:0.8".into(), brightness: "1.0".into() }, + ]); + assert_eq!(black_args(&outputs[..1]), ["--output", "HDMI-1", "--brightness", "0"]); + assert_eq!(restore_args(&outputs[1..]), ["--output", "DP-1", "--gamma", "1.0:0.9:0.8", "--brightness", "1.0"]); + } + + #[test] + fn settings_report_private_screen_on_and_its_type() { + use crate::system_metrics::{payload_with_settings, Permission::Allow, Settings}; + let on = payload_with_settings(Allow, Allow, Allow, "", &Settings { private_screen: Some((true, PS_NORMAL)), ..Default::default() }); + assert!(on.ends_with(&[34, 10, 32, 1, 56, 2, 64, 2, 72, 2, 80, 2])); + let unset = payload_with_settings(Allow, Allow, Allow, "", &Settings { private_screen: Some((false, PS_NOT_SET)), ..Default::default() }); + assert!(unset.ends_with(&[34, 8, 56, 1, 64, 2, 72, 2, 80, 2])); + } + + #[test] + fn unsupported_request_answers_failure_with_the_header() { + use crate::protocol::{decode_wire, WireValue}; + // RpcRequest { 1 header{1:5}, 7 { 1 enable, 2 NORMAL, 3 source 1 } } + let rpc = [10, 2, 8, 5, 58, 6, 8, 1, 16, 2, 24, 1]; + let fields = decode_wire(&rpc).unwrap(); + assert!(is_request(&fields)); + let out = rpc_response(&fields).unwrap(); + let outer = decode_wire(&out).unwrap(); + assert_eq!(outer[0].value, WireValue::Bytes(&[8, 5])); + let WireValue::Bytes(payload) = outer[1].value else { panic!("payload") }; + assert_eq!(outer[1].number, 3); + let payload = decode_wire(payload).unwrap(); + assert_eq!(payload[0].value, WireValue::Varint(ERROR_FAILED)); + assert_eq!(payload[1].value, WireValue::Varint(PS_NORMAL)); + assert_eq!(payload[2].number, 3); + assert!(!active()); + } +} diff --git a/src/system_actions.rs b/src/system_actions.rs index 443bb9e..06332d1 100644 --- a/src/system_actions.rs +++ b/src/system_actions.rs @@ -32,6 +32,8 @@ pub(crate) struct Settings { #[serde(default)] auto_lock: bool, #[serde(default)] keep_mute: bool, #[serde(default)] mute_permanent: bool, + /// 防窥 type the viewer chose (privacy_screen::PS_NORMAL), 0 = never set. + #[serde(default)] pub(crate) privacy_screen_type: u64, /// "auto" or absent does not override the environment. A non-string value becomes None so a bad /// video field cannot drop auto_lock / mute when the document is loaded. #[serde(default, deserialize_with = "lenient_string")] pub(crate) video_encoder: Option, @@ -273,6 +275,7 @@ impl PeerActions { let mut state = state().lock().unwrap(); state.desktop_sessions = state.desktop_sessions.saturating_sub(1); if state.desktop_sessions > 0 { return; } + crate::privacy_screen::disable(); crate::virtual_audio::disable(); if !state.settings.mute_permanent { restore_mute(&mut state); } if state.settings.auto_lock { @@ -287,6 +290,7 @@ impl PeerActions { let current = state().lock().unwrap().settings.clone(); payload_with_settings(desktop, desktop, desktop, &home, &crate::system_metrics::Settings { sound, keep_mute: current.keep_mute, mute_permanent: current.mute_permanent, auto_lock: current.auto_lock, + private_screen: crate::privacy_screen::supported().then(|| (crate::privacy_screen::active(), crate::privacy_screen::current_type())), }) } } diff --git a/src/system_metrics.rs b/src/system_metrics.rs index 5648d65..e358d1e 100644 --- a/src/system_metrics.rs +++ b/src/system_metrics.rs @@ -25,20 +25,23 @@ pub fn payload_with_location(capture: Permission, operation: Permission, control } /// Optional host settings the viewer shows in 声音 / 安全 (SettingMetric 1 keep_mute, -/// 2 mute_permanent, 3 auto_lock; GeneralMetric 2 system_sound_support). +/// 2 mute_permanent, 3 auto_lock; GeneralMetric 2 system_sound_support), and 防窥 when the host +/// supports it (SettingMetric 4 private_screen on, 7 private_screen_type). #[derive(Debug, Default, Clone, Copy)] -pub struct Settings { pub sound: bool, pub keep_mute: bool, pub mute_permanent: bool, pub auto_lock: bool } +pub struct Settings { pub sound: bool, pub keep_mute: bool, pub mute_permanent: bool, pub auto_lock: bool, pub private_screen: Option<(bool, u64)> } pub fn payload_with_settings(capture: Permission, operation: Permission, control: Permission, location: &str, settings: &Settings) -> Vec { let mut setting = Vec::new(); for (field, on) in [(1u8, settings.keep_mute), (2, settings.mute_permanent), (3, settings.auto_lock)] { if on { setting.push(field << 3); setting.push(1); } } + if let Some((true, _)) = settings.private_screen { setting.extend_from_slice(&[4 << 3, 1]); } if !location.is_empty() { setting.push(5 << 3 | 2); varint(location.len() as u64, &mut setting); setting.extend_from_slice(location.as_bytes()); } + if let Some((_, kind)) = settings.private_screen { setting.push(7 << 3); varint(kind, &mut setting); } for (field, state) in [(8u8, capture), (9u8, operation), (10u8, control)] { if state != Permission::Unknown { setting.push(field << 3); @@ -48,7 +51,7 @@ pub fn payload_with_settings(capture: Permission, operation: Permission, control // SystemMetrics.general: system_sound_support = SS_SUPPORT (2) when desktop audio is streamed // (GvPb_SystemSoundSupport: 0 unknown, 1 nonsupport, 2 support). let mut out = if settings.sound { vec![26, 2, 16, 2] } else { vec![26, 0] }; - // No support_touch, sound capability, win_os_ver, private-screen, virtual + // No support_touch, sound capability, win_os_ver, virtual // mouse, auto-lock, file path or optional feature claims are fabricated. out.push(34); // SystemMetrics.setting field 4 varint(setting.len() as u64, &mut out); diff --git a/src/webrtc.rs b/src/webrtc.rs index 4d9431d..7689fbf 100644 --- a/src/webrtc.rs +++ b/src/webrtc.rs @@ -1121,6 +1121,22 @@ impl WebRtcSession { use crate::protocol::WireValue; let rpc = fields.iter().find_map(|f| match (f.number, &f.value) { (21, WireValue::Bytes(b)) => Some(*b), _ => None }); let rpc_fields = rpc.and_then(|r| crate::protocol::decode_wire(r).ok()); + if let Some(request) = rpc.filter(|_| rpc_fields.as_deref().is_some_and(crate::privacy_screen::is_request)) { + let (request, actions, chan, seq_out, rpc_out) = (request.to_vec(), actions.clone(), reply_chan.clone(), out_sequence.clone(), rpc_out.clone()); + let settings_portal = portal_for_message.clone(); + tokio::spawn(async move { + let response = tokio::task::spawn_blocking(move || crate::protocol::decode_wire(&request).ok() + .and_then(|r| crate::privacy_screen::rpc_response(&r))).await.ok().flatten(); + let Some(response) = response else { return }; + let ts = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs(); + let _ = rpc_out.send(crate::initialization::envelope(seq_out.fetch_add(1, std::sync::atomic::Ordering::Relaxed), ts, 22, &response)); + // The 防窥 switch shows SettingMetric 4 like the other 安全 settings. + let permission = settings_portal.as_ref().map_or(crate::system_metrics::Permission::Allow, |manager| manager.snapshot().permission(desktop)); + let message = crate::initialization::envelope(seq_out.fetch_add(1, std::sync::atomic::Ordering::Relaxed), ts, 13, &actions.metrics_payload(desktop_sound, permission)); + if let Err(e) = chan.send(&bytes::Bytes::from(message)).await { log::warn!("Settings report failed: {}", e); } + }); + return; + } if let Some(response) = rpc_fields.as_deref().and_then(|r| crate::system_actions::plugin_response(r).or_else(|| crate::system_actions::session_rpc_response(r))) { let ts = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs(); let _ = rpc_out.send(crate::initialization::envelope(out_sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed), ts, 22, &response));