fix: wayland delete restore token (#7988)

* fix: wayland delete restore token

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* Wayland close session when clearing restore token

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* fix build

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* Refact Wayland option

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* Wayland clear screen selection, fake token

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* fix build web

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* fix: build

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* chore

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2024-05-09 11:03:59 +08:00
committed by GitHub
parent a31a68ba17
commit bbe9017318
48 changed files with 392 additions and 25 deletions

View File

@@ -909,6 +909,39 @@ pub fn main_set_local_option(key: String, value: String) {
set_local_option(key, value)
}
// We do use use `main_get_local_option` and `main_set_local_option`.
//
// 1. For get, the value is stored in the server process.
// 2. For clear, we need to need to return the error mmsg from the server process to flutter.
#[cfg(target_os = "linux")]
pub fn main_handle_wayland_screencast_restore_token(key: String, value: String) -> String {
if value == "get" {
match crate::ipc::get_wayland_screencast_restore_token(key) {
Ok(v) => v,
Err(e) => {
log::error!("Failed to get wayland screencast restore token, {}", e);
"".to_owned()
}
}
} else if value == "clear" {
match crate::ipc::clear_wayland_screencast_restore_token(key.clone()) {
Ok(true) => {
set_local_option(key, "".to_owned());
"".to_owned()
}
Ok(false) => "Failed to clear, please try again.".to_owned(),
Err(e) => format!("Failed to clear, {}", e),
}
} else {
"".to_owned()
}
}
#[cfg(not(target_os = "linux"))]
pub fn main_handle_wayland_screencast_restore_token(_key: String, _value: String) -> String {
"".to_owned()
}
pub fn main_get_input_source() -> SyncReturn<String> {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let input_source = get_cur_session_input_source();

View File

@@ -5,7 +5,10 @@ use std::{
#[cfg(not(windows))]
use std::{fs::File, io::prelude::*};
use crate::privacy_mode::PrivacyModeState;
use crate::{
privacy_mode::PrivacyModeState,
ui_interface::{get_local_option, set_local_option},
};
use bytes::Bytes;
use parity_tokio_ipc::{
Connection as Conn, ConnectionClient as ConnClient, Endpoint, Incoming, SecurityAttributes,
@@ -234,6 +237,8 @@ pub enum Data {
CmErr(String),
CheckHwcodec,
VideoConnCount(Option<usize>),
// Although the key is not neccessary, it is used to avoid hardcoding the key.
WaylandScreencastRestoreToken((String, String)),
}
#[tokio::main(flavor = "current_thread")]
@@ -526,6 +531,42 @@ async fn handle(data: Data, stream: &mut Connection) {
scrap::hwcodec::start_check_process(true);
}
}
Data::WaylandScreencastRestoreToken((key, value)) => {
let v = if value == "get" {
let opt = get_local_option(key.clone());
#[cfg(not(target_os = "linux"))]
{
Some(opt)
}
#[cfg(target_os = "linux")]
{
let v = if opt.is_empty() {
if scrap::wayland::pipewire::is_rdp_session_hold() {
"fake token".to_string()
} else {
"".to_owned()
}
} else {
opt
};
Some(v)
}
} else if value == "clear" {
set_local_option(key.clone(), "".to_owned());
#[cfg(target_os = "linux")]
scrap::wayland::pipewire::close_session();
Some("".to_owned())
} else {
None
};
if let Some(v) = v {
allow_err!(
stream
.send(&Data::WaylandScreencastRestoreToken((key, v)))
.await
);
}
}
_ => {}
}
}
@@ -959,6 +1000,35 @@ pub async fn notify_server_to_check_hwcodec() -> ResultType<()> {
Ok(())
}
#[tokio::main(flavor = "current_thread")]
pub async fn get_wayland_screencast_restore_token(key: String) -> ResultType<String> {
let v = handle_wayland_screencast_restore_token(key, "get".to_owned()).await?;
Ok(v.unwrap_or_default())
}
#[tokio::main(flavor = "current_thread")]
pub async fn clear_wayland_screencast_restore_token(key: String) -> ResultType<bool> {
if let Some(v) = handle_wayland_screencast_restore_token(key, "clear".to_owned()).await? {
return Ok(v.is_empty());
}
return Ok(false);
}
async fn handle_wayland_screencast_restore_token(
key: String,
value: String,
) -> ResultType<Option<String>> {
let ms_timeout = 1_000;
let mut c = connect(ms_timeout, "").await?;
c.send(&Data::WaylandScreencastRestoreToken((key, value)))
.await?;
if let Some(Data::WaylandScreencastRestoreToken((_key, v))) = c.next_timeout(ms_timeout).await?
{
return Ok(Some(v));
}
return Ok(None);
}
#[cfg(test)]
mod test {
use super::*;

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", "未找到音频输入设备"),
("Incoming", "被控"),
("Outgoing", "主控"),
("Clear Wayland screen selection", "清除 Wayland 的屏幕选择"),
("clear_Wayland_screen_selection_tip", "清除 Wayland 的屏幕选择后,您可以重新选择分享的屏幕。"),
("confirm_clear_Wayland_screen_selection_tip", "是否确认清除 Wayland 的分享屏幕选择?"),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", "Nebylo nalezeno žádné vstupní zvukové zařízení."),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", "Kein Audio-Eingabegerät gefunden."),
("Incoming", "Eingehend"),
("Outgoing", "Ausgehend"),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -225,5 +225,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Follow remote window focus", ""),
("default_proxy_tip", "Default protocol and port are Socks5 and 1080"),
("no_audio_input_device_tip", "No audio input device found."),
("clear_Wayland_screen_selection_tip", "After clearing the screen selection, you can reselect the screen to share."),
("confirm_clear_Wayland_screen_selection_tip", "Are you sure to clear the Wayland screen selection?"),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", "Nessun dispositivo input audio trovato."),
("Incoming", "In entrata"),
("Outgoing", "In uscita"),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", "Nav atrasta neviena audio ievades ierīce."),
("Incoming", "Ienākošie"),
("Outgoing", "Izejošie"),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", "Nenašlo sa žiadne vstupné zvukové zariadenie."),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -609,5 +609,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("no_audio_input_device_tip", ""),
("Incoming", ""),
("Outgoing", ""),
("Clear Wayland screen selection", ""),
("clear_Wayland_screen_selection_tip", ""),
("confirm_clear_Wayland_screen_selection_tip", ""),
].iter().cloned().collect();
}

View File

@@ -3736,6 +3736,8 @@ mod raii {
display_service::reset_resolutions();
#[cfg(windows)]
let _ = virtual_display_manager::reset_all();
#[cfg(target_os = "linux")]
scrap::wayland::pipewire::try_close_session();
}
Self::check_wake_lock();
}