Skip to content

Commit

Permalink
Merge branch 'rustdesk:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Evelye authored Sep 20, 2024
2 parents bd6ed1c + b93d4ce commit e248c3d
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 65 deletions.
12 changes: 12 additions & 0 deletions libs/hbb_common/src/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ lazy_static::lazy_static! {

pub const DISPLAY_SERVER_WAYLAND: &str = "wayland";
pub const DISPLAY_SERVER_X11: &str = "x11";
pub const DISPLAY_DESKTOP_KDE: &str = "KDE";

pub const XDG_CURRENT_DESKTOP: &str = "XDG_CURRENT_DESKTOP";

pub struct Distro {
pub name: String,
Expand All @@ -29,6 +32,15 @@ impl Distro {
}
}

#[inline]
pub fn is_kde() -> bool {
if let Ok(env) = std::env::var(XDG_CURRENT_DESKTOP) {
env == DISPLAY_DESKTOP_KDE
} else {
false
}
}

#[inline]
pub fn is_gdm_user(username: &str) -> bool {
username == "gdm"
Expand Down
58 changes: 40 additions & 18 deletions libs/scrap/src/wayland/pipewire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,40 @@ use super::screencast_portal::OrgFreedesktopPortalScreenCast as screencast_porta
use lazy_static::lazy_static;

lazy_static! {
pub static ref RDP_RESPONSE: Mutex<Option<RdpResponse>> = Mutex::new(None);
pub static ref RDP_SESSION_INFO: Mutex<Option<RdpSessionInfo>> = Mutex::new(None);
}

#[inline]
pub fn close_session() {
let _ = RDP_RESPONSE.lock().unwrap().take();
let _ = RDP_SESSION_INFO.lock().unwrap().take();
}

#[inline]
pub fn is_rdp_session_hold() -> bool {
RDP_RESPONSE.lock().unwrap().is_some()
RDP_SESSION_INFO.lock().unwrap().is_some()
}

pub fn try_close_session() {
let mut rdp_res = RDP_RESPONSE.lock().unwrap();
let mut rdp_info = RDP_SESSION_INFO.lock().unwrap();
let mut close = false;
if let Some(rdp_res) = &*rdp_res {
if let Some(rdp_info) = &*rdp_info {
// If is server running and restore token is supported, there's no need to keep the session.
if is_server_running() && rdp_res.is_support_restore_token {
if is_server_running() && rdp_info.is_support_restore_token {
close = true;
}
}
if close {
*rdp_res = None;
*rdp_info = None;
}
}

pub struct RdpResponse {
pub struct RdpSessionInfo {
pub conn: Arc<SyncConnection>,
pub streams: Vec<PwStreamInfo>,
pub fd: OwnedFd,
pub session: dbus::Path<'static>,
pub is_support_restore_token: bool,
pub resolution: Arc<Mutex<Option<(usize, usize)>>>,
}
#[derive(Debug, Clone, Copy)]
pub struct PwStreamInfo {
Expand All @@ -69,6 +70,12 @@ pub struct PwStreamInfo {
size: (usize, usize),
}

impl PwStreamInfo {
pub fn get_size(&self) -> (usize, usize) {
self.size
}
}

#[derive(Debug)]
pub struct DBusError(String);

Expand Down Expand Up @@ -105,24 +112,31 @@ pub struct PipeWireCapturable {
}

impl PipeWireCapturable {
fn new(conn: Arc<SyncConnection>, fd: OwnedFd, stream: PwStreamInfo) -> Self {
fn new(
conn: Arc<SyncConnection>,
fd: OwnedFd,
resolution: Arc<Mutex<Option<(usize, usize)>>>,
stream: PwStreamInfo,
) -> Self {
// alternative to get screen resolution as stream.size is not always correct ex: on fractional scaling
// https://github.com/rustdesk/rustdesk/issues/6116#issuecomment-1817724244
let res = get_res(Self {
let size = get_res(Self {
dbus_conn: conn.clone(),
fd: fd.clone(),
path: stream.path,
source_type: stream.source_type,
position: stream.position,
size: stream.size,
});
})
.unwrap_or(stream.size);
*resolution.lock().unwrap() = Some(size);
Self {
dbus_conn: conn,
fd,
path: stream.path,
source_type: stream.source_type,
position: stream.position,
size: res.unwrap_or(stream.size),
size,
}
}
}
Expand Down Expand Up @@ -813,7 +827,7 @@ fn on_start_response(
}

pub fn get_capturables() -> Result<Vec<PipeWireCapturable>, Box<dyn Error>> {
let mut rdp_connection = match RDP_RESPONSE.lock() {
let mut rdp_connection = match RDP_SESSION_INFO.lock() {
Ok(conn) => conn,
Err(err) => return Err(Box::new(err)),
};
Expand All @@ -822,28 +836,36 @@ pub fn get_capturables() -> Result<Vec<PipeWireCapturable>, Box<dyn Error>> {
let (conn, fd, streams, session, is_support_restore_token) = request_remote_desktop()?;
let conn = Arc::new(conn);

let rdp_res = RdpResponse {
let rdp_info = RdpSessionInfo {
conn,
streams,
fd,
session,
is_support_restore_token,
resolution: Arc::new(Mutex::new(None)),
};
*rdp_connection = Some(rdp_res);
*rdp_connection = Some(rdp_info);
}

let rdp_res = match rdp_connection.as_ref() {
let rdp_info = match rdp_connection.as_ref() {
Some(res) => res,
None => {
return Err(Box::new(DBusError("RDP response is None.".into())));
}
};

Ok(rdp_res
Ok(rdp_info
.streams
.clone()
.into_iter()
.map(|s| PipeWireCapturable::new(rdp_res.conn.clone(), rdp_res.fd.clone(), s))
.map(|s| {
PipeWireCapturable::new(
rdp_info.conn.clone(),
rdp_info.fd.clone(),
rdp_info.resolution.clone(),
s,
)
})
.collect())
}

Expand Down
8 changes: 4 additions & 4 deletions src/lang/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("pull_group_failed_tip", "Aktualisierung der Gruppe fehlgeschlagen"),
("Filter by intersection", "Nach Schnittmenge filtern"),
("Remove wallpaper during incoming sessions", "Hintergrundbild bei eingehenden Sitzungen entfernen"),
("Test", "Test"),
("Test", "Testen"),
("display_is_plugged_out_msg", "Der Bildschirm ist nicht angeschlossen, schalten Sie auf den ersten Bildschirm um."),
("No displays", "Keine Bildschirme"),
("Open in new window", "In einem neuen Fenster öffnen"),
Expand Down Expand Up @@ -644,8 +644,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Parent directory", "Übergeordnetes Verzeichnis"),
("Resume", "Fortsetzen"),
("Invalid file name", "Ungültiger Dateiname"),
("one-way-file-transfer-tip", ""),
("Authentication Required", ""),
("Authenticate", ""),
("one-way-file-transfer-tip", "Die einseitige Dateiübertragung ist auf der kontrollierten Seite aktiviert."),
("Authentication Required", "Authentifizierung erforderlich"),
("Authenticate", "Authentifizieren"),
].iter().cloned().collect();
}
18 changes: 9 additions & 9 deletions src/lang/it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Remember password", "Ricorda password"),
("Wrong Password", "Password errata"),
("Do you want to enter again?", "Vuoi riprovare?"),
("Connection Error", "Errore di connessione"),
("Connection Error", "Errore connessione"),
("Error", "Errore"),
("Reset by the peer", "Reimpostata dal dispositivo remoto"),
("Connecting...", "Connessione..."),
Expand Down Expand Up @@ -134,14 +134,14 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Insert Lock", "Blocco inserimento"),
("Refresh", "Aggiorna"),
("ID does not exist", "L'ID non esiste"),
("Failed to connect to rendezvous server", "Errore di connessione al server rendezvous"),
("Failed to connect to rendezvous server", "Errore connessione al server rendezvous"),
("Please try later", "Riprova più tardi"),
("Remote desktop is offline", "Il desktop remoto è offline"),
("Key mismatch", "La chiave non corrisponde"),
("Timeout", "Timeout"),
("Failed to connect to relay server", "Errore di connessione al server relay"),
("Failed to connect via rendezvous server", "Errore di connessione tramite il server rendezvous"),
("Failed to connect via relay server", "Errore di connessione tramite il server relay"),
("Failed to connect to relay server", "Errore connessione al server relay"),
("Failed to connect via rendezvous server", "Errore connessione tramite il server rendezvous"),
("Failed to connect via relay server", "Errore connessione tramite il server relay"),
("Failed to make direct connection to remote desktop", "Impossibile connettersi direttamente al desktop remoto"),
("Set Password", "Imposta password"),
("OS Password", "Password sistema operativo"),
Expand Down Expand Up @@ -226,7 +226,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Add ID", "Aggiungi ID"),
("Add Tag", "Aggiungi etichetta"),
("Unselect all tags", "Deseleziona tutte le etichette"),
("Network error", "Errore di rete"),
("Network error", "Errore rete"),
("Username missed", "Nome utente mancante"),
("Password missed", "Password mancante"),
("Wrong credentials", "Credenziali errate"),
Expand Down Expand Up @@ -644,8 +644,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Parent directory", "Cartella principale"),
("Resume", "Riprendi"),
("Invalid file name", "Nome file non valido"),
("one-way-file-transfer-tip", ""),
("Authentication Required", ""),
("Authenticate", ""),
("one-way-file-transfer-tip", "Il trasferimento file unidirezionale è abilitato sul lato controllato."),
("Authentication Required", "Richiesta autenticazione"),
("Authenticate", "Autentica"),
].iter().cloned().collect();
}
12 changes: 6 additions & 6 deletions src/lang/ko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,11 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Platform", "플랫폼"),
("Days remaining", "일 남음"),
("enable-trusted-devices-tip", "신뢰할 수 있는 기기에서 2FA 검증 건너뛰기"),
("Parent directory", ""),
("Resume", ""),
("Invalid file name", ""),
("one-way-file-transfer-tip", ""),
("Authentication Required", ""),
("Authenticate", ""),
("Parent directory", "상위 디렉토리"),
("Resume", "재개"),
("Invalid file name", "잘못된 파일 이름"),
("one-way-file-transfer-tip", "단방향 파일 전송은 제어되는 쪽에서 활성화됩니다."),
("Authentication Required", "인증 필요함"),
("Authenticate", "인증"),
].iter().cloned().collect();
}
21 changes: 9 additions & 12 deletions src/platform/gtk_sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::{
const EXIT_CODE: i32 = -1;

enum Message {
PasswordPrompt(String),
PasswordPrompt((String, bool)),
Password((String, String)),
ErrorDialog(String),
Cancel,
Expand Down Expand Up @@ -107,24 +107,20 @@ fn ui(args: Vec<String>) {

let username = Arc::new(Mutex::new(crate::platform::get_active_username()));
let username_clone = username.clone();
let first_prompt = Arc::new(Mutex::new(true));

application.connect_activate(glib::clone!(@weak application =>move |_| {
let rx_to_ui = rx_to_ui_clone.clone();
let tx_from_ui = tx_from_ui_clone.clone();
let last_password = Arc::new(Mutex::new(String::new()));
let username = username_clone.clone();
let first_prompt = first_prompt.clone();

glib::timeout_add_local(std::time::Duration::from_millis(50), move || {
if let Ok(msg) = rx_to_ui.lock().unwrap().try_recv() {
match msg {
Message::PasswordPrompt(err_msg) => {
Message::PasswordPrompt((err_msg, show_edit)) => {
let last_pwd = last_password.lock().unwrap().clone();
let username = username.lock().unwrap().clone();
let first = first_prompt.lock().unwrap().clone();
*first_prompt.lock().unwrap() = false;
if let Some((username, password)) = password_prompt(&username, &last_pwd, &err_msg, first) {
if let Some((username, password)) = password_prompt(&username, &last_pwd, &err_msg, show_edit) {
*last_password.lock().unwrap() = password.clone();
if let Err(e) = tx_from_ui
.lock()
Expand Down Expand Up @@ -157,7 +153,7 @@ fn ui(args: Vec<String>) {
let acitve_user = crate::platform::get_active_username();
let mut initial_password = None;
if acitve_user != "root" {
if let Err(e) = tx_to_ui_clone.send(Message::PasswordPrompt("".to_string())) {
if let Err(e) = tx_to_ui_clone.send(Message::PasswordPrompt(("".to_string(), true))) {
log::error!("Channel error: {e:?}");
std::process::exit(EXIT_CODE);
}
Expand Down Expand Up @@ -385,7 +381,7 @@ fn ui_parent(
let err_msg = if first { "" } else { "Sorry, try again." };
first = false;
if let Err(e) =
tx_to_ui.send(Message::PasswordPrompt(err_msg.to_string()))
tx_to_ui.send(Message::PasswordPrompt((err_msg.to_string(), false)))
{
log::error!("Channel error: {e:?}");
kill_child(child);
Expand Down Expand Up @@ -627,6 +623,7 @@ fn password_prompt(
user_box.add(&user_entry);
user_box.set_halign(gtk::Align::Center);
user_box.set_valign(gtk::Align::Center);
user_box.set_vexpand(true);
content_area.add(&user_box);

edit_button.connect_clicked(
Expand Down Expand Up @@ -690,21 +687,21 @@ fn password_prompt(

let cancel_button = gtk::Button::builder()
.label(translate("Cancel".to_string()))
.expand(true)
.hexpand(true)
.build();
cancel_button.connect_clicked(glib::clone!(@weak dialog => move |_| {
dialog.response(gtk::ResponseType::Cancel);
}));
let authenticate_button = gtk::Button::builder()
.label(translate("Authenticate".to_string()))
.expand(true)
.hexpand(true)
.build();
authenticate_button.connect_clicked(glib::clone!(@weak dialog => move |_| {
dialog.response(gtk::ResponseType::Ok);
}));
let button_box = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.expand(true)
.hexpand(true)
.homogeneous(true)
.spacing(10)
.margin_top(10)
Expand Down
Loading

0 comments on commit e248c3d

Please sign in to comment.