diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index 8d3a5f68c..7f9ad1f73 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -54,7 +54,7 @@ cfg_aliases = "0.1.1" [dev-dependencies] proptest = "1.0.0" serde_json = "1.0" -tauri = { path = ".", features = [ "api-all" ] } +tauri = { path = "." } serde = { version = "1.0", features = [ "derive" ] } quickcheck = "1.0.3" quickcheck_macros = "1.0.0" diff --git a/core/tauri/src/endpoints/dialog.rs b/core/tauri/src/endpoints/dialog.rs index 617422cfb..ca72a70e9 100644 --- a/core/tauri/src/endpoints/dialog.rs +++ b/core/tauri/src/endpoints/dialog.rs @@ -10,6 +10,7 @@ use serde::Deserialize; use std::path::PathBuf; +#[allow(dead_code)] #[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct DialogFilter { @@ -69,18 +70,16 @@ pub enum Cmd { impl Cmd { pub fn run(self) -> crate::Result { match self { - Self::OpenDialog { options } => { - #[cfg(dialog_open)] - return open(options); - #[cfg(not(dialog_open))] - return Err(crate::Error::ApiNotAllowlisted("dialog > open".to_string())); - } - Self::SaveDialog { options } => { - #[cfg(dialog_save)] - return save(options); - #[cfg(not(dialog_save))] - return Err(crate::Error::ApiNotAllowlisted("dialog > save".to_string())); - } + #[cfg(dialog_open)] + Self::OpenDialog { options } => open(options), + #[cfg(not(dialog_open))] + Self::OpenDialog { .. } => Err(crate::Error::ApiNotAllowlisted("dialog > open".to_string())), + + #[cfg(dialog_save)] + Self::SaveDialog { options } => save(options), + #[cfg(not(dialog_save))] + Self::SaveDialog { .. } => Err(crate::Error::ApiNotAllowlisted("dialog > save".to_string())), + Self::MessageDialog { message } => { let exe = std::env::current_exe()?; let app_name = exe diff --git a/core/tauri/src/endpoints/file_system.rs b/core/tauri/src/endpoints/file_system.rs index 319aed65d..9b540abf5 100644 --- a/core/tauri/src/endpoints/file_system.rs +++ b/core/tauri/src/endpoints/file_system.rs @@ -98,104 +98,94 @@ pub enum Cmd { impl Cmd { pub fn run(self) -> crate::Result { match self { - Self::ReadTextFile { path, options } => { - #[cfg(fs_read_text_file)] - return read_text_file(path, options).map(Into::into); - #[cfg(not(fs_read_text_file))] - Err(crate::Error::ApiNotAllowlisted( - "fs > readTextFile".to_string(), - )) - } - Self::ReadBinaryFile { path, options } => { - #[cfg(fs_read_binary_file)] - return read_binary_file(path, options).map(Into::into); - #[cfg(not(fs_read_binary_file))] - Err(crate::Error::ApiNotAllowlisted( - "readBinaryFile".to_string(), - )) - } + #[cfg(fs_read_text_file)] + Self::ReadTextFile { path, options } => read_text_file(path, options).map(Into::into), + #[cfg(not(fs_read_text_file))] + Self::ReadTextFile { .. } => Err(crate::Error::ApiNotAllowlisted( + "fs > readTextFile".to_string(), + )), + + #[cfg(fs_read_binary_file)] + Self::ReadBinaryFile { path, options } => read_binary_file(path, options).map(Into::into), + #[cfg(not(fs_read_binary_file))] + Self::ReadBinaryFile { .. } => Err(crate::Error::ApiNotAllowlisted( + "readBinaryFile".to_string(), + )), + + #[cfg(fs_write_file)] Self::WriteFile { path, contents, options, - } => { - #[cfg(fs_write_file)] - return write_file(path, contents, options).map(Into::into); - #[cfg(not(fs_write_file))] - Err(crate::Error::ApiNotAllowlisted( - "fs > writeFile".to_string(), - )) - } + } => write_file(path, contents, options).map(Into::into), + #[cfg(not(fs_write_file))] + Self::WriteFile { .. } => Err(crate::Error::ApiNotAllowlisted( + "fs > writeFile".to_string(), + )), + + #[cfg(fs_write_binary_file)] Self::WriteBinaryFile { path, contents, options, - } => { - #[cfg(fs_write_binary_file)] - return write_binary_file(path, contents, options).map(Into::into); - #[cfg(not(fs_write_binary_file))] - Err(crate::Error::ApiNotAllowlisted( - "writeBinaryFile".to_string(), - )) - } - Self::ReadDir { path, options } => { - #[cfg(fs_read_dir)] - return read_dir(path, options).map(Into::into); - #[cfg(not(fs_read_dir))] - Err(crate::Error::ApiNotAllowlisted("fs > readDir".to_string())) - } + } => write_binary_file(path, contents, options).map(Into::into), + #[cfg(not(fs_write_binary_file))] + Self::WriteBinaryFile { .. } => Err(crate::Error::ApiNotAllowlisted( + "writeBinaryFile".to_string(), + )), + + #[cfg(fs_read_dir)] + Self::ReadDir { path, options } => read_dir(path, options).map(Into::into), + #[cfg(not(fs_read_dir))] + Self::ReadDir { .. } => Err(crate::Error::ApiNotAllowlisted("fs > readDir".to_string())), + + #[cfg(fs_copy_file)] Self::CopyFile { source, destination, options, - } => { - #[cfg(fs_copy_file)] - return copy_file(source, destination, options).map(Into::into); - #[cfg(not(fs_copy_file))] - Err(crate::Error::ApiNotAllowlisted("fs > copyFile".to_string())) - } - Self::CreateDir { path, options } => { - #[cfg(fs_create_dir)] - return create_dir(path, options).map(Into::into); - #[cfg(not(fs_create_dir))] - Err(crate::Error::ApiNotAllowlisted( - "fs > createDir".to_string(), - )) - } - Self::RemoveDir { path, options } => { - #[cfg(fs_remove_dir)] - return remove_dir(path, options).map(Into::into); - #[cfg(not(fs_remove_dir))] - Err(crate::Error::ApiNotAllowlisted( - "fs > removeDir".to_string(), - )) - } - Self::RemoveFile { path, options } => { - #[cfg(fs_remove_file)] - return remove_file(path, options).map(Into::into); - #[cfg(not(fs_remove_file))] - Err(crate::Error::ApiNotAllowlisted( - "fs > removeFile".to_string(), - )) - } + } => copy_file(source, destination, options).map(Into::into), + #[cfg(not(fs_copy_file))] + Self::CopyFile { .. } => Err(crate::Error::ApiNotAllowlisted("fs > copyFile".to_string())), + + #[cfg(fs_create_dir)] + Self::CreateDir { path, options } => create_dir(path, options).map(Into::into), + #[cfg(not(fs_create_dir))] + Self::CreateDir { .. } => Err(crate::Error::ApiNotAllowlisted( + "fs > createDir".to_string(), + )), + + #[cfg(fs_remove_dir)] + Self::RemoveDir { path, options } => remove_dir(path, options).map(Into::into), + #[cfg(not(fs_remove_dir))] + Self::RemoveDir { .. } => Err(crate::Error::ApiNotAllowlisted( + "fs > removeDir".to_string(), + )), + + #[cfg(fs_remove_file)] + Self::RemoveFile { path, options } => remove_file(path, options).map(Into::into), + #[cfg(not(fs_remove_file))] + Self::RemoveFile { .. } => Err(crate::Error::ApiNotAllowlisted( + "fs > removeFile".to_string(), + )), + + #[cfg(fs_rename_file)] Self::RenameFile { old_path, new_path, options, - } => { - #[cfg(fs_rename_file)] - return rename_file(old_path, new_path, options).map(Into::into); - #[cfg(not(fs_rename_file))] - Err(crate::Error::ApiNotAllowlisted( - "fs > renameFile".to_string(), - )) - } + } => rename_file(old_path, new_path, options).map(Into::into), + #[cfg(not(fs_rename_file))] + Self::RenameFile { .. } => Err(crate::Error::ApiNotAllowlisted( + "fs > renameFile".to_string(), + )), + + #[cfg(fs_path)] Self::ResolvePath { path, directory } => { - #[cfg(fs_path)] - return resolve_path_handler(path, directory).map(Into::into); - #[cfg(not(fs_path))] - Err(crate::Error::ApiNotAllowlisted("fs > pathApi".to_string())) + resolve_path_handler(path, directory).map(Into::into) } + #[cfg(not(fs_path))] + Self::ResolvePath { .. } => Err(crate::Error::ApiNotAllowlisted("fs > pathApi".to_string())), } } } diff --git a/core/tauri/src/endpoints/global_shortcut.rs b/core/tauri/src/endpoints/global_shortcut.rs index 22909d5be..0f309b1bf 100644 --- a/core/tauri/src/endpoints/global_shortcut.rs +++ b/core/tauri/src/endpoints/global_shortcut.rs @@ -3,19 +3,18 @@ // SPDX-License-Identifier: MIT use super::InvokeResponse; -use crate::{runtime::Dispatch, Params, Window}; -use once_cell::sync::Lazy; +use crate::{Params, Window}; use serde::Deserialize; -use std::sync::{Arc, Mutex}; #[cfg(global_shortcut_all)] -use crate::api::shortcuts::ShortcutManager; +use crate::{api::shortcuts::ShortcutManager, runtime::Dispatch}; #[cfg(global_shortcut_all)] -type ShortcutManagerHandle = Arc>; +type ShortcutManagerHandle = std::sync::Arc>; #[cfg(global_shortcut_all)] pub fn manager_handle() -> &'static ShortcutManagerHandle { + use once_cell::sync::Lazy; static MANAGER: Lazy = Lazy::new(Default::default); &MANAGER } diff --git a/core/tauri/src/endpoints/http.rs b/core/tauri/src/endpoints/http.rs index a8aae5f03..84abe17ef 100644 --- a/core/tauri/src/endpoints/http.rs +++ b/core/tauri/src/endpoints/http.rs @@ -4,7 +4,7 @@ use super::InvokeResponse; -use crate::api::http::{Client, ClientBuilder, HttpRequestBuilder, ResponseData}; +use crate::api::http::{Client, ClientBuilder, HttpRequestBuilder}; use once_cell::sync::Lazy; use serde::Deserialize; @@ -51,14 +51,14 @@ impl Cmd { store.remove(&client); Ok(().into()) } + #[cfg(http_request)] Self::HttpRequest { client, options } => { - #[cfg(http_request)] return make_request(client, *options).await.map(Into::into); - #[cfg(not(http_request))] - Err(crate::Error::ApiNotAllowlisted( - "http > request".to_string(), - )) } + #[cfg(not(http_request))] + Self::HttpRequest { .. } => Err(crate::Error::ApiNotAllowlisted( + "http > request".to_string(), + )), } } } @@ -68,7 +68,7 @@ impl Cmd { pub async fn make_request( client_id: ClientId, options: HttpRequestBuilder, -) -> crate::Result { +) -> crate::Result { let client = clients() .lock() .unwrap() diff --git a/core/tauri/src/endpoints/notification.rs b/core/tauri/src/endpoints/notification.rs index 333a7b387..819a07d90 100644 --- a/core/tauri/src/endpoints/notification.rs +++ b/core/tauri/src/endpoints/notification.rs @@ -32,14 +32,13 @@ pub enum Cmd { } impl Cmd { + #[allow(unused_variables)] pub fn run(self, identifier: String) -> crate::Result { match self { - Self::Notification { options } => { - #[cfg(notification_all)] - return send(options, identifier).map(Into::into); - #[cfg(not(notification_all))] - Err(crate::Error::ApiNotAllowlisted("notification".to_string())) - } + #[cfg(notification_all)] + Self::Notification { options } => send(options, identifier).map(Into::into), + #[cfg(not(notification_all))] + Self::Notification { .. } => Err(crate::Error::ApiNotAllowlisted("notification".to_string())), Self::IsNotificationPermissionGranted => { #[cfg(notification_all)] return is_permission_granted().map(Into::into); diff --git a/core/tauri/src/endpoints/shell.rs b/core/tauri/src/endpoints/shell.rs index 2ca808559..0365e2e3e 100644 --- a/core/tauri/src/endpoints/shell.rs +++ b/core/tauri/src/endpoints/shell.rs @@ -2,25 +2,22 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use crate::{ - api::{ - command::{Command, CommandChild, CommandEvent}, - rpc::format_callback, - }, - endpoints::InvokeResponse, - Params, Window, -}; -use once_cell::sync::Lazy; +use crate::{endpoints::InvokeResponse, Params, Window}; use serde::Deserialize; + +#[cfg(shell_execute)] use std::{ collections::HashMap, sync::{Arc, Mutex}, }; type ChildId = u32; -type ChildStore = Arc>>; +#[cfg(shell_execute)] +type ChildStore = Arc>>; +#[cfg(shell_execute)] fn command_childs() -> &'static ChildStore { + use once_cell::sync::Lazy; static STORE: Lazy = Lazy::new(Default::default); &STORE } @@ -59,6 +56,7 @@ pub enum Cmd { } impl Cmd { + #[allow(unused_variables)] pub fn run(self, window: Window) -> crate::Result { match self { Self::Execute { @@ -70,9 +68,9 @@ impl Cmd { #[cfg(shell_execute)] { let mut command = if sidecar { - Command::new_sidecar(program)? + crate::api::command::Command::new_sidecar(program)? } else { - Command::new(program) + crate::api::command::Command::new(program) }; command = command.args(args); let (mut rx, child) = command.spawn()?; @@ -82,10 +80,10 @@ impl Cmd { crate::async_runtime::spawn(async move { while let Some(event) = rx.recv().await { - if matches!(event, CommandEvent::Terminated(_)) { + if matches!(event, crate::api::command::CommandEvent::Terminated(_)) { command_childs().lock().unwrap().remove(&pid); } - let js = format_callback(on_event_fn.clone(), &event) + let js = crate::api::rpc::format_callback(on_event_fn.clone(), &event) .expect("unable to serialize CommandEvent"); let _ = window.eval(js.as_str()); diff --git a/core/tauri/src/endpoints/window.rs b/core/tauri/src/endpoints/window.rs index c20d457b2..95f168bf2 100644 --- a/core/tauri/src/endpoints/window.rs +++ b/core/tauri/src/endpoints/window.rs @@ -2,10 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use crate::{ - api::config::WindowConfig, endpoints::InvokeResponse, runtime::window::PendingWindow, Manager, - Params, Window, -}; +#[cfg(window_create)] +use crate::Manager; +use crate::{api::config::WindowConfig, endpoints::InvokeResponse, Params, Window}; use serde::Deserialize; use crate::Icon; @@ -99,35 +98,38 @@ struct WindowCreatedEvent { } impl Cmd { - pub async fn run(self, mut window: Window) -> crate::Result { + #[allow(dead_code)] + pub async fn run(self, window: Window) -> crate::Result { if cfg!(not(window_all)) { Err(crate::Error::ApiNotAllowlisted("window > all".to_string())) } else { match self { - Self::CreateWebview { options } => { - #[cfg(not(window_create))] + #[cfg(not(window_create))] + Self::CreateWebview { .. } => { return Err(crate::Error::ApiNotAllowlisted( "window > create".to_string(), )); - #[cfg(window_create)] - { - // Panic if the user's `Tag` type decided to return an error while parsing. - let label: M::Label = options.label.parse().unwrap_or_else(|_| { - panic!( - "Window module received unknown window label: {}", - options.label - ) - }); + } + #[cfg(window_create)] + Self::CreateWebview { options } => { + let mut window = window; + // Panic if the user's `Tag` type decided to return an error while parsing. + let label: M::Label = options.label.parse().unwrap_or_else(|_| { + panic!( + "Window module received unknown window label: {}", + options.label + ) + }); - let url = options.url.clone(); - let pending = PendingWindow::with_config(options, label.clone(), url); - window.create_window(pending)?.emit_others_internal( - "tauri://window-created".to_string(), - Some(WindowCreatedEvent { - label: label.to_string(), - }), - )?; - } + let url = options.url.clone(); + let pending = + crate::runtime::window::PendingWindow::with_config(options, label.clone(), url); + window.create_window(pending)?.emit_others_internal( + "tauri://window-created".to_string(), + Some(WindowCreatedEvent { + label: label.to_string(), + }), + )?; } Self::SetResizable { resizable } => window.set_resizable(resizable)?, Self::SetTitle { title } => window.set_title(&title)?, diff --git a/core/tauri/src/runtime/window.rs b/core/tauri/src/runtime/window.rs index f92a914bb..22f9572af 100644 --- a/core/tauri/src/runtime/window.rs +++ b/core/tauri/src/runtime/window.rs @@ -221,6 +221,7 @@ pub(crate) mod export { self.emit_internal(event.clone(), payload) } + #[allow(dead_code)] pub(crate) fn emit_others_internal( &self, event: String, diff --git a/core/tauri/src/settings.rs b/core/tauri/src/settings.rs index aff19d337..f8d89e276 100644 --- a/core/tauri/src/settings.rs +++ b/core/tauri/src/settings.rs @@ -27,6 +27,7 @@ fn get_settings_path() -> crate::api::Result { } /// Write the settings to the file system. +#[allow(dead_code)] pub(crate) fn write_settings(settings: Settings) -> crate::Result<()> { let settings_path = get_settings_path()?; let settings_folder = Path::new(&settings_path).parent().unwrap(); diff --git a/core/tauri/src/updater/mod.rs b/core/tauri/src/updater/mod.rs index fdc30148b..5af6d40f5 100644 --- a/core/tauri/src/updater/mod.rs +++ b/core/tauri/src/updater/mod.rs @@ -510,13 +510,9 @@ pub(crate) fn listener( // Linux we replace the AppImage by launching a new install, it start a new AppImage instance, so we're closing the previous. (the process stop here) let update_result = updater.clone().download_and_install(pubkey.clone()).await; - if update_result.is_err() { + if let Err(err) = update_result { // emit {"status": "ERROR", "error": "The error message"} - send_status_update( - window.clone(), - EVENT_STATUS_ERROR, - Some(update_result.err().unwrap().to_string()), - ); + send_status_update(window.clone(), EVENT_STATUS_ERROR, Some(err.to_string())); } else { // emit {"status": "DONE"} send_status_update(window.clone(), EVENT_STATUS_SUCCESS, None); diff --git a/tooling/bundler/src/bundle/wix.rs b/tooling/bundler/src/bundle/wix.rs index 1e1a5821b..b3a67cd29 100644 --- a/tooling/bundler/src/bundle/wix.rs +++ b/tooling/bundler/src/bundle/wix.rs @@ -830,11 +830,11 @@ fn generate_resource_data(settings: &Settings) -> crate::Result { .directories .iter() .position(|f| f.name == directory_name); - if index.is_some() { + if let Some(index) = index { // the directory entry is already a part of the chain let dir = directory_entry .directories - .get_mut(index.expect("Unable to get index")) + .get_mut(index) .expect("Unable to get directory"); dir.add_file(resource_entry.clone()); } else {