From b4321dc51088f808fc0eee3ea094d30f3b895204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Youn=20M=C3=A9lois?= Date: Sat, 9 Nov 2024 13:31:37 +0100 Subject: [PATCH] fix: exclude theme plugin from mobile build --- src-tauri/Cargo.toml | 5 +- src-tauri/capabilities/default.json | 3 +- src-tauri/src/lib.rs | 73 +++++++++++++++++------------ 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 698682c..5f5dc07 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -31,6 +31,9 @@ tar = "0.4.43" tauri = { version = "2.0.6", features = ["protocol-asset"] } tauri-plugin-log = "2.0.2" tauri-plugin-store = "2.1.0" -tauri-plugin-theme = "2.1.2" tauri-plugin-http = "2.0.3" tokio = { version = "1.41.1", features = ["full"] } + +# Dependencies for mobile targets +[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] +tauri-plugin-theme = "2.1.2" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index c73b8ae..ad2e058 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -8,7 +8,6 @@ "permissions": [ "core:default", "store:default", - "log:default", - "theme:default" + "log:default" ] } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c812c65..d92f50a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -187,8 +187,12 @@ async fn get_page_list( #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { let mut ctx = tauri::generate_context!(); - tauri::Builder::default() - .plugin(tauri_plugin_theme::init(ctx.config_mut())) + let builder = tauri::Builder::default(); + + // Register the plugins + #[cfg(not(any(target_os = "android", target_os = "ios")))] + let builder = builder.plugin(tauri_plugin_theme::init(ctx.config_mut())); + let builder = builder .plugin(tauri_plugin_http::init()) .plugin( tauri_plugin_log::Builder::default() @@ -203,35 +207,42 @@ pub fn run() { .targets([Target::new(TargetKind::Stdout)]) .build(), ) - .plugin(tauri_plugin_store::Builder::default().build()) - .setup(|app| { - let app_local_data_dir: PathBuf = app - .path() - .app_local_data_dir() - .expect("failed to get local app data dir"); - - let extensions_dir = app_local_data_dir.join(EXTENSIONS_DIR); - std::fs::create_dir_all(&extensions_dir).expect("failed to create extensions dir"); - - // Load the extensions. - let extensions = Extensions::from_dir(extensions_dir); - app.manage(extensions); - - // Load the store. - let _store = app.store(STORE_FILE)?; - - Ok(()) - }) - .invoke_handler(tauri::generate_handler![ - get_extensions, - get_repository_extensions, - install_extension, - uninstall_extension, - get_manga_list, - get_manga_details, - get_chapter_list, - get_page_list - ]) + .plugin(tauri_plugin_store::Builder::default().build()); + + // Setup the app + let builder = builder.setup(|app| { + let app_local_data_dir: PathBuf = app + .path() + .app_local_data_dir() + .expect("failed to get local app data dir"); + + let extensions_dir = app_local_data_dir.join(EXTENSIONS_DIR); + std::fs::create_dir_all(&extensions_dir).expect("failed to create extensions dir"); + + // Load the extensions. + let extensions = Extensions::from_dir(extensions_dir); + app.manage(extensions); + + // Load the store. + let _store = app.store(STORE_FILE)?; + + Ok(()) + }); + + // Register the commands + let builder = builder.invoke_handler(tauri::generate_handler![ + get_extensions, + get_repository_extensions, + install_extension, + uninstall_extension, + get_manga_list, + get_manga_details, + get_chapter_list, + get_page_list + ]); + + // Run the application + builder .run(ctx) .expect("error while running tauri application"); }