From 3fd1da05f4d9fc1bd6f8c866998888eae0d58e4c Mon Sep 17 00:00:00 2001 From: fufesou Date: Thu, 30 Mar 2023 10:48:18 +0800 Subject: [PATCH] tmp commit Signed-off-by: fufesou --- flutter/lib/common/widgets/dialog.dart | 2 +- .../lib/desktop/widgets/remote_toolbar.dart | 68 ++++++++++++++++++- flutter/lib/models/model.dart | 1 + src/lang/en.rs | 14 ++-- src/platform/linux_desktop_manager.rs | 9 +++ src/server/connection.rs | 10 ++- 6 files changed, 92 insertions(+), 12 deletions(-) diff --git a/flutter/lib/common/widgets/dialog.dart b/flutter/lib/common/widgets/dialog.dart index 569d64428..0fdd17a4b 100644 --- a/flutter/lib/common/widgets/dialog.dart +++ b/flutter/lib/common/widgets/dialog.dart @@ -625,7 +625,7 @@ _connectDialog( osAccountWidget(), osUsernameController == null || passwordController == null ? Offstage() - : Container(height: 10), + : Container(height: 12), passwdWidget(), ]), actions: [ diff --git a/flutter/lib/desktop/widgets/remote_toolbar.dart b/flutter/lib/desktop/widgets/remote_toolbar.dart index 703ed6db9..467cd69b0 100644 --- a/flutter/lib/desktop/widgets/remote_toolbar.dart +++ b/flutter/lib/desktop/widgets/remote_toolbar.dart @@ -639,7 +639,7 @@ class _ControlMenu extends StatelessWidget { ffi: ffi, menuChildren: [ requestElevation(), - osPassword(), + ffi.ffiModel.pi.is_headless ? osAccount() : osPassword(), transferFile(context), tcpTunneling(context), note(), @@ -662,6 +662,72 @@ class _ControlMenu extends StatelessWidget { onPressed: () => showRequestElevationDialog(id, ffi.dialogManager)); } + osAccount() { + return _MenuItemButton( + child: Text(translate('OS Account')), + trailingIcon: Transform.scale(scale: 0.8, child: Icon(Icons.edit)), + ffi: ffi, + onPressed: () => _showSetOSAccount(id, false, ffi.dialogManager)); + } + + _showSetOSAccount( + String id, bool login, OverlayDialogManager dialogManager) async { + final usernameController = TextEditingController(); + final passwdController = TextEditingController(); + var username = + await bind.sessionGetOption(id: id, arg: 'os-username') ?? ''; + var password = + await bind.sessionGetOption(id: id, arg: 'os-password') ?? ''; + usernameController.text = username; + passwdController.text = password; + dialogManager.show((setState, close) { + submit() { + final username = usernameController.text.trim(); + final password = usernameController.text.trim(); + bind.sessionPeerOption(id: id, name: 'os-username', value: username); + bind.sessionPeerOption(id: id, name: 'os-password', value: password); + close(); + } + + return CustomAlertDialog( + title: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon(Icons.password_rounded, color: MyTheme.accent), + Text(translate('OS Password')).paddingOnly(left: 10), + ], + ), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + DialogTextField( + title: translate(DialogTextField.kUsernameTitle), + controller: usernameController, + prefixIcon: DialogTextField.kUsernameIcon, + errorText: null, + ), + PasswordWidget(controller: passwdController), + ], + ), + actions: [ + dialogButton( + "Cancel", + icon: Icon(Icons.close_rounded), + onPressed: close, + isOutline: true, + ), + dialogButton( + "OK", + icon: Icon(Icons.done_rounded), + onPressed: submit, + ), + ], + onSubmit: submit, + onCancel: close, + ); + }); + } + osPassword() { return _MenuItemButton( child: Text(translate('OS Password')), diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 470bb47c3..7d1249906 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -1725,6 +1725,7 @@ class PeerInfo { Map platform_additions = {}; bool get is_wayland => platform_additions['is_wayland'] == true; + bool get is_headless => platform_additions['headless'] == true; } const canvasKey = 'canvas'; diff --git a/src/lang/en.rs b/src/lang/en.rs index 95186325f..79f18ebc5 100644 --- a/src/lang/en.rs +++ b/src/lang/en.rs @@ -54,12 +54,12 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> = ("empty_address_book_tip", "Oh dear, it appears that there are currently no peers listed in your address book."), ("identical_file_tip", "This file is identical with the peer's one."), ("show_monitors_tip", "Show monitors in toolbar."), - ("enter_rustdesk_passwd_tip", "Enter RustDesk password."), - ("remember_rustdesk_passwd_tip", "Remember RustDesk password."), - ("login_linux_tip", "Login to remote Linux account."), - ("login_linux_tooltip_tip", "You need to login to remote Linux account to enable a X desktop session."), - ("verify_rustdesk_password_tip", "Veryfy RustDesk password."), - ("remember_account_tip", "Remember this account."), - ("remember_password_tip", "Remember password."), + ("enter_rustdesk_passwd_tip", "Enter RustDesk password"), + ("remember_rustdesk_passwd_tip", "Remember RustDesk password"), + ("login_linux_tip", "Login to remote Linux account"), + ("login_linux_tooltip_tip", "You need to login to remote Linux account to enable a X desktop session"), + ("verify_rustdesk_password_tip", "Veryfy RustDesk password"), + ("remember_account_tip", "Remember this account"), + ("remember_password_tip", "Remember password"), ].iter().cloned().collect(); } diff --git a/src/platform/linux_desktop_manager.rs b/src/platform/linux_desktop_manager.rs index b21b2d5b1..a957e045e 100644 --- a/src/platform/linux_desktop_manager.rs +++ b/src/platform/linux_desktop_manager.rs @@ -80,6 +80,15 @@ pub fn try_start_x_session(username: &str, password: &str) -> ResultType<(String } } +#[inline] +pub fn is_headless() -> bool { + DESKTOP_MANAGER + .lock() + .unwrap() + .as_ref() + .map_or(false, |manager| manager.x11_username.is_empty()) +} + pub fn get_username() -> String { match &*DESKTOP_MANAGER.lock().unwrap() { Some(manager) => { diff --git a/src/server/connection.rs b/src/server/connection.rs index 2f86ca5f0..ee4bdda35 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -3,6 +3,8 @@ use super::{input_service::*, *}; use crate::clipboard_file::*; #[cfg(not(any(target_os = "android", target_os = "ios")))] use crate::common::update_clipboard; +#[cfg(target_os = "linux")] +use crate::platform::linux_desktop_manager; #[cfg(windows)] use crate::portable_service::client as portable_client; use crate::{ @@ -866,6 +868,9 @@ impl Connection { if crate::platform::current_is_wayland() { platform_additions.insert("is_wayland".into(), json!(true)); } + if linux_desktop_manager::is_headless() { + platform_additions.insert("headless".into(), json!(true)); + } if !platform_additions.is_empty() { pi.platform_additions = serde_json::to_string(&platform_additions).unwrap_or("".into()); @@ -1074,7 +1079,7 @@ impl Connection { fn try_start_desktop(_username: &str, _passsword: &str) -> String { #[cfg(target_os = "linux")] if _username.is_empty() { - let username = crate::platform::linux_desktop_manager::get_username(); + let username = linux_desktop_manager::get_username(); if username.is_empty() { LOGIN_MSG_XSESSION_NOT_READY } else { @@ -1082,8 +1087,7 @@ impl Connection { } .to_owned() } else { - match crate::platform::linux_desktop_manager::try_start_x_session(_username, _passsword) - { + match linux_desktop_manager::try_start_x_session(_username, _passsword) { Ok((username, x11_ready)) => { if x11_ready { if _username != username {