From 296a844aaacbc0f644f4de3f8052d7f02ae9964e Mon Sep 17 00:00:00 2001 From: pandadev <70103896+0PandaDEV@users.noreply.github.com> Date: Fri, 5 Jul 2024 01:54:39 +0200 Subject: [PATCH] much cleaner file structure --- src-tauri/Cargo.lock | 40 ++++++++++++++++----------------- src-tauri/Cargo.toml | 14 +++--------- src-tauri/src/lib.rs | 50 ----------------------------------------- src-tauri/src/main.rs | 52 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 72 insertions(+), 84 deletions(-) delete mode 100644 src-tauri/src/lib.rs diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 8395e99..0c829f8 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -81,26 +81,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "app" -version = "0.1.0" -dependencies = [ - "rand 0.8.5", - "rdev", - "serde", - "serde_json", - "sqlx", - "tauri", - "tauri-build", - "tauri-plugin-autostart", - "tauri-plugin-clipboard-manager", - "tauri-plugin-global-shortcut", - "tauri-plugin-os", - "tauri-plugin-sql", - "tauri-plugin-window-state", - "tokio", -] - [[package]] name = "arboard" version = "3.4.0" @@ -419,6 +399,26 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "clipboard-manager" +version = "0.1.0" +dependencies = [ + "rand 0.8.5", + "rdev", + "serde", + "serde_json", + "sqlx", + "tauri", + "tauri-build", + "tauri-plugin-autostart", + "tauri-plugin-clipboard-manager", + "tauri-plugin-global-shortcut", + "tauri-plugin-os", + "tauri-plugin-sql", + "tauri-plugin-window-state", + "tokio", +] + [[package]] name = "clipboard-win" version = "5.3.1" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 3c48ff3..e60b116 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,19 +1,11 @@ [package] -name = "app" +name = "clipboard-manager" version = "0.1.0" -description = "A Tauri App" -authors = ["you"] -license = "" -repository = "" +description = "Clipboard manager" +authors = ["pandadev"] edition = "2021" rust-version = "1.70" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[lib] -name = "app_lib" -crate-type = ["staticlib", "cdylib", "rlib"] - [build-dependencies] tauri-build = { version = "2.0.0-beta.18", features = [] } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs deleted file mode 100644 index c1473b6..0000000 --- a/src-tauri/src/lib.rs +++ /dev/null @@ -1,50 +0,0 @@ -mod clipboard_listener; -mod database; -mod global_shortcut; -mod tray; - -use tauri::Manager; -use tauri_plugin_autostart::MacosLauncher; -use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt}; - -#[cfg_attr(mobile, tauri::mobile_entry_point)] -pub fn run() { - tauri::Builder::default() - .plugin(tauri_plugin_os::init()) - .plugin(tauri_plugin_autostart::init( - MacosLauncher::LaunchAgent, - Some(vec![]), - )) - .plugin(tauri_plugin_global_shortcut::Builder::new().build()) - .plugin(tauri_plugin_clipboard_manager::init()) - .plugin(tauri_plugin_window_state::Builder::default().build()) - .plugin(tauri_plugin_sql::Builder::default().build()) - .setup(|app| { - let app_handle = app.handle().clone(); - - global_shortcut::setup(app_handle.clone()); - tray::setup(app)?; - database::setup(app)?; - clipboard_listener::setup(app_handle); - - if let Some(window) = app.get_window("main") { - let _ = window.restore_state(StateFlags::POSITION); - window.show().unwrap(); - } - - Ok(()) - }) - .on_window_event(|app, event| match event { - tauri::WindowEvent::CloseRequested { .. } - | tauri::WindowEvent::Destroyed - | tauri::WindowEvent::Focused(false) => { - let _ = AppHandleExt::save_window_state(app.app_handle(), StateFlags::POSITION); - } - _ => {} - }) - .invoke_handler(tauri::generate_handler![ - clipboard_listener::simulate_paste - ]) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); -} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 69c3a72..77965df 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,6 +1,52 @@ -// Prevents additional console window on Windows in release, DO NOT REMOVE!! -#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +#![cfg_attr( + all(not(debug_assertions), target_os = "windows"), + windows_subsystem = "windows" +)] + +mod clipboard_listener; +mod database; +mod global_shortcut; +mod tray; + +use tauri::Manager; +use tauri_plugin_autostart::MacosLauncher; +use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt}; fn main() { - app_lib::run(); + tauri::Builder::default() + .plugin(tauri_plugin_os::init()) + .plugin(tauri_plugin_autostart::init( + MacosLauncher::LaunchAgent, + Some(vec![]), + )) + .plugin(tauri_plugin_global_shortcut::Builder::new().build()) + .plugin(tauri_plugin_clipboard_manager::init()) + .plugin(tauri_plugin_window_state::Builder::default().build()) + .plugin(tauri_plugin_sql::Builder::default().build()) + .setup(|app| { + let app_handle = app.handle().clone(); + + global_shortcut::setup(app_handle.clone()); + tray::setup(app)?; + database::setup(app)?; + clipboard_listener::setup(app_handle); + + if let Some(window) = app.get_window("main") { + let _ = window.restore_state(StateFlags::POSITION); + window.show().unwrap(); + } + + Ok(()) + }) + .on_window_event(|app, event| match event { + tauri::WindowEvent::CloseRequested { .. } + | tauri::WindowEvent::Destroyed + | tauri::WindowEvent::Focused(false) => { + let _ = AppHandleExt::save_window_state(app.app_handle(), StateFlags::POSITION); + } + _ => {} + }) + .invoke_handler(tauri::generate_handler![clipboard_listener::simulate_paste]) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); }