From 4ba842f18bdceb3aceccefc7d1bb71b1b403e065 Mon Sep 17 00:00:00 2001 From: Medcl Date: Tue, 18 Feb 2025 08:26:52 +0800 Subject: [PATCH] chore: fix build for linux (#143) * chore: fix build for linux * chore: fix build for linux --- src-tauri/Cargo.toml | 6 +++--- src-tauri/src/lib.rs | 19 ++++++++++++------- src-tauri/src/setup/mod.rs | 8 +++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c8b2bd9a..2a0572f9 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -36,9 +36,6 @@ tauri-plugin-updater = "2" tauri-plugin-process = "2" tauri-plugin-drag = "2" -[target."cfg(target_os = \"macos\")".dependencies] -tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" } - reqwest = "0.12.12" futures = "0.3.31" ordered-float = { version = "4.6.0", default-features = false } @@ -56,6 +53,9 @@ base64 = "0.13" walkdir = "2" fuzzy_prefix_search = "0.2" +[target."cfg(target_os = \"macos\")".dependencies] +tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" } + [profile.dev] incremental = true # Compile your binary in smaller steps. diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ccf062bf..3b0632d4 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -18,10 +18,7 @@ use reqwest::Client; use std::path::PathBuf; #[cfg(target_os = "macos")] use tauri::ActivationPolicy; -use tauri::{ - AppHandle, Emitter, Listener, Manager, PhysicalPosition, Runtime, WebviewWindow, Window, - WindowEvent, -}; +use tauri::{AppHandle, Emitter, Listener, Manager, PhysicalPosition, Runtime, State, WebviewWindow, Window, WindowEvent}; use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_deep_link::DeepLinkExt; use tokio::runtime::Runtime as RT; @@ -53,8 +50,8 @@ struct Payload { pub fn run() { let mut ctx = tauri::generate_context!(); - let app = tauri::Builder::default() - .plugin(tauri_nspanel::init()) + let mut app_builder = tauri::Builder::default() + // .plugin(tauri_nspanel::init()) .plugin(tauri_plugin_http::init()) .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_autostart::init( @@ -68,6 +65,14 @@ pub fn run() { .unwrap(); })) .plugin(tauri_plugin_store::Builder::default().build()) + + // Conditional compilation for macOS + #[cfg(target_os = "macos")] + { + app_builder = app_builder.plugin(tauri_nspanel::init()); + } + + let app = app_builder .invoke_handler(tauri::generate_handler![ change_window_height, shortcut::change_shortcut, @@ -182,7 +187,7 @@ pub async fn init(app_handle: &AppHandle) { let coco_servers = server::servers::get_all_servers(); // Get the registry from Tauri's state - let registry = app_handle.state::(); + let registry:State = app_handle.state::(); for server in coco_servers { let source = CocoSearchSource::new(server.clone(), Client::new()); diff --git a/src-tauri/src/setup/mod.rs b/src-tauri/src/setup/mod.rs index 3aada309..5b8bb54b 100644 --- a/src-tauri/src/setup/mod.rs +++ b/src-tauri/src/setup/mod.rs @@ -3,19 +3,17 @@ use tauri::{App, WebviewWindow}; #[cfg(target_os = "macos")] mod mac; -#[cfg(target_os = "windows")] -mod win; - #[cfg(target_os = "linux")] mod linux; -mod linux; + +#[cfg(target_os = "windows")] mod windows; #[cfg(target_os = "macos")] pub use mac::*; #[cfg(target_os = "windows")] -pub use win::*; +pub use windows::*; #[cfg(target_os = "linux")] pub use linux::*;