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
zhangbo8418 authored Mar 12, 2024
2 parents f68a73b + 3c1492e commit 3583409
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 57 deletions.
6 changes: 3 additions & 3 deletions flutter/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ class LastWindowPosition {
}

String get windowFramePrefix =>
bind.isQs() ? "${kWindowPrefix}qs_" : kWindowPrefix;
bind.isIncomingOnly() ? "${kWindowPrefix}qs_" : kWindowPrefix;

/// Save window position and size on exit
/// Note that windowId must be provided if it's subwindow
Expand Down Expand Up @@ -1793,11 +1793,11 @@ Future<bool> restoreWindowPosition(WindowType type,
}
if (lpos.isMaximized == true) {
await restorePos();
if (!bind.isQs()) {
if (!bind.isIncomingOnly()) {
await windowManager.maximize();
}
} else {
if (!bind.isQs()) {
if (!bind.isIncomingOnly()) {
await windowManager.setSize(size);
}
await restorePos();
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/desktop/pages/connection_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class _OnlineStatusWidgetState extends State<OnlineStatusWidget> {
)
],
)),
).paddingOnly(right: bind.isQs() ? 8 : 0);
).paddingOnly(right: bind.isIncomingOnly() ? 8 : 0);
}

updateStatus() async {
Expand Down
12 changes: 6 additions & 6 deletions flutter/lib/desktop/pages/desktop_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
super.build(context);

final children = [buildLeftPane(context)];
if (!bind.isQs()) {
if (!bind.isIncomingOnly()) {
children.addAll([
const VerticalDivider(width: 1),
Expanded(child: buildRightPane(context)),
Expand All @@ -79,7 +79,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
future: buildHelpCards(),
builder: (_, data) {
if (data.hasData) {
if (bind.isQs()) {
if (bind.isIncomingOnly()) {
Future.delayed(Duration(milliseconds: 300), () {
_updateWindowSize();
});
Expand All @@ -92,7 +92,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
),
buildPluginEntry(),
];
if (bind.isQs()) {
if (bind.isIncomingOnly()) {
children.addAll([
Divider(),
Container(
Expand All @@ -104,7 +104,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
return ChangeNotifierProvider.value(
value: gFFI.serverModel,
child: Container(
width: bind.isQs() ? 280.0 : 200.0,
width: bind.isIncomingOnly() ? 280.0 : 200.0,
color: Theme.of(context).colorScheme.background,
child: DesktopScrollWrapper(
scrollController: _leftPaneScrollController,
Expand Down Expand Up @@ -474,7 +474,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
children: [
Container(
margin:
EdgeInsets.fromLTRB(0, marginTop, 0, bind.isQs() ? marginTop : 0),
EdgeInsets.fromLTRB(0, marginTop, 0, bind.isIncomingOnly() ? marginTop : 0),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
Expand Down Expand Up @@ -693,7 +693,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
});
_uniLinksSubscription = listenUniLinks();

if (bind.isQs()) {
if (bind.isIncomingOnly()) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_updateWindowSize();
});
Expand Down
8 changes: 4 additions & 4 deletions flutter/lib/desktop/pages/desktop_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class _DesktopSettingPageState extends State<DesktopSettingPage>
_TabInfo('Account', Icons.person_outline, Icons.person),
_TabInfo('About', Icons.info_outline, Icons.info)
];
if (!bind.isQs()) {
if (!bind.isIncomingOnly()) {
settingTabs.insert(
3,
_TabInfo('Display', Icons.desktop_windows_outlined,
Expand All @@ -133,7 +133,7 @@ class _DesktopSettingPageState extends State<DesktopSettingPage>
_Account(),
_About(),
];
if (!bind.isQs()) {
if (!bind.isIncomingOnly()) {
children.insert(3, _Display());
if (bind.pluginFeatureIsEnabled()) {
children.insert(4, _Plugin());
Expand Down Expand Up @@ -325,7 +325,7 @@ class _GeneralState extends State<_General> {

Widget other() {
final children = <Widget>[];
if (!bind.isQs()) {
if (!bind.isIncomingOnly()) {
children.add(_OptionCheckBox(context,
'Confirm before closing multiple tabs', 'enable-confirm-closing-tabs',
isServer: false));
Expand All @@ -334,7 +334,7 @@ class _GeneralState extends State<_General> {
_OptionCheckBox(context, 'Adaptive bitrate', 'enable-abr'),
wallpaper()
]);
if (!bind.isQs()) {
if (!bind.isIncomingOnly()) {
children.addAll([
_OptionCheckBox(
context,
Expand Down
4 changes: 2 additions & 2 deletions flutter/lib/desktop/pages/desktop_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
page: DesktopHomePage(
key: const ValueKey(kTabLabelHomePage),
)));
if (bind.isQs()) {
if (bind.isIncomingOnly()) {
tabController.onSelected = (key) {
if (key == kTabLabelHomePage) {
windowManager.setSize(getDesktopQsHomeSize());
Expand All @@ -81,7 +81,7 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
body: DesktopTab(
controller: tabController,
tail: Offstage(
offstage: bind.isQs(),
offstage: bind.isIncomingOnly(),
child: ActionIcon(
message: 'Settings',
icon: IconFont.menu,
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/desktop/widgets/tabbar_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class DesktopTabController {
}));
}
});
if ((isDesktop && bind.isQs()) || callOnSelected) {
if ((isDesktop && bind.isIncomingOnly()) || callOnSelected) {
if (state.value.tabs.length > index) {
final key = state.value.tabs[index].key;
onSelected?.call(key);
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void runMainApp(bool startService) async {
}
windowManager.setOpacity(1);
windowManager.setTitle(getWindowName());
windowManager.setResizable(!bind.isQs());
windowManager.setResizable(!bind.isIncomingOnly());
});
}

Expand Down
60 changes: 59 additions & 1 deletion libs/hbb_common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,13 @@ impl Config {
}

pub fn get_permanent_password() -> String {
CONFIG.read().unwrap().password.clone()
let mut password = CONFIG.read().unwrap().password.clone();
if password.is_empty() {
if let Some(v) = HARD_SETTINGS.read().unwrap().get("password") {
password = v.to_owned();
}
}
password
}

pub fn set_salt(salt: &str) {
Expand Down Expand Up @@ -1857,6 +1863,58 @@ fn get_or(
.cloned()
}

#[inline]
pub fn is_incoming_only() -> bool {
HARD_SETTINGS
.read()
.unwrap()
.get("conn-type")
.map_or(false, |x| x == ("incoming"))
}

#[inline]
pub fn is_outgoing_only() -> bool {
HARD_SETTINGS
.read()
.unwrap()
.get("conn-type")
.map_or(false, |x| x == ("outgoing"))
}

#[inline]
fn is_some_hard_opton(name: &str) -> bool {
HARD_SETTINGS
.read()
.unwrap()
.get(name)
.map_or(false, |x| x == ("Y"))
}

#[inline]
pub fn is_disable_tcp_listen() -> bool {
is_some_hard_opton("disable-tcp-listen")
}

#[inline]
pub fn is_disable_settings() -> bool {
is_some_hard_opton("disable-settings")
}

#[inline]
pub fn is_disable_ab() -> bool {
is_some_hard_opton("disable-ab")
}

#[inline]
pub fn is_disable_account() -> bool {
is_some_hard_opton("disable-account")
}

#[inline]
pub fn is_disable_installation() -> bool {
is_some_hard_opton("disable-installation")
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
17 changes: 14 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,11 @@ impl ClipboardContext {
}

pub fn load_custom_client() {
#[cfg(debug_assertions)]
if let Ok(data) = std::fs::read_to_string("./custom.txt") {
read_custom_client(data.trim());
return;
}
let Ok(cmd) = std::env::current_exe() else {
return;
};
Expand All @@ -1488,7 +1493,7 @@ pub fn load_custom_client() {
log::error!("Failed to read custom client config");
return;
};
read_custom_client(&data);
read_custom_client(&data.trim());
}
}

Expand All @@ -1512,7 +1517,13 @@ pub fn read_custom_client(config: &str) {
log::error!("Failed to parse custom client config");
return;
};
if let Some(default_settings) = data.remove("default_settings") {

if let Some(app_name) = data.remove("app-name") {
if let Some(app_name) = app_name.as_str() {
*config::APP_NAME.write().unwrap() = app_name.to_owned();
}
}
if let Some(default_settings) = data.remove("default-settings") {
if let Some(default_settings) = default_settings.as_object() {
for (k, v) in default_settings {
let Some(v) = v.as_str() else {
Expand All @@ -1537,7 +1548,7 @@ pub fn read_custom_client(config: &str) {
}
}
}
if let Some(overwrite_settings) = data.remove("overwrite_settings") {
if let Some(overwrite_settings) = data.remove("override-settings") {
if let Some(overwrite_settings) = overwrite_settings.as_object() {
for (k, v) in overwrite_settings {
let Some(v) = v.as_str() else {
Expand Down
13 changes: 8 additions & 5 deletions src/core_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::client::translate;
#[cfg(not(debug_assertions))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use crate::platform::breakdown_callback;
use hbb_common::log;
use hbb_common::{config, log};
#[cfg(not(debug_assertions))]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::platform::register_breakdown_handler;
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn core_main() -> Option<Vec<String>> {
]
.contains(&arg.as_str())
{
if crate::flutter_ffi::is_qs().0 {
if config::is_incoming_only() {
return None;
} else {
_is_flutter_invoke_new_connection = true;
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn core_main() -> Option<Vec<String>> {
#[cfg(feature = "flutter")]
{
let (k, v) = ("LIBGL_ALWAYS_SOFTWARE", "1");
if !hbb_common::config::Config::get_option("allow-always-software-render").is_empty() {
if !config::Config::get_option("allow-always-software-render").is_empty() {
std::env::set_var(k, v);
} else {
std::env::remove_var(k);
Expand All @@ -111,7 +111,7 @@ pub fn core_main() -> Option<Vec<String>> {
return core_main_invoke_new_connection(std::env::args());
}
let click_setup = cfg!(windows) && args.is_empty() && crate::common::is_setup(&arg_exe);
if click_setup {
if click_setup && !config::is_disable_installation(){
args.push("--install".to_owned());
flutter_args.push("--install".to_string());
}
Expand Down Expand Up @@ -188,6 +188,9 @@ pub fn core_main() -> Option<Vec<String>> {
}
return None;
} else if args[0] == "--silent-install" {
if config::is_disable_installation() {
return None;
}
let res = platform::install_me(
"desktopicon startmenu",
"".to_owned(),
Expand All @@ -202,7 +205,7 @@ pub fn core_main() -> Option<Vec<String>> {
}
};
Toast::new(Toast::POWERSHELL_APP_ID)
.title(&hbb_common::config::APP_NAME.read().unwrap())
.title(&config::APP_NAME.read().unwrap())
.text1(&text)
.sound(Some(Sound::Default))
.duration(Duration::Short)
Expand Down
34 changes: 31 additions & 3 deletions src/flutter_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ lazy_static::lazy_static! {
fn initialize(app_dir: &str) {
flutter::async_tasks::start_flutter_async_runner();
*config::APP_DIR.write().unwrap() = app_dir.to_owned();
// core_main's load_custom_client does not work for flutter since it is only applied to its load_library in main.c
crate::load_custom_client();
#[cfg(target_os = "android")]
{
// flexi_logger can't work when android_logger initialized.
Expand All @@ -62,7 +64,12 @@ fn initialize(app_dir: &str) {
#[cfg(target_os = "ios")]
{
use hbb_common::env_logger::*;
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "debug"));
init_fro_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "debug"));
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
// core_main's init_log does not work for flutter since it is only applied to its load_library in main.c
hbb_common::init_log(false, "flutter_ffi");
}
}

Expand Down Expand Up @@ -1813,8 +1820,29 @@ pub fn main_support_remove_wallpaper() -> bool {
support_remove_wallpaper()
}

pub fn is_qs() -> SyncReturn<bool> {
SyncReturn(get_hard_option("connection-type".to_owned()) == "incoming")
pub fn is_incoming_only() -> SyncReturn<bool> {
SyncReturn(config::is_incoming_only())
}

pub fn is_outgoing_only() -> SyncReturn<bool> {
SyncReturn(config::is_outgoing_only())
}

pub fn is_disable_settings() -> SyncReturn<bool> {
SyncReturn(config::is_disable_settings())
}

pub fn is_disable_ab() -> SyncReturn<bool> {
SyncReturn(config::is_disable_ab())
}

pub fn is_disable_account() -> SyncReturn<bool> {
SyncReturn(config::is_disable_account())
}

// windows only
pub fn is_disable_installation() -> SyncReturn<bool> {
SyncReturn(config::is_disable_installation())
}

/// Send a url scheme throught the ipc.
Expand Down
Loading

0 comments on commit 3583409

Please sign in to comment.