refactor: upgrade tauri 2.0

This commit is contained in:
Kevin Yue
2024-12-26 21:35:55 +08:00
parent 0f67be465b
commit 8f8ad466f4
73 changed files with 7232 additions and 5026 deletions

View File

@@ -2,25 +2,20 @@ use std::{process::ExitStatus, time::Duration};
use anyhow::bail;
use log::info;
use tauri::Window;
use tauri::WebviewWindow;
use tokio::process::Command;
pub trait WindowExt {
fn raise(&self) -> anyhow::Result<()>;
fn hide_menu(&self);
}
impl WindowExt for Window {
impl WindowExt for WebviewWindow {
fn raise(&self) -> anyhow::Result<()> {
raise_window(self)
}
fn hide_menu(&self) {
hide_menu(self);
}
}
pub fn raise_window(win: &Window) -> anyhow::Result<()> {
pub fn raise_window(win: &WebviewWindow) -> anyhow::Result<()> {
let is_wayland = std::env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland";
if is_wayland {
@@ -40,7 +35,7 @@ pub fn raise_window(win: &Window) -> anyhow::Result<()> {
// Calling window.show() on Windows will cause the menu to be shown.
// We need to hide it again.
hide_menu(win);
win.hide_menu()?;
Ok(())
}
@@ -76,22 +71,3 @@ async fn wmctrl_try_raise_window(title: &str) -> anyhow::Result<ExitStatus> {
Ok(exit_status)
}
fn hide_menu(win: &Window) {
let menu_handle = win.menu_handle();
tokio::spawn(async move {
loop {
let menu_visible = menu_handle.is_visible().unwrap_or(false);
if !menu_visible {
break;
}
if menu_visible {
let _ = menu_handle.hide();
tokio::time::sleep(Duration::from_millis(10)).await;
}
}
});
}