diff --git a/espanso-modulo/build.rs b/espanso-modulo/build.rs index 429bc28..86bc21d 100644 --- a/espanso-modulo/build.rs +++ b/espanso-modulo/build.rs @@ -192,7 +192,7 @@ fn build_native() { "--without-liblzma", "--with-libjpeg=builtin", "--with-libpng=builtin", - "--enable-universal-binary=arm64,x86_64" + "--enable-universal-binary=arm64,x86_64", ]) .spawn() .expect("failed to execute configure") diff --git a/espanso-modulo/src/form/mod.rs b/espanso-modulo/src/form/mod.rs index 0e66678..0556ba3 100644 --- a/espanso-modulo/src/form/mod.rs +++ b/espanso-modulo/src/form/mod.rs @@ -21,4 +21,4 @@ pub mod config; pub mod generator; pub mod parser; -pub use crate::sys::form::show; \ No newline at end of file +pub use crate::sys::form::show; diff --git a/espanso-modulo/src/lib.rs b/espanso-modulo/src/lib.rs index b139690..afd5396 100644 --- a/espanso-modulo/src/lib.rs +++ b/espanso-modulo/src/lib.rs @@ -22,7 +22,7 @@ extern crate lazy_static; pub mod form; pub mod search; +mod sys; pub mod troubleshooting; pub mod welcome; pub mod wizard; -mod sys; \ No newline at end of file diff --git a/espanso-modulo/src/search/algorithm.rs b/espanso-modulo/src/search/algorithm.rs index b90a3d5..80c829a 100644 --- a/espanso-modulo/src/search/algorithm.rs +++ b/espanso-modulo/src/search/algorithm.rs @@ -97,19 +97,21 @@ fn command_filter( let (valid_ids, trimmed_query) = if query.starts_with('>') { ( items - .iter() - .enumerate() - .filter(|(_, item)| item.is_builtin) - .map(|(i, _)| i).collect::>(), + .iter() + .enumerate() + .filter(|(_, item)| item.is_builtin) + .map(|(i, _)| i) + .collect::>(), query.trim_start_matches('>'), ) } else { ( items - .iter() - .enumerate() - .filter(|(_, item)| !item.is_builtin) - .map(|(i, _)| i).collect::>(), + .iter() + .enumerate() + .filter(|(_, item)| !item.is_builtin) + .map(|(i, _)| i) + .collect::>(), query, ) }; diff --git a/espanso-modulo/src/search/mod.rs b/espanso-modulo/src/search/mod.rs index d1c4a9c..c076798 100644 --- a/espanso-modulo/src/search/mod.rs +++ b/espanso-modulo/src/search/mod.rs @@ -21,4 +21,4 @@ pub mod algorithm; pub mod config; pub mod generator; -pub use crate::sys::search::show; \ No newline at end of file +pub use crate::sys::search::show; diff --git a/espanso-modulo/src/sys/form/mod.rs b/espanso-modulo/src/sys/form/mod.rs index 48e3bc9..42f3cb9 100644 --- a/espanso-modulo/src/sys/form/mod.rs +++ b/espanso-modulo/src/sys/form/mod.rs @@ -156,7 +156,9 @@ mod interop { impl From for OwnedField { fn from(field: types::Field) -> Self { - let id = field.id.map(|id| CString::new(id).expect("unable to create cstring for field id")); + let id = field + .id + .map(|id| CString::new(id).expect("unable to create cstring for field id")); let field_type = match field.field_type { types::FieldType::Row(_) => FieldType_ROW, @@ -353,8 +355,7 @@ pub fn show(form: types::Form) -> HashMap { let mut value_map: HashMap = HashMap::new(); extern "C" fn callback(values: *const ValuePair, size: c_int, map: *mut c_void) { - let values: &[ValuePair] = - unsafe { std::slice::from_raw_parts(values, size as usize) }; + let values: &[ValuePair] = unsafe { std::slice::from_raw_parts(values, size as usize) }; let map = map as *mut HashMap; let map = unsafe { &mut (*map) }; for pair in values.iter() { diff --git a/espanso-modulo/src/sys/interop/mod.rs b/espanso-modulo/src/sys/interop/mod.rs index 2a4a393..d4fde29 100644 --- a/espanso-modulo/src/sys/interop/mod.rs +++ b/espanso-modulo/src/sys/interop/mod.rs @@ -136,12 +136,12 @@ pub struct WizardMetadata { pub accessibility_image_2_path: *const c_char, pub detected_os: c_int, - pub is_legacy_version_running: extern fn() -> c_int, - pub backup_and_migrate: extern fn() -> c_int, - pub add_to_path: extern fn() -> c_int, - pub enable_accessibility: extern fn() -> c_int, - pub is_accessibility_enabled: extern fn() -> c_int, - pub on_completed: extern fn(), + pub is_legacy_version_running: extern "C" fn() -> c_int, + pub backup_and_migrate: extern "C" fn() -> c_int, + pub add_to_path: extern "C" fn() -> c_int, + pub enable_accessibility: extern "C" fn() -> c_int, + pub is_accessibility_enabled: extern "C" fn() -> c_int, + pub on_completed: extern "C" fn(), } #[repr(C)] @@ -152,7 +152,7 @@ pub struct WelcomeMetadata { pub already_running: c_int, - pub dont_show_again_changed: extern fn(c_int), + pub dont_show_again_changed: extern "C" fn(c_int), } #[repr(C)] @@ -164,8 +164,8 @@ pub struct TroubleshootingMetadata { pub error_sets: *const ErrorSetMetadata, pub error_sets_count: c_int, - pub dont_show_again_changed: extern fn(c_int), - pub open_file: extern fn(*const c_char), + pub dont_show_again_changed: extern "C" fn(c_int), + pub open_file: extern "C" fn(*const c_char), } #[repr(C)] @@ -216,6 +216,6 @@ extern "C" { // WELCOME pub(crate) fn interop_show_welcome(metadata: *const WelcomeMetadata); - // TROUBLESHOOTING + // TROUBLESHOOTING pub(crate) fn interop_show_troubleshooting(metadata: *const TroubleshootingMetadata); } diff --git a/espanso-modulo/src/sys/mod.rs b/espanso-modulo/src/sys/mod.rs index 3ac74cc..d69b485 100644 --- a/espanso-modulo/src/sys/mod.rs +++ b/espanso-modulo/src/sys/mod.rs @@ -20,12 +20,12 @@ pub mod form; pub mod search; pub mod troubleshooting; -pub mod wizard; pub mod welcome; +pub mod wizard; #[allow(non_upper_case_globals)] #[allow(dead_code)] #[allow(non_snake_case)] pub mod interop; -mod util; \ No newline at end of file +mod util; diff --git a/espanso-modulo/src/sys/search/mod.rs b/espanso-modulo/src/sys/search/mod.rs index 30b6804..de44836 100644 --- a/espanso-modulo/src/sys/search/mod.rs +++ b/espanso-modulo/src/sys/search/mod.rs @@ -40,8 +40,8 @@ pub mod types { #[allow(dead_code)] mod interop { - use super::types; use super::super::interop::*; + use super::types; use std::ffi::{c_void, CString}; pub(crate) struct OwnedSearch { @@ -102,7 +102,14 @@ mod interop { hintText: hint_ptr, }); - Self { title, icon_path, hint, items, interop_items, _interop } + Self { + title, + icon_path, + hint, + items, + interop_items, + _interop, + } } } diff --git a/espanso-modulo/src/sys/troubleshooting/mod.rs b/espanso-modulo/src/sys/troubleshooting/mod.rs index b3ae9ab..c303f5d 100644 --- a/espanso-modulo/src/sys/troubleshooting/mod.rs +++ b/espanso-modulo/src/sys/troubleshooting/mod.rs @@ -23,7 +23,7 @@ use std::path::PathBuf; use std::sync::Mutex; use crate::sys::interop::{ErrorSetMetadata, TroubleshootingMetadata}; -use crate::sys::troubleshooting::interop::{OwnedErrorSet}; +use crate::sys::troubleshooting::interop::OwnedErrorSet; use crate::sys::util::convert_to_cstring_or_null; use crate::troubleshooting::{TroubleshootingHandlers, TroubleshootingOptions}; use anyhow::Result; @@ -39,10 +39,7 @@ mod interop { use super::interop::{ErrorMetadata, ErrorSetMetadata}; use super::super::interop::*; - use std::{ - ffi::{CString}, - os::raw::c_int, - }; + use std::{ffi::CString, os::raw::c_int}; pub(crate) struct OwnedErrorSet { file_path: Option, @@ -68,8 +65,10 @@ mod interop { impl From<&ErrorSet> for OwnedErrorSet { fn from(error_set: &ErrorSet) -> Self { - let file_path = error_set.file.as_ref().map(|file_path| CString::new(file_path.to_string_lossy().to_string()) - .expect("unable to convert file_path to CString")); + let file_path = error_set.file.as_ref().map(|file_path| { + CString::new(file_path.to_string_lossy().to_string()) + .expect("unable to convert file_path to CString") + }); let errors: Vec = error_set.errors.iter().map(|item| item.into()).collect(); diff --git a/espanso-modulo/src/sys/util.rs b/espanso-modulo/src/sys/util.rs index 6ca1d78..5c3b5cb 100644 --- a/espanso-modulo/src/sys/util.rs +++ b/espanso-modulo/src/sys/util.rs @@ -17,8 +17,8 @@ * along with espanso. If not, see . */ -use std::os::raw::{c_char}; use std::ffi::CString; +use std::os::raw::c_char; pub fn convert_to_cstring_or_null(str: Option) -> (Option, *const c_char) { let c_string = @@ -28,4 +28,4 @@ pub fn convert_to_cstring_or_null(str: Option) -> (Option, *con .map_or(std::ptr::null(), |path| path.as_ptr()); (c_string, c_ptr) -} \ No newline at end of file +} diff --git a/espanso-modulo/src/sys/welcome/mod.rs b/espanso-modulo/src/sys/welcome/mod.rs index 0357e7e..95570ba 100644 --- a/espanso-modulo/src/sys/welcome/mod.rs +++ b/espanso-modulo/src/sys/welcome/mod.rs @@ -17,11 +17,14 @@ * along with modulo. If not, see . */ -use std::os::raw::{c_int}; -use std::{ sync::Mutex}; +use std::os::raw::c_int; +use std::sync::Mutex; use crate::sys::util::convert_to_cstring_or_null; -use crate::{sys::interop::{WelcomeMetadata}, welcome::{WelcomeHandlers, WelcomeOptions}}; +use crate::{ + sys::interop::WelcomeMetadata, + welcome::{WelcomeHandlers, WelcomeOptions}, +}; lazy_static! { static ref HANDLERS: Mutex> = Mutex::new(None); @@ -43,7 +46,7 @@ pub fn show(options: WelcomeOptions) { (*handler_ref)(value); } } - + { let mut lock = HANDLERS.lock().expect("unable to acquire handlers lock"); *lock = Some(options.handlers) diff --git a/espanso-modulo/src/sys/wizard/mod.rs b/espanso-modulo/src/sys/wizard/mod.rs index c1b3b99..4c02f09 100644 --- a/espanso-modulo/src/sys/wizard/mod.rs +++ b/espanso-modulo/src/sys/wizard/mod.rs @@ -17,7 +17,7 @@ * along with modulo. If not, see . */ -use std::os::raw::{c_int}; +use std::os::raw::c_int; use std::{ffi::CString, sync::Mutex}; use crate::sys::interop::{