mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
fix: multiple tray icon related: #464
This commit is contained in:
parent
fe3d3df662
commit
c70c7ee5b9
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1599,6 +1599,7 @@ dependencies = [
|
||||
"clap-verbosity-flag",
|
||||
"dns-lookup",
|
||||
"env_logger",
|
||||
"gtk",
|
||||
"log",
|
||||
"log-reload",
|
||||
"md5",
|
||||
|
@ -39,6 +39,9 @@ clap-verbosity-flag = { workspace = true, optional = true }
|
||||
env_logger = { workspace = true, optional = true }
|
||||
log-reload = { version = "0.1", optional = true }
|
||||
|
||||
[target.'cfg(not(any(target_os="macos", target_os="windows")))'.dependencies]
|
||||
gtk = "0.18"
|
||||
|
||||
[features]
|
||||
tauri = ["dep:tauri"]
|
||||
clap = ["dep:clap", "dep:clap-verbosity-flag"]
|
||||
|
@ -41,12 +41,6 @@ pub fn patch_gui_runtime_env(hidpi: bool) {
|
||||
// This is to avoid blank screen on some systems
|
||||
std::env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1");
|
||||
|
||||
// Workaround for https://github.com/tauri-apps/tao/issues/929
|
||||
let is_wayland = std::env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland";
|
||||
if is_wayland {
|
||||
env::set_var("GDK_BACKEND", "x11");
|
||||
}
|
||||
|
||||
if hidpi {
|
||||
info!("Setting GDK_SCALE=2 and GDK_DPI_SCALE=0.5");
|
||||
std::env::set_var("GDK_SCALE", "2");
|
||||
|
@ -1,26 +1,49 @@
|
||||
use std::{process::ExitStatus, time::Duration};
|
||||
|
||||
use anyhow::bail;
|
||||
use log::info;
|
||||
use tauri::WebviewWindow;
|
||||
use tokio::process::Command;
|
||||
|
||||
pub trait WindowExt {
|
||||
fn raise(&self) -> anyhow::Result<()>;
|
||||
}
|
||||
|
||||
impl WindowExt for WebviewWindow {
|
||||
#[cfg(any(target_os = "macos", target_os = "windows"))]
|
||||
fn raise(&self) -> anyhow::Result<()> {
|
||||
raise_window(self)
|
||||
self.show()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
||||
fn raise(&self) -> anyhow::Result<()> {
|
||||
unix::raise_window(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn raise_window(win: &WebviewWindow) -> anyhow::Result<()> {
|
||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
||||
mod unix {
|
||||
use std::{process::ExitStatus, time::Duration};
|
||||
|
||||
use anyhow::bail;
|
||||
use gtk::{
|
||||
glib::Cast,
|
||||
traits::{EventBoxExt, GtkWindowExt, WidgetExt},
|
||||
EventBox,
|
||||
};
|
||||
use log::info;
|
||||
use tauri::WebviewWindow;
|
||||
use tokio::process::Command;
|
||||
|
||||
pub fn raise_window(win: &WebviewWindow) -> anyhow::Result<()> {
|
||||
let is_wayland = std::env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland";
|
||||
|
||||
if is_wayland {
|
||||
win.hide()?;
|
||||
win.show()?;
|
||||
let gtk_win = win.gtk_window()?;
|
||||
if let Some(header) = gtk_win.titlebar() {
|
||||
let _ = header.downcast::<EventBox>().map(|event_box| {
|
||||
event_box.set_above_child(false);
|
||||
});
|
||||
}
|
||||
|
||||
gtk_win.hide();
|
||||
gtk_win.show_all();
|
||||
} else {
|
||||
if !win.is_visible()? {
|
||||
win.show()?;
|
||||
@ -33,14 +56,14 @@ pub fn raise_window(win: &WebviewWindow) -> anyhow::Result<()> {
|
||||
});
|
||||
}
|
||||
|
||||
// Calling window.show() on Windows will cause the menu to be shown.
|
||||
// Calling window.show() on window object will cause the menu to be shown.
|
||||
// We need to hide it again.
|
||||
win.hide_menu()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn wmctrl_raise_window(title: &str) -> anyhow::Result<()> {
|
||||
async fn wmctrl_raise_window(title: &str) -> anyhow::Result<()> {
|
||||
let mut counter = 0;
|
||||
|
||||
loop {
|
||||
@ -58,9 +81,9 @@ async fn wmctrl_raise_window(title: &str) -> anyhow::Result<()> {
|
||||
counter += 1;
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn wmctrl_try_raise_window(title: &str) -> anyhow::Result<ExitStatus> {
|
||||
async fn wmctrl_try_raise_window(title: &str) -> anyhow::Result<ExitStatus> {
|
||||
let exit_status = Command::new("wmctrl")
|
||||
.arg("-F")
|
||||
.arg("-a")
|
||||
@ -70,4 +93,5 @@ async fn wmctrl_try_raise_window(title: &str) -> anyhow::Result<ExitStatus> {
|
||||
.await?;
|
||||
|
||||
Ok(exit_status)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user