diff --git a/app/tauri/src/lib.rs b/app/tauri/src/lib.rs index 23549d70..b9989f07 100644 --- a/app/tauri/src/lib.rs +++ b/app/tauri/src/lib.rs @@ -1,13 +1,17 @@ -#[cfg(debug_assertions)] -use tauri::Manager; -use tauri::RunEvent; +#![cfg_attr( +all(not(debug_assertions), target_os = "windows"), +windows_subsystem = "windows" +)] + +#[cfg(desktop)] +use tauri::{Manager}; +use tauri::{RunEvent}; #[cfg(desktop)] use tauri_plugin_autostart::MacosLauncher; #[cfg(desktop)] +use tauri_plugin_updater::Builder; use tauri_plugin_window; -use tauri_plugin_shell; - #[cfg(desktop)] mod desktop; @@ -16,48 +20,75 @@ use desktop::{ commands::PomatezCommands, global_shortcuts::{PomatezGlobalShortcutsRegister, PomatezGlobalShortcutsSetup}, system_tray::PomatezTray, - updater, }; +#[cfg(target_os = "macos")] +use crate::commands::try_set_native_titlebar; + #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { - let builder = tauri::Builder::default(); + let mut context = tauri::generate_context!(); #[cfg(desktop)] - let builder = builder - .plugin(tauri_plugin_autostart::init( + let config = context.config_mut(); + + let app = tauri::Builder::default(); + + #[cfg(desktop)] + let app = app.plugin(tauri_plugin_autostart::init( MacosLauncher::LaunchAgent, None, - )) - .plugin(tauri_plugin_window::init()) - .plugin(tauri_plugin_notification::init()) - .plugin(tauri_plugin_updater::Builder::new().build()); + )); - let builder = builder.plugin(tauri_plugin_shell::init()); + let app = app.plugin(tauri_plugin_window::init()) + .plugin(tauri_plugin_shell::init()) + .plugin(tauri_plugin_notification::init()); #[cfg(desktop)] - let builder = builder.register_pomatez_commands(); + let mut app = app; #[cfg(desktop)] - let builder = builder.setup(|app| { - app.setup_global_shortcuts(); - app.set_pomatez_system_tray(); + if config.tauri.bundle.updater.active { + app = app.plugin(Builder::new().build()); + } - Ok(()) - }); + #[cfg(desktop)] + let app = app.register_pomatez_commands(); + + #[allow(unused_variables)] + let app = app.setup(|app| { + #[cfg(desktop)] + { + app.setup_global_shortcuts(); + app.set_pomatez_system_tray(); + } - let app = builder - .build(tauri::generate_context!()) + Ok(()) + }); + + let app = app.build(context) .expect("error while running tauri application"); #[allow(unused_variables)] app.run(|app_handle, e| match e { RunEvent::Ready => { #[cfg(desktop)] - app_handle.register_global_shortcuts(); + { + app_handle.register_global_shortcuts(); + + let window = app_handle.get_window("main").unwrap(); + + // There is a bug on mac where the size is not properly respected initially, though this seems to fix it. + #[cfg(target_os = "macos")] + { + try_set_native_titlebar(false, &window); + try_set_native_titlebar(true, &window); + } + + #[cfg(debug_assertions)] + window.open_devtools(); + } - #[cfg(debug_assertions)] - app_handle.get_window("main").unwrap().open_devtools(); println!("Pomatez is ready"); } diff --git a/app/tauri/src/main.rs b/app/tauri/src/main.rs index 14eb49d6..a58c3a46 100644 --- a/app/tauri/src/main.rs +++ b/app/tauri/src/main.rs @@ -1,79 +1,8 @@ #![cfg_attr( - all(not(debug_assertions), target_os = "windows"), - windows_subsystem = "windows" +all(not(debug_assertions), target_os = "windows"), +windows_subsystem = "windows" )] -use tauri::{Manager}; -use tauri::{RunEvent}; -use tauri_plugin_autostart::MacosLauncher; -use tauri_plugin_window; - -#[macro_use] -mod commands; -mod global_shortcuts; -mod system_tray; -mod updater; - -#[cfg(target_os = "macos")] -use crate::commands::try_set_native_titlebar; - -use commands::PomatezCommands; -use global_shortcuts::{PomatezGlobalShortcutsRegister, PomatezGlobalShortcutsSetup}; -use system_tray::PomatezTray; - fn main() { - let mut context = tauri::generate_context!(); - - let config = context.config_mut(); - - let mut app = tauri::Builder::default() - .plugin(tauri_plugin_autostart::init( - MacosLauncher::LaunchAgent, - None, - )) - .plugin(tauri_plugin_window::init()) - .plugin(tauri_plugin_shell::init()) - .plugin(tauri_plugin_notification::init()); - - - - if config.tauri.bundle.updater.active { - app = app.plugin(tauri_plugin_updater::Builder::new().build()); - } - - let app = app - .register_pomatez_commands() - .setup(|app| { - #[cfg(desktop)] - { - app.setup_global_shortcuts(); - app.set_pomatez_system_tray(); - } - - Ok(()) - }) - .build(context) - .expect("error while running tauri application"); - - #[cfg(desktop)] - app.run(|app_handle, e| match e { - RunEvent::Ready => { - app_handle.register_global_shortcuts(); - - let window = app_handle.get_window("main").unwrap(); - - // There is a bug on mac where the size is not properly respected initially, though this seems to fix it. - #[cfg(target_os = "macos")] - { - try_set_native_titlebar(false, &window); - try_set_native_titlebar(true, &window); - } - - #[cfg(debug_assertions)] - window.open_devtools(); - - println!("Pomatez is ready"); - } - _ => {} - }); -} + pomatez_lib::run() +} \ No newline at end of file diff --git a/package.json b/package.json index 9c036839..9a5792d9 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,13 @@ "tauri": "tauri", "tauri:dev": "tauri dev", "tauri:dev-with-updater": "tauri dev --config ./app/tauri/release.conf.json", - "tauri:updateversion": "node ./app/tauri/util/cargo-version-updater.js" + "tauri:updateversion": "node ./app/tauri/util/cargo-version-updater.js", + "tauri:android:dev": "tauri android dev", + "tauri:android:open": "tauri android open", + "tauri:android:build": "tauri android build", + "tauri:ios:dev": "tauri ios dev", + "tauri:ios:open": "tauri ios open", + "tauri:ios:build": "tauri ios build" }, "config": { "commitizen": {