From afe07dde6f980f85f6a685dfc428099e8c456d01 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sun, 9 Apr 2023 11:35:14 +0800 Subject: [PATCH 1/4] do not enable linux_headless when flatpak or appimage is enabled Signed-off-by: fufesou --- src/platform/mod.rs | 1 + src/rendezvous_mediator.rs | 2 ++ src/server/connection.rs | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/platform/mod.rs b/src/platform/mod.rs index fc27be098..e382b0b13 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -18,6 +18,7 @@ pub mod delegate; pub mod linux; #[cfg(all(target_os = "linux", feature = "linux_headless"))] +#[cfg(not(any(feature = "flatpak", feature = "appimage")))] pub mod linux_desktop_manager; #[cfg(not(any(target_os = "android", target_os = "ios")))] diff --git a/src/rendezvous_mediator.rs b/src/rendezvous_mediator.rs index 6dd0a1284..b6422e9a6 100644 --- a/src/rendezvous_mediator.rs +++ b/src/rendezvous_mediator.rs @@ -73,6 +73,7 @@ impl RendezvousMediator { }); } #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] crate::platform::linux_desktop_manager::start_xdesktop(); loop { Config::reset_online(); @@ -101,6 +102,7 @@ impl RendezvousMediator { // It should be better to call stop_xdesktop. // But for server, it also is Ok without calling this method. // #[cfg(all(target_os = "linux", feature = "linux_headless"))] + // #[cfg(not(any(feature = "flatpak", feature = "appimage")))] // crate::platform::linux_desktop_manager::stop_xdesktop(); } diff --git a/src/server/connection.rs b/src/server/connection.rs index cf962d983..318424b3d 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -4,6 +4,7 @@ use crate::clipboard_file::*; #[cfg(not(any(target_os = "android", target_os = "ios")))] use crate::common::update_clipboard; #[cfg(all(target_os = "linux", feature = "linux_headless"))] +#[cfg(not(any(feature = "flatpak", feature = "appimage")))] use crate::platform::linux_desktop_manager; #[cfg(windows)] use crate::portable_service::client as portable_client; @@ -19,6 +20,7 @@ use crate::{common::DEVICE_NAME, flutter::connection_manager::start_channel}; use crate::{ipc, VERSION}; use cidr_utils::cidr::IpCidr; #[cfg(all(target_os = "linux", feature = "linux_headless"))] +#[cfg(not(any(feature = "flatpak", feature = "appimage")))] use hbb_common::platform::linux::run_cmds; use hbb_common::{ config::Config, @@ -158,8 +160,10 @@ pub struct Connection { #[cfg(not(any(target_os = "android", target_os = "ios")))] pressed_modifiers: HashSet, #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] rx_cm_stream_ready: mpsc::Receiver<()>, #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] tx_desktop_ready: mpsc::Sender<()>, } @@ -279,8 +283,10 @@ impl Connection { #[cfg(not(any(target_os = "android", target_os = "ios")))] pressed_modifiers: Default::default(), #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] rx_cm_stream_ready: _rx_cm_stream_ready, #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] tx_desktop_ready: _tx_desktop_ready, }; #[cfg(not(any(target_os = "android", target_os = "ios")))] @@ -895,6 +901,7 @@ impl Connection { platform_additions.insert("is_wayland".into(), json!(true)); } #[cfg(feature = "linux_headless")] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] if linux_desktop_manager::is_headless() { platform_additions.insert("headless".into(), json!(true)); } @@ -1262,6 +1269,7 @@ impl Connection { } #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] let desktop_err = match lr.os_login.as_ref() { Some(os_login) => { linux_desktop_manager::try_start_desktop(&os_login.username, &os_login.password) @@ -1269,12 +1277,15 @@ impl Connection { None => linux_desktop_manager::try_start_desktop("", ""), }; #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] let is_headless = linux_desktop_manager::is_headless(); #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] let wait_ipc_timeout = 10_000; // If err is LOGIN_MSG_DESKTOP_SESSION_NOT_READY, just keep this msg and go on checking password. #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] if !desktop_err.is_empty() && desktop_err != LOGIN_MSG_DESKTOP_SESSION_NOT_READY { self.send_login_error(desktop_err).await; return true; @@ -1299,6 +1310,7 @@ impl Connection { return false; } else if self.is_recent_session() { #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] if desktop_err.is_empty() { #[cfg(target_os = "linux")] if is_headless { @@ -1323,6 +1335,7 @@ impl Connection { } } else if lr.password.is_empty() { #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] if desktop_err.is_empty() { self.try_start_cm(lr.my_id, lr.my_name, false); } else { @@ -1372,6 +1385,7 @@ impl Connection { .unwrap() .insert(self.ip.clone(), failure); #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] if desktop_err.is_empty() { self.send_login_error(LOGIN_MSG_PASSWORD_WRONG).await; self.try_start_cm(lr.my_id, lr.my_name, false); @@ -1389,6 +1403,7 @@ impl Connection { LOGIN_FAILURES.lock().unwrap().remove(&self.ip); } #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] if desktop_err.is_empty() { #[cfg(target_os = "linux")] if is_headless { @@ -2200,9 +2215,11 @@ async fn start_ipc( #[cfg(not(feature = "linux_headless"))] let user = None; #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] let mut user = None; // Cm run as user, wait until desktop session is ready. #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(not(any(feature = "flatpak", feature = "appimage")))] if linux_desktop_manager::is_headless() { let mut username = linux_desktop_manager::get_username(); loop { From 6da9d2430708738bf67b79a4651b9ffd2677ab39 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sun, 9 Apr 2023 12:38:17 +0800 Subject: [PATCH 2/4] update github workflow Signed-off-by: fufesou --- .github/workflows/flutter-build.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/flutter-build.yml b/.github/workflows/flutter-build.yml index 1bc519f56..b6eca6c22 100644 --- a/.github/workflows/flutter-build.yml +++ b/.github/workflows/flutter-build.yml @@ -681,7 +681,16 @@ jobs: x86_64) # no need mock on x86_64 export VCPKG_ROOT=/opt/artifacts/vcpkg - cargo build --lib --features hwcodec,flutter,flutter_texture_render,linux_headless,${{ matrix.job.extra-build-features }} --release + case "${{ matrix.job.extra-build-features }}" in + "flatpak") + cargo build --lib --features hwcodec,flutter,flutter_texture_render,${{ matrix.job.extra-build-features }} --release + ;; + "appimage") + cargo build --lib --features hwcodec,flutter,flutter_texture_render,${{ matrix.job.extra-build-features }} --release + ;; + "") + cargo build --lib --features hwcodec,flutter,flutter_texture_render,linux_headless,${{ matrix.job.extra-build-features }} --release + ;; ;; esac From 02f5ed9e56c4353373e51b9e5b6ac99f96140825 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sun, 9 Apr 2023 12:43:44 +0800 Subject: [PATCH 3/4] update github workflow Signed-off-by: fufesou --- .github/workflows/flutter-build.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/flutter-build.yml b/.github/workflows/flutter-build.yml index b6eca6c22..e732a2a30 100644 --- a/.github/workflows/flutter-build.yml +++ b/.github/workflows/flutter-build.yml @@ -545,7 +545,7 @@ jobs: arch: x86_64, target: x86_64-unknown-linux-gnu, os: ubuntu-20.04, - extra-build-features: "", + extra-build-features: "linux_headless", } - { arch: x86_64, @@ -681,16 +681,7 @@ jobs: x86_64) # no need mock on x86_64 export VCPKG_ROOT=/opt/artifacts/vcpkg - case "${{ matrix.job.extra-build-features }}" in - "flatpak") - cargo build --lib --features hwcodec,flutter,flutter_texture_render,${{ matrix.job.extra-build-features }} --release - ;; - "appimage") - cargo build --lib --features hwcodec,flutter,flutter_texture_render,${{ matrix.job.extra-build-features }} --release - ;; - "") - cargo build --lib --features hwcodec,flutter,flutter_texture_render,linux_headless,${{ matrix.job.extra-build-features }} --release - ;; + cargo build --lib --features hwcodec,flutter,flutter_texture_render,${{ matrix.job.extra-build-features }} --release ;; esac From b6f7d56a066e881faf075d29cf1401ab3c06d8e1 Mon Sep 17 00:00:00 2001 From: fufesou Date: Sun, 9 Apr 2023 13:01:02 +0800 Subject: [PATCH 4/4] fix build Signed-off-by: fufesou --- src/server/connection.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/server/connection.rs b/src/server/connection.rs index 318424b3d..8a6ba99b9 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -2215,6 +2215,9 @@ async fn start_ipc( #[cfg(not(feature = "linux_headless"))] let user = None; #[cfg(all(target_os = "linux", feature = "linux_headless"))] + #[cfg(any(feature = "flatpak", feature = "appimage"))] + let user = None; + #[cfg(all(target_os = "linux", feature = "linux_headless"))] #[cfg(not(any(feature = "flatpak", feature = "appimage")))] let mut user = None; // Cm run as user, wait until desktop session is ready.