mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-20 15:06:14 -05:00
Prefer Native Shell on supported Linux installations
This commit is contained in:
37 files changed
+869
-250
No files matched your search
@@ -486,6 +486,25 @@ mod tests {
|
||||
assert!(cli.can_run_alongside_client());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn launch_gui_interface_accepts_minimized_launch_but_not_an_auth_callback() {
|
||||
for variant in ["tauri", "nsh"] {
|
||||
assert!(Cli::try_parse_from(["gpclient", "launch-gui", "--interface", variant, "--minimized"]).is_ok());
|
||||
assert!(
|
||||
Cli::try_parse_from([
|
||||
"gpclient",
|
||||
"launch-gui",
|
||||
"--interface",
|
||||
variant,
|
||||
"globalprotectcallback:token"
|
||||
])
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
assert!(Cli::try_parse_from(["gpclient", "launch-gui", "--interface", "unknown"]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
fn launch_gui_rejects_callback_with_minimized() {
|
||||
|
||||
@@ -24,6 +24,14 @@ pub(crate) struct LaunchGuiArgs {
|
||||
help = "The external-browser authentication callback URL"
|
||||
)]
|
||||
callback: Option<String>,
|
||||
#[cfg(target_os = "linux")]
|
||||
#[arg(
|
||||
long,
|
||||
value_enum,
|
||||
conflicts_with = "callback",
|
||||
help = "Launch this interface and remember it for future launches"
|
||||
)]
|
||||
interface: Option<gpapi::gui::GuiVariant>,
|
||||
#[arg(long, help = "Launch the GUI minimized")]
|
||||
minimized: bool,
|
||||
}
|
||||
@@ -61,7 +69,10 @@ impl<'a> LaunchGuiHandler<'a> {
|
||||
return forward_auth_callback(callback);
|
||||
}
|
||||
|
||||
if DesktopLauncher::activate_existing().await.is_ok() {
|
||||
let launcher = DesktopLauncher::new(env!("CARGO_PKG_VERSION")).minimized(self.args.minimized);
|
||||
#[cfg(target_os = "linux")]
|
||||
let launcher = launcher.interface(self.args.interface);
|
||||
if launcher.activate_or_reject_existing().await? {
|
||||
info!("The GUI is already running");
|
||||
return Ok(());
|
||||
}
|
||||
@@ -71,11 +82,7 @@ impl<'a> LaunchGuiHandler<'a> {
|
||||
|
||||
info!("Log file: {}", log_file_path);
|
||||
|
||||
let exit_status = DesktopLauncher::new(env!("CARGO_PKG_VERSION"))
|
||||
.minimized(self.args.minimized)
|
||||
.log_file(&log_file_path)
|
||||
.launch()
|
||||
.await?;
|
||||
let exit_status = launcher.log_file(&log_file_path).launch().await?;
|
||||
|
||||
info!("Service exited with status: {}", exit_status);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::{io::Read, sync::Arc};
|
||||
use anyhow::{Context, bail};
|
||||
use gpapi::{
|
||||
clap::InfoLevelVerbosity,
|
||||
gui::GuiTheme,
|
||||
gui::{GuiTheme, GuiVariant, NATIVE_SHELL_SUPPORTED},
|
||||
service::transport::{MAX_CREDENTIAL_FRAME, SessionCredential},
|
||||
utils::env_utils,
|
||||
};
|
||||
@@ -30,8 +30,8 @@ struct Cli {
|
||||
|
||||
#[arg(long, default_value = env!("CARGO_PKG_VERSION"), help = "The version of the GUI")]
|
||||
gui_version: String,
|
||||
#[arg(long, default_value = "tauri", value_parser = ["tauri", "nsh"])]
|
||||
gui_variant: String,
|
||||
#[arg(long, value_enum, default_value_t = GuiVariant::Tauri)]
|
||||
gui_variant: GuiVariant,
|
||||
|
||||
#[arg(long, value_enum, default_value = "system", help = "Window appearance")]
|
||||
theme: GuiTheme,
|
||||
@@ -44,20 +44,15 @@ impl Cli {
|
||||
fn run(&self) -> anyhow::Result<()> {
|
||||
let credential = self.read_credential()?;
|
||||
let credential_lease = monitor_credential_lease().context("Failed to monitor service credential lifetime")?;
|
||||
let variant = if self.gui_variant == "nsh" {
|
||||
gpapi::gui::GuiVariant::Nsh
|
||||
} else {
|
||||
gpapi::gui::GuiVariant::Tauri
|
||||
};
|
||||
anyhow::ensure!(
|
||||
variant != gpapi::gui::GuiVariant::Nsh || cfg!(target_os = "linux"),
|
||||
"Native Shell is available only on Linux"
|
||||
self.gui_variant != GuiVariant::Nsh || NATIVE_SHELL_SUPPORTED,
|
||||
"Native Shell is unavailable for this platform"
|
||||
);
|
||||
let app = App::new(
|
||||
Arc::new(credential),
|
||||
credential_lease,
|
||||
&self.gui_version,
|
||||
variant,
|
||||
self.gui_variant,
|
||||
self.theme,
|
||||
);
|
||||
|
||||
|
||||
@@ -42,22 +42,17 @@ const GUI_LIBC_SUFFIX: &str = "-musl";
|
||||
const GUI_LIBC_SUFFIX: &str = "";
|
||||
|
||||
fn gui_asset_name(variant: gpapi::gui::GuiVariant) -> Option<String> {
|
||||
gui_asset_name_for(variant, std::env::consts::OS, std::env::consts::ARCH, GUI_LIBC_SUFFIX)
|
||||
}
|
||||
|
||||
fn gui_asset_name_for(variant: gpapi::gui::GuiVariant, os: &str, arch: &str, libc_suffix: &str) -> Option<String> {
|
||||
if os == "linux" && matches!(arch, "x86_64" | "aarch64") {
|
||||
return Some(format!("{}_{arch}{libc_suffix}.bin.tar.xz", variant.binary_name()));
|
||||
}
|
||||
if variant == gpapi::gui::GuiVariant::Nsh {
|
||||
return nsh_asset_name_for(std::env::consts::OS, std::env::consts::ARCH);
|
||||
return None;
|
||||
}
|
||||
gui_asset_name_for(std::env::consts::OS, std::env::consts::ARCH, GUI_LIBC_SUFFIX)
|
||||
}
|
||||
|
||||
fn nsh_asset_name_for(os: &str, arch: &str) -> Option<String> {
|
||||
match (os, arch) {
|
||||
("linux", "x86_64" | "aarch64") => Some(format!("gpgui-nsh_{arch}.bin.tar.xz")),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn gui_asset_name_for(os: &str, arch: &str, libc_suffix: &str) -> Option<String> {
|
||||
let name = match (os, arch) {
|
||||
("linux", "x86_64" | "aarch64") => format!("gpgui_{arch}{libc_suffix}.bin.tar.xz"),
|
||||
("freebsd", "x86_64") => "gpgui_freebsd_amd64.bin.tar.xz".to_owned(),
|
||||
("freebsd", "aarch64") => "gpgui_freebsd_arm64.bin.tar.xz".to_owned(),
|
||||
("openbsd", "x86_64") => "gpgui_openbsd_amd64.bin.tar.xz".to_owned(),
|
||||
@@ -506,6 +501,7 @@ impl GuiUpdater {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use gpapi::gui::GuiVariant;
|
||||
use gpapi::service::{
|
||||
transport::{ClientPrelude, NoiseResponder},
|
||||
vpn_env::{HostInfo, VpnEnv},
|
||||
@@ -519,36 +515,36 @@ mod tests {
|
||||
#[test]
|
||||
fn selects_platform_specific_gui_assets() {
|
||||
assert_eq!(
|
||||
gui_asset_name_for("linux", "x86_64", ""),
|
||||
gui_asset_name_for(GuiVariant::Tauri, "linux", "x86_64", ""),
|
||||
Some("gpgui_x86_64.bin.tar.xz".to_owned())
|
||||
);
|
||||
assert_eq!(
|
||||
gui_asset_name_for("linux", "aarch64", "-musl"),
|
||||
gui_asset_name_for(GuiVariant::Tauri, "linux", "aarch64", "-musl"),
|
||||
Some("gpgui_aarch64-musl.bin.tar.xz".to_owned())
|
||||
);
|
||||
assert_eq!(
|
||||
gui_asset_name_for("freebsd", "x86_64", ""),
|
||||
gui_asset_name_for(GuiVariant::Tauri, "freebsd", "x86_64", ""),
|
||||
Some("gpgui_freebsd_amd64.bin.tar.xz".to_owned())
|
||||
);
|
||||
assert_eq!(
|
||||
gui_asset_name_for("openbsd", "aarch64", ""),
|
||||
gui_asset_name_for(GuiVariant::Tauri, "openbsd", "aarch64", ""),
|
||||
Some("gpgui_openbsd_arm64.bin.tar.xz".to_owned())
|
||||
);
|
||||
assert_eq!(gui_asset_name_for("macos", "aarch64", ""), None);
|
||||
assert_eq!(gui_asset_name_for(GuiVariant::Tauri, "macos", "aarch64", ""), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nsh_assets_are_linux_only_and_use_the_nsh_binary_archive() {
|
||||
assert_eq!(
|
||||
nsh_asset_name_for("linux", "x86_64"),
|
||||
gui_asset_name_for(GuiVariant::Nsh, "linux", "x86_64", ""),
|
||||
Some("gpgui-nsh_x86_64.bin.tar.xz".into())
|
||||
);
|
||||
assert_eq!(
|
||||
nsh_asset_name_for("linux", "aarch64"),
|
||||
Some("gpgui-nsh_aarch64.bin.tar.xz".into())
|
||||
gui_asset_name_for(GuiVariant::Nsh, "linux", "aarch64", "-musl"),
|
||||
Some("gpgui-nsh_aarch64-musl.bin.tar.xz".into())
|
||||
);
|
||||
for os in ["freebsd", "openbsd", "macos"] {
|
||||
assert_eq!(nsh_asset_name_for(os, "x86_64"), None);
|
||||
assert_eq!(gui_asset_name_for(GuiVariant::Nsh, os, "x86_64", ""), None);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user