屏蔽Mac端托盘相关代码
This commit is contained in:
36
src-tauri/Cargo.lock
generated
36
src-tauri/Cargo.lock
generated
@@ -1422,46 +1422,12 @@ version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
|
||||
|
||||
[[package]]
|
||||
name = "libappindicator"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db2d3cb96d092b4824cb306c9e544c856a4cb6210c1081945187f7f1924b47e8"
|
||||
dependencies = [
|
||||
"glib",
|
||||
"gtk",
|
||||
"gtk-sys",
|
||||
"libappindicator-sys",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libappindicator-sys"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1b3b6681973cea8cc3bce7391e6d7d5502720b80a581c9a95c9cbaf592826aa"
|
||||
dependencies = [
|
||||
"gtk-sys",
|
||||
"libloading",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "line-wrap"
|
||||
version = "0.1.1"
|
||||
@@ -2593,7 +2559,6 @@ dependencies = [
|
||||
"core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-graphics 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crossbeam-channel",
|
||||
"dirs-next",
|
||||
"dispatch",
|
||||
"gdk",
|
||||
"gdk-pixbuf",
|
||||
@@ -2607,7 +2572,6 @@ dependencies = [
|
||||
"instant",
|
||||
"jni",
|
||||
"lazy_static",
|
||||
"libappindicator",
|
||||
"libc",
|
||||
"log",
|
||||
"ndk",
|
||||
|
||||
@@ -17,7 +17,7 @@ tauri-build = { version = "1.2.1", features = [] }
|
||||
[dependencies]
|
||||
serde_json = "1.0.89"
|
||||
serde = { version = "1.0.150", features = ["derive"] }
|
||||
tauri = { version = "1.2.3", features = ["system-tray"] }
|
||||
tauri = { version = "1.2.3", features = [] }
|
||||
image = "0.24.5"
|
||||
home = "0.5"
|
||||
tauri-utils = "1.2.1"
|
||||
|
||||
@@ -5,9 +5,12 @@ use tauri::MenuItem;
|
||||
#[macro_use]
|
||||
extern crate objc;
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
use tauri::{Manager, SystemTray, SystemTrayEvent, SystemTrayMenu};
|
||||
|
||||
use tauri::{
|
||||
window::PlatformWebview, App, Config, CustomMenuItem, Manager, Menu, Submenu, SystemTray,
|
||||
SystemTrayEvent, SystemTrayMenu, Window, WindowBuilder, WindowMenuEvent, WindowUrl,
|
||||
window::PlatformWebview, App, Config, CustomMenuItem, Menu, Submenu, Window, WindowBuilder,
|
||||
WindowMenuEvent, WindowUrl,
|
||||
};
|
||||
mod pake;
|
||||
use pake::PakeConfig;
|
||||
@@ -149,6 +152,7 @@ pub fn get_pake_config() -> (PakeConfig, Config) {
|
||||
(pake_config, tauri_config)
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
pub fn get_system_tray(show_menu: bool) -> SystemTray {
|
||||
let hide_app = CustomMenuItem::new("hide_app".to_string(), "Hide App");
|
||||
let show_app = CustomMenuItem::new("show_app".to_string(), "Show App");
|
||||
@@ -169,6 +173,7 @@ pub fn get_system_tray(show_menu: bool) -> SystemTray {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
pub fn system_tray_handle(app: &tauri::AppHandle, event: tauri::SystemTrayEvent) {
|
||||
if let SystemTrayEvent::MenuItemClick { tray_id: _, id, .. } = event {
|
||||
match id.as_str() {
|
||||
@@ -251,7 +256,7 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: std::path::PathB
|
||||
.fullscreen(window_config.fullscreen)
|
||||
// .transparent(window_config.transparent)
|
||||
//用于隐藏头部
|
||||
.title_bar_style(tauri_utils::TitleBarStyle::Overlay)
|
||||
// .title_bar_style(tauri_utils::TitleBarStyle::Overlay)
|
||||
.inner_size(window_config.width, window_config.height)
|
||||
.initialization_script(include_str!("pake.js"));
|
||||
|
||||
|
||||
@@ -3,35 +3,46 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use app::{
|
||||
get_data_dir, get_menu, get_pake_config, get_system_tray, get_window, menu_event_handle,
|
||||
system_tray_handle,
|
||||
};
|
||||
use app::{get_data_dir, get_menu, get_pake_config, get_window, menu_event_handle};
|
||||
|
||||
pub fn run_app() {
|
||||
let (pake_config, tauri_config) = get_pake_config();
|
||||
let show_menu = pake_config.show_menu();
|
||||
let show_system_tray = pake_config.show_system_tray();
|
||||
let system_tray = get_system_tray(show_menu);
|
||||
let data_dir = get_data_dir(tauri_config);
|
||||
let menu = get_menu();
|
||||
let tauri_app = if show_menu && !show_system_tray {
|
||||
let data_dir = get_data_dir(tauri_config);
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
let tauri_app = {
|
||||
use app::{get_system_tray, system_tray_handle};
|
||||
|
||||
let show_system_tray = pake_config.show_system_tray();
|
||||
let system_tray = get_system_tray(show_menu);
|
||||
let tauri_app = if show_menu && !show_system_tray {
|
||||
tauri::Builder::default()
|
||||
.menu(menu)
|
||||
.on_menu_event(menu_event_handle)
|
||||
} else if !show_menu && show_system_tray {
|
||||
tauri::Builder::default()
|
||||
.system_tray(system_tray)
|
||||
.on_system_tray_event(system_tray_handle)
|
||||
} else if show_menu && show_system_tray {
|
||||
tauri::Builder::default()
|
||||
.menu(menu)
|
||||
.on_menu_event(menu_event_handle)
|
||||
.system_tray(system_tray)
|
||||
.on_system_tray_event(system_tray_handle)
|
||||
} else {
|
||||
tauri::Builder::default()
|
||||
};
|
||||
};
|
||||
#[cfg(target_os = "macos")]
|
||||
let tauri_app = if show_menu {
|
||||
tauri::Builder::default()
|
||||
.menu(menu)
|
||||
.on_menu_event(menu_event_handle)
|
||||
} else if !show_menu && show_system_tray {
|
||||
tauri::Builder::default()
|
||||
.system_tray(system_tray)
|
||||
.on_system_tray_event(system_tray_handle)
|
||||
} else if show_menu && show_system_tray {
|
||||
tauri::Builder::default()
|
||||
.menu(menu)
|
||||
.on_menu_event(menu_event_handle)
|
||||
.system_tray(system_tray)
|
||||
.on_system_tray_event(system_tray_handle)
|
||||
} else {
|
||||
tauri::Builder::default()
|
||||
};
|
||||
|
||||
tauri_app
|
||||
.plugin(tauri_plugin_window_state::Builder::default().build())
|
||||
.invoke_handler(tauri::generate_handler![])
|
||||
|
||||
Reference in New Issue
Block a user