style(core): fix formatting

This commit is contained in:
Federico Terzi 2021-10-06 18:36:23 +02:00
parent 5d7b13e0bc
commit 9e3742f273
89 changed files with 439 additions and 328 deletions

View File

@ -26,7 +26,7 @@ pub fn can_use_capabilities() -> bool {
Err(err) => {
error!("error while checking if capabilities are enabled: {}", err);
false
},
}
}
}

View File

@ -26,4 +26,3 @@ pub use linux::*;
mod fallback;
#[cfg(not(target_os = "linux"))]
pub use fallback::*;

View File

@ -19,7 +19,7 @@
use anyhow::Result;
use crossbeam::channel::Sender;
use log::{error, debug};
use log::{debug, error};
const WATCHER_INTERVAL: u64 = 1000;

View File

@ -29,7 +29,7 @@ use log::{error, info, warn};
use crate::{
cli::util::CommandExt,
common_flags::{*},
common_flags::*,
exit_code::{
DAEMON_ALREADY_RUNNING, DAEMON_FATAL_CONFIG_ERROR, DAEMON_GENERAL_ERROR,
DAEMON_LEGACY_ALREADY_RUNNING, DAEMON_SUCCESS, WORKER_EXIT_ALL_PROCESSES, WORKER_RESTART,
@ -123,11 +123,7 @@ fn daemon_main(args: CliModuleArgs) -> i32 {
// TODO: register signals to terminate the worker if the daemon terminates
spawn_worker(
&paths_overrides,
exit_notify.clone(),
None
);
spawn_worker(&paths_overrides, exit_notify.clone(), None);
ipc::initialize_and_spawn(&paths.runtime, exit_notify.clone())
.expect("unable to initialize ipc server for daemon");
@ -246,10 +242,7 @@ fn spawn_worker(
let mut command = Command::new(&espanso_exe_path.to_string_lossy().to_string());
let mut args = vec![
"worker",
"--monitor-daemon",
];
let mut args = vec!["worker", "--monitor-daemon"];
if let Some(start_reason) = &start_reason {
args.push("--start-reason");
args.push(start_reason);
@ -312,11 +305,7 @@ fn restart_worker(
}
if !has_timed_out {
spawn_worker(
paths_overrides,
exit_notify,
start_reason,
);
spawn_worker(paths_overrides, exit_notify, start_reason);
} else {
error!("could not restart worker, as the exit process has timed out");
}

View File

@ -99,11 +99,9 @@ pub fn load_config_or_troubleshoot(paths: &Paths, paths_overrides: &PathsOverrid
LoadResult::Warning(load_result, troubleshoot_handle)
}
}
Err(_) => {
LoadResult::Fatal(
Err(_) => LoadResult::Fatal(
launch_troubleshoot(paths_overrides).expect("unable to launch troubleshoot GUI"),
)
}
),
}
}

View File

@ -22,8 +22,8 @@ use std::process::Command;
use anyhow::Result;
use thiserror::Error;
use crate::cli::PathsOverrides;
use crate::cli::util::CommandExt;
use crate::cli::PathsOverrides;
pub fn launch_daemon(paths_overrides: &PathsOverrides) -> Result<()> {
let espanso_exe_path = std::env::current_exe()?;

View File

@ -18,8 +18,11 @@
*/
use self::util::MigrationError;
use crate::{exit_code::{LAUNCHER_ALREADY_RUNNING, LAUNCHER_CONFIG_DIR_POPULATION_FAILURE, LAUNCHER_SUCCESS}, lock::acquire_daemon_lock};
use crate::preferences::Preferences;
use crate::{
exit_code::{LAUNCHER_ALREADY_RUNNING, LAUNCHER_CONFIG_DIR_POPULATION_FAILURE, LAUNCHER_SUCCESS},
lock::acquire_daemon_lock,
};
use log::error;
use super::{CliModule, CliModuleArgs};
@ -76,7 +79,8 @@ fn launcher_main(args: CliModuleArgs) -> i32 {
let is_legacy_version_running_handler =
Box::new(move || util::is_legacy_version_running(&runtime_dir_clone));
let (is_wrong_edition_page_enabled, wrong_edition_detected_os) = edition_check::is_wrong_edition();
let (is_wrong_edition_page_enabled, wrong_edition_detected_os) =
edition_check::is_wrong_edition();
let is_migrate_page_enabled = espanso_config::is_legacy_config(&paths.config);
let paths_clone = paths.clone();
@ -115,8 +119,7 @@ fn launcher_main(args: CliModuleArgs) -> i32 {
} else {
false
};
let is_accessibility_enabled_handler =
Box::new(accessibility::is_accessibility_enabled);
let is_accessibility_enabled_handler = Box::new(accessibility::is_accessibility_enabled);
let enable_accessibility_handler = Box::new(move || {
accessibility::prompt_enable_accessibility();
});

View File

@ -20,10 +20,13 @@
use std::{path::Path, process::Command};
use anyhow::Result;
use thiserror::Error;
use espanso_path::Paths;
use thiserror::Error;
use crate::{exit_code::{MIGRATE_CLEAN_FAILURE, MIGRATE_DIRTY_FAILURE}, lock::acquire_legacy_lock};
use crate::{
exit_code::{MIGRATE_CLEAN_FAILURE, MIGRATE_DIRTY_FAILURE},
lock::acquire_legacy_lock,
};
pub fn is_legacy_version_running(runtime_path: &Path) -> bool {
let legacy_lock_file = acquire_legacy_lock(runtime_path);
@ -56,7 +59,7 @@ pub fn migrate_configuration(paths: &Paths) -> Result<()> {
match result.code() {
Some(code) if code == MIGRATE_CLEAN_FAILURE => Err(MigrationError::Clean.into()),
Some(code) if code == MIGRATE_DIRTY_FAILURE => Err(MigrationError::Dirty.into()),
_ => Err(MigrationError::Unexpected.into())
_ => Err(MigrationError::Unexpected.into()),
}
}
}

View File

@ -17,8 +17,8 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{fs::File, io::BufReader};
use std::io::BufRead;
use std::{fs::File, io::BufReader};
use super::{CliModule, CliModuleArgs};

View File

@ -17,9 +17,16 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{path::PathBuf};
use std::path::PathBuf;
use crate::{exit_code::{MIGRATE_ALREADY_NEW_FORMAT, MIGRATE_CLEAN_FAILURE, MIGRATE_DIRTY_FAILURE, MIGRATE_LEGACY_INSTANCE_RUNNING, MIGRATE_SUCCESS, MIGRATE_USER_ABORTED, configure_custom_panic_hook, update_panic_exit_code}, lock::acquire_legacy_lock};
use crate::{
exit_code::{
configure_custom_panic_hook, update_panic_exit_code, MIGRATE_ALREADY_NEW_FORMAT,
MIGRATE_CLEAN_FAILURE, MIGRATE_DIRTY_FAILURE, MIGRATE_LEGACY_INSTANCE_RUNNING, MIGRATE_SUCCESS,
MIGRATE_USER_ABORTED,
},
lock::acquire_legacy_lock,
};
use super::{CliModule, CliModuleArgs};
use colored::*;
@ -91,11 +98,13 @@ fn migrate_main(args: CliModuleArgs) -> i32 {
target_backup_dir.to_string_lossy()
);
if !cli_args.is_present("noconfirm") && !Confirm::new()
if !cli_args.is_present("noconfirm")
&& !Confirm::new()
.with_prompt("Do you want to proceed?")
.default(true)
.interact()
.expect("unable to read choice") {
.expect("unable to read choice")
{
return MIGRATE_USER_ABORTED;
}

View File

@ -59,7 +59,7 @@ impl Default for CliModule {
subcommand: "".to_string(),
show_in_dock: false,
requires_linux_capabilities: false,
entry: |_| {0},
entry: |_| 0,
}
}
}

View File

@ -17,9 +17,9 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use clap::{ArgMatches};
use espanso_modulo::form::*;
use crate::icon::IconPaths;
use clap::ArgMatches;
use espanso_modulo::form::*;
pub fn form_main(matches: &ArgMatches, _icon_paths: &IconPaths) -> i32 {
let as_json: bool = matches.is_present("json");
@ -45,7 +45,10 @@ pub fn form_main(matches: &ArgMatches, _icon_paths: &IconPaths) -> i32 {
};
// Overwrite the icon
config.icon = _icon_paths.form_icon.as_deref().map(|path| path.to_string_lossy().to_string());
config.icon = _icon_paths
.form_icon
.as_deref()
.map(|path| path.to_string_lossy().to_string());
let form = generator::generate(config);
let values = show(form);

View File

@ -24,9 +24,9 @@ mod form;
#[cfg(feature = "modulo")]
mod search;
#[cfg(feature = "modulo")]
mod welcome;
#[cfg(feature = "modulo")]
mod troubleshoot;
#[cfg(feature = "modulo")]
mod welcome;
pub fn new() -> CliModule {
#[allow(clippy::needless_update)]

View File

@ -17,10 +17,10 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::collections::HashMap;
use clap::{ArgMatches};
use espanso_modulo::search::*;
use crate::icon::IconPaths;
use clap::ArgMatches;
use espanso_modulo::search::*;
use std::collections::HashMap;
pub fn search_main(matches: &ArgMatches, icon_paths: &IconPaths) -> i32 {
let as_json: bool = matches.is_present("json");
@ -46,7 +46,10 @@ pub fn search_main(matches: &ArgMatches, icon_paths: &IconPaths) -> i32 {
};
// Overwrite the icon
config.icon = icon_paths.logo.as_deref().map(|path| path.to_string_lossy().to_string());
config.icon = icon_paths
.logo
.as_deref()
.map(|path| path.to_string_lossy().to_string());
let algorithm = algorithm::get_algorithm(&config.algorithm, true);

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::path::{Path};
use std::path::Path;
use crate::icon::IconPaths;
use crate::preferences::Preferences;
@ -38,8 +38,8 @@ pub fn troubleshoot_main(paths: &Paths, icon_paths: &IconPaths) -> i32 {
}
});
let (is_fatal_error, error_sets) = match crate::config::load_config(&paths.config, &paths.packages)
{
let (is_fatal_error, error_sets) =
match crate::config::load_config(&paths.config, &paths.packages) {
Ok(config_result) => {
let error_sets = config_result
.non_fatal_errors
@ -99,7 +99,8 @@ pub fn troubleshoot_main(paths: &Paths, icon_paths: &IconPaths) -> i32 {
dont_show_again_changed: Some(dont_show_again_handler),
open_file: Some(open_file_handler),
},
}).expect("troubleshoot GUI returned error");
})
.expect("troubleshoot GUI returned error");
0
}

View File

@ -17,8 +17,8 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use clap::{ArgMatches};
use crate::icon::IconPaths;
use clap::ArgMatches;
use espanso_modulo::welcome::*;
use espanso_path::Paths;

View File

@ -70,8 +70,12 @@ pub fn install_package(paths: &Paths, matches: &ArgMatches) -> Result<()> {
error_eprintln!("Error: the requested package is hosted on an external repository");
error_eprintln!("and its contents may not have been verified by the espanso team.");
error_eprintln!("");
error_eprintln!("For security reasons, espanso blocks packages that are not verified by default.");
error_eprintln!("If you want to install the package anyway, you can proceed with the installation");
error_eprintln!(
"For security reasons, espanso blocks packages that are not verified by default."
);
error_eprintln!(
"If you want to install the package anyway, you can proceed with the installation"
);
error_eprintln!("by passing the '--external' flag, but please do it only if you trust the");
error_eprintln!("source or you verified the contents of the package yourself.");
error_eprintln!("");

View File

@ -42,10 +42,15 @@ pub fn list_packages(paths: &Paths, _: &ArgMatches) -> Result<()> {
match package {
StoredPackage::Legacy(legacy) => {
info_println!("- {} (legacy)", legacy.name);
},
}
StoredPackage::Modern(package) => {
info_println!("- {} - version: {} ({})", package.manifest.name, package.manifest.version, package.source);
},
info_println!(
"- {} - version: {} ({})",
package.manifest.name,
package.manifest.version,
package.source
);
}
}
}

View File

@ -31,7 +31,9 @@ pub fn uninstall_package(paths: &Paths, matches: &ArgMatches) -> Result<()> {
let archiver =
espanso_package::get_archiver(&paths.packages).context("unable to get package archiver")?;
archiver.delete(package_name).context("unable to delete package")?;
archiver
.delete(package_name)
.context("unable to delete package")?;
info_println!("package '{}' uninstalled!", package_name);

View File

@ -37,19 +37,35 @@ fn path_main(args: CliModuleArgs) -> i32 {
println!("{}", paths.config.to_string_lossy());
} else if cli_args.subcommand_matches("packages").is_some() {
println!("{}", paths.packages.to_string_lossy());
} else if cli_args.subcommand_matches("data").is_some() || cli_args.subcommand_matches("runtime").is_some() {
} else if cli_args.subcommand_matches("data").is_some()
|| cli_args.subcommand_matches("runtime").is_some()
{
println!("{}", paths.runtime.to_string_lossy());
} else if cli_args.subcommand_matches("default").is_some() {
if args.is_legacy_config {
println!("{}", paths.config.join("default.yml").to_string_lossy());
} else {
println!("{}", paths.config.join("config").join("default.yml").to_string_lossy());
println!(
"{}",
paths
.config
.join("config")
.join("default.yml")
.to_string_lossy()
);
}
} else if cli_args.subcommand_matches("base").is_some() {
if args.is_legacy_config {
eprintln!("base config not available when using legacy configuration format");
} else {
println!("{}", paths.config.join("match").join("base.yml").to_string_lossy());
println!(
"{}",
paths
.config
.join("match")
.join("base.yml")
.to_string_lossy()
);
}
} else {
println!("Config: {}", paths.config.to_string_lossy());

View File

@ -20,9 +20,9 @@
use anyhow::Result;
use const_format::formatcp;
use regex::Regex;
use std::fs::create_dir_all;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::{fs::create_dir_all};
use thiserror::Error;
use crate::{error_eprintln, info_println, warn_eprintln};
@ -143,8 +143,7 @@ pub fn is_registered() -> bool {
if cmd_output.status.success() {
let caps = EXEC_PATH_REGEX.captures(output).unwrap();
let path = caps.get(1).map_or("", |m| m.as_str());
let espanso_path =
get_binary_path().expect("unable to get espanso executable path");
let espanso_path = get_binary_path().expect("unable to get espanso executable path");
if espanso_path.to_string_lossy() != path {
error_eprintln!("Espanso is registered as a systemd service, but it points to another binary location:");
@ -195,8 +194,12 @@ pub fn start_service() -> Result<()> {
);
error_eprintln!("You can run it in unmanaged mode with `espanso service start --unmanaged`");
error_eprintln!("");
error_eprintln!("NOTE: unmanaged mode means espanso does not rely on the system service manager");
error_eprintln!(" to run, but as a result, you are in charge of starting/stopping espanso");
error_eprintln!(
"NOTE: unmanaged mode means espanso does not rely on the system service manager"
);
error_eprintln!(
" to run, but as a result, you are in charge of starting/stopping espanso"
);
error_eprintln!(" when needed.");
return Err(StartError::SystemdNotFound.into());
}
@ -207,8 +210,12 @@ pub fn start_service() -> Result<()> {
error_eprintln!("You can either register it first with `espanso service register` or");
error_eprintln!("you can run it in unmanaged mode with `espanso service start --unmanaged`");
error_eprintln!("");
error_eprintln!("NOTE: unmanaged mode means espanso does not rely on the system service manager");
error_eprintln!(" to run, but as a result, you are in charge of starting/stopping espanso");
error_eprintln!(
"NOTE: unmanaged mode means espanso does not rely on the system service manager"
);
error_eprintln!(
" to run, but as a result, you are in charge of starting/stopping espanso"
);
error_eprintln!(" when needed.");
return Err(StartError::NotRegistered.into());
}

View File

@ -18,7 +18,15 @@
*/
use super::{CliModule, CliModuleArgs};
use crate::{error_eprintln, exit_code::{SERVICE_ALREADY_RUNNING, SERVICE_FAILURE, SERVICE_NOT_REGISTERED, SERVICE_NOT_RUNNING, SERVICE_SUCCESS}, info_println, lock::acquire_worker_lock};
use crate::{
error_eprintln,
exit_code::{
SERVICE_ALREADY_RUNNING, SERVICE_FAILURE, SERVICE_NOT_REGISTERED, SERVICE_NOT_RUNNING,
SERVICE_SUCCESS,
},
info_println,
lock::acquire_worker_lock,
};
#[cfg(target_os = "macos")]
mod macos;

View File

@ -17,9 +17,9 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::cli::util::CommandExt;
use anyhow::Result;
use thiserror::Error;
use crate::cli::util::CommandExt;
use crate::cli::PathsOverrides;

View File

@ -18,11 +18,11 @@
*/
use anyhow::Result;
use std::fs::create_dir_all;
use std::os::windows::process::CommandExt;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{fs::create_dir_all};
use thiserror::Error;
use std::os::windows::process::CommandExt;
use crate::{error_eprintln, warn_eprintln};
@ -67,7 +67,9 @@ pub fn is_registered() -> bool {
if current_path != target_path {
warn_eprintln!("WARNING: Espanso is already registered as a service, but it points to another executable,");
warn_eprintln!("which can create some inconsistencies.");
warn_eprintln!("To fix the problem, unregister and register espanso again with these commands:");
warn_eprintln!(
"To fix the problem, unregister and register espanso again with these commands:"
);
warn_eprintln!("");
warn_eprintln!(" espanso service unregister");
warn_eprintln!(" espanso service register");
@ -75,11 +77,11 @@ pub fn is_registered() -> bool {
}
true
},
}
Err(err) => {
error_eprintln!("unable to determine shortcut target path: {}", err);
false
},
}
}
}
Err(err) => {
@ -138,7 +140,11 @@ fn get_shortcut_target_file(shortcut_path: &Path) -> Result<PathBuf> {
Ok(path)
}
fn create_shortcut_target_file(shortcut_path: &Path, target_path: &Path, arguments: &str) -> Result<()> {
fn create_shortcut_target_file(
shortcut_path: &Path,
target_path: &Path,
arguments: &str,
) -> Result<()> {
let output = Command::new("powershell")
.arg("-c")
.arg("$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut($env:SHORTCUT_PATH); $Shortcut.TargetPath = $env:TARGET_PATH; $Shortcut.Arguments = $env:TARGET_ARGS; $Shortcut.Save()")

View File

@ -18,7 +18,7 @@
*/
use super::{CliModule, CliModuleArgs};
use crate::{error_eprintln, exit_code::{WORKAROUND_SUCCESS}};
use crate::{error_eprintln, exit_code::WORKAROUND_SUCCESS};
#[cfg(target_os = "macos")]
mod secure_input;

View File

@ -27,11 +27,9 @@ use std::{
const BLUR_CHROME_WINDOWS_SCRIPT: &str =
include_str!("../../res/macos/scripts/blur_chrome_windows.scpt");
const GET_RUNNING_APPS_SCRIPT: &str =
include_str!("../../res/macos/scripts/get_running_apps.scpt");
const GET_RUNNING_APPS_SCRIPT: &str = include_str!("../../res/macos/scripts/get_running_apps.scpt");
const FOCUS_BITWARDEN_SCRIPT: &str =
include_str!("../../res/macos/scripts/focus_bitwarden.scpt");
const FOCUS_BITWARDEN_SCRIPT: &str = include_str!("../../res/macos/scripts/focus_bitwarden.scpt");
const SECURE_INPUT_ASK_LOCK_SCREEN_SCRIPT: &str =
include_str!("../../res/macos/scripts/secure_input_ask_lock_screen.scpt");

View File

@ -28,9 +28,7 @@ pub fn create_match_exit() -> BuiltInMatch {
id: generate_next_builtin_id(),
label: "Exit espanso",
triggers: Vec::new(),
action: |_| {
EventType::ExitRequested(ExitMode::ExitAllProcesses)
},
action: |_| EventType::ExitRequested(ExitMode::ExitAllProcesses),
..Default::default()
}
}
@ -40,9 +38,7 @@ pub fn create_match_restart() -> BuiltInMatch {
id: generate_next_builtin_id(),
label: "Restart espanso",
triggers: Vec::new(),
action: |_| {
EventType::ExitRequested(ExitMode::RestartWorker)
},
action: |_| EventType::ExitRequested(ExitMode::RestartWorker),
..Default::default()
}
}

View File

@ -86,7 +86,8 @@ impl<'a> espanso_engine::process::MatchFilter for ConfigManager<'a> {
let builtin_matches: Vec<i32> = matches_ids
.iter()
.filter(|id| is_builtin_match(**id)).copied()
.filter(|id| is_builtin_match(**id))
.copied()
.collect();
let mut output = active_user_defined_matches;
@ -164,7 +165,7 @@ impl<'a> espanso_engine::process::UndoEnabledProvider for ConfigManager<'a> {
fn is_undo_enabled(&self) -> bool {
// Disable undo_backspace on Wayland for now as it's not stable
if cfg!(feature = "wayland") {
return false
return false;
}
self.active().undo_backspace()

View File

@ -23,7 +23,7 @@ use espanso_config::config::Config;
mod default;
pub use default::DefaultContext;
use espanso_info::{AppInfo};
use espanso_info::AppInfo;
pub trait Context: ConfigContext + AppInfoContext {}

View File

@ -17,7 +17,10 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{cell::RefCell, time::{Duration, Instant}};
use std::{
cell::RefCell,
time::{Duration, Instant},
};
use espanso_info::{AppInfo, AppInfoProvider};

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use espanso_ui::{UIRemote, icons::TrayIcon};
use espanso_ui::{icons::TrayIcon, UIRemote};
use espanso_engine::{dispatch::IconHandler, event::ui::IconStatus};

View File

@ -48,9 +48,7 @@ impl<'a> funnel::Source<'a> for DetectSource {
key: convert_to_engine_key(keyboard_event.key),
value: keyboard_event.value,
status: convert_to_engine_status(keyboard_event.status),
variant: keyboard_event
.variant
.map(convert_to_engine_variant),
variant: keyboard_event.variant.map(convert_to_engine_variant),
}),
},
InputEvent::Mouse(mouse_event) => Event {

View File

@ -19,7 +19,10 @@
use crossbeam::channel::{Receiver, Select, SelectedOperation};
use espanso_engine::{event::{Event, EventType, ExitMode}, funnel};
use espanso_engine::{
event::{Event, EventType, ExitMode},
funnel,
};
use super::sequencer::Sequencer;

View File

@ -29,7 +29,16 @@ use espanso_path::Paths;
use espanso_ui::{event::UIEvent, UIRemote};
use log::{debug, error, info, warn};
use crate::{cli::worker::{context::Context, engine::{dispatch::executor::{clipboard_injector::ClipboardInjectorAdapter, context_menu::ContextMenuHandlerAdapter, event_injector::EventInjectorAdapter, icon::IconHandlerAdapter, key_injector::KeyInjectorAdapter, secure_input::SecureInputManagerAdapter}, process::middleware::{
use crate::{
cli::worker::{
context::Context,
engine::{
dispatch::executor::{
clipboard_injector::ClipboardInjectorAdapter, context_menu::ContextMenuHandlerAdapter,
event_injector::EventInjectorAdapter, icon::IconHandlerAdapter,
key_injector::KeyInjectorAdapter, secure_input::SecureInputManagerAdapter,
},
process::middleware::{
image_resolve::PathProviderAdapter,
match_select::MatchSelectorAdapter,
matcher::{
@ -42,15 +51,25 @@ use crate::{cli::worker::{context::Context, engine::{dispatch::executor::{clipbo
extension::{clipboard::ClipboardAdapter, form::FormProviderAdapter},
RendererAdapter,
},
}}, match_cache::{CombinedMatchCache, MatchCache}, ui::notification::NotificationManager}, common_flags::{WORKER_START_REASON_CONFIG_CHANGED, WORKER_START_REASON_KEYBOARD_LAYOUT_CHANGED, WORKER_START_REASON_MANUAL}, preferences::Preferences};
},
},
match_cache::{CombinedMatchCache, MatchCache},
ui::notification::NotificationManager,
},
common_flags::{
WORKER_START_REASON_CONFIG_CHANGED, WORKER_START_REASON_KEYBOARD_LAYOUT_CHANGED,
WORKER_START_REASON_MANUAL,
},
preferences::Preferences,
};
use super::secure_input::SecureInputEvent;
mod caches;
pub mod dispatch;
pub mod funnel;
pub mod process;
mod caches;
mod keyboard_layout_util;
pub mod process;
#[allow(clippy::too_many_arguments)]
pub fn initialize_and_spawn(
@ -68,12 +87,16 @@ pub fn initialize_and_spawn(
.name("engine thread".to_string())
.spawn(move || {
// TODO: properly order the initializations if necessary
let preferences = crate::preferences::get_default(&paths.runtime).expect("unable to load preferences");
let preferences =
crate::preferences::get_default(&paths.runtime).expect("unable to load preferences");
let app_info_provider =
espanso_info::get_provider().expect("unable to initialize app info provider");
// TODO: read interval from configs?
let cached_app_info_provider = caches::app_info_provider::CachedAppInfoProvider::from(&*app_info_provider, std::time::Duration::from_millis(400));
let cached_app_info_provider = caches::app_info_provider::CachedAppInfoProvider::from(
&*app_info_provider,
std::time::Duration::from_millis(400),
);
let config_manager =
super::config::ConfigManager::new(&*config_store, &*match_store, &cached_app_info_provider);
let match_cache = MatchCache::load(&*config_store, &*match_store);
@ -83,7 +106,10 @@ pub fn initialize_and_spawn(
let modulo_form_ui = crate::gui::modulo::form::ModuloFormUI::new(&modulo_manager);
let modulo_search_ui = crate::gui::modulo::search::ModuloSearchUI::new(&modulo_manager);
let context: Box<dyn Context> = Box::new(super::context::DefaultContext::new(&config_manager, &cached_app_info_provider));
let context: Box<dyn Context> = Box::new(super::context::DefaultContext::new(
&config_manager,
&cached_app_info_provider,
));
let builtin_matches = super::builtin::get_builtin_matches(&*config_manager.default());
let combined_match_cache = CombinedMatchCache::load(&match_cache, &builtin_matches);
@ -95,7 +121,9 @@ pub fn initialize_and_spawn(
let (detect_source, modifier_state_store, sequencer, key_state_store) =
super::engine::funnel::init_and_spawn(SourceCreationOptions {
use_evdev: use_evdev_backend,
evdev_keyboard_rmlvo: keyboard_layout_util::generate_detect_rmlvo(&*config_manager.default()),
evdev_keyboard_rmlvo: keyboard_layout_util::generate_detect_rmlvo(
&*config_manager.default(),
),
hotkeys: match_converter.get_hotkeys(),
win32_exclude_orphan_events: default_config.win32_exclude_orphan_events(),
})
@ -136,8 +164,11 @@ pub fn initialize_and_spawn(
let injector = espanso_inject::get_injector(InjectorCreationOptions {
use_evdev: use_evdev_backend,
keyboard_state_provider: key_state_store.map(|store| Box::new(store) as Box<dyn KeyboardStateProvider>),
evdev_keyboard_rmlvo: keyboard_layout_util::generate_inject_rmlvo(&*config_manager.default()),
keyboard_state_provider: key_state_store
.map(|store| Box::new(store) as Box<dyn KeyboardStateProvider>),
evdev_keyboard_rmlvo: keyboard_layout_util::generate_inject_rmlvo(
&*config_manager.default(),
),
..Default::default()
})
.expect("failed to initialize injector module"); // TODO: handle the options

View File

@ -124,6 +124,8 @@ impl<'a> MatchConverter<'a> {
fn global_match_set(&self) -> MatchSet {
let paths = self.config_store.get_all_match_paths();
self.match_store.query(&paths.into_iter().collect::<Vec<_>>())
self
.match_store
.query(&paths.into_iter().collect::<Vec<_>>())
}
}

View File

@ -19,7 +19,7 @@
pub mod disable;
pub mod image_resolve;
pub mod matcher;
pub mod match_select;
pub mod matcher;
pub mod multiplex;
pub mod render;

View File

@ -26,9 +26,7 @@ pub struct ClipboardAdapter<'a> {
impl<'a> ClipboardAdapter<'a> {
pub fn new(clipboard: &'a dyn Clipboard) -> Self {
Self {
clipboard
}
Self { clipboard }
}
}

View File

@ -86,7 +86,9 @@ fn generate_global_vars_map(config_provider: &dyn ConfigProvider) -> HashMap<i32
for (_, match_set) in config_provider.configs() {
for var in match_set.global_vars.iter() {
global_vars_map.entry(var.id).or_insert_with(|| convert_var((*var).clone()));
global_vars_map
.entry(var.id)
.or_insert_with(|| convert_var((*var).clone()));
}
}

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{collections::HashMap};
use std::collections::HashMap;
use espanso_config::{
config::ConfigStore,

View File

@ -34,7 +34,10 @@ pub fn convert_icon_paths_to_tray_vec(icon_paths: &IconPaths) -> Vec<(TrayIcon,
}
if let Some(system_disabled) = &icon_paths.tray_icon_system_disabled {
paths.push((TrayIcon::SystemDisabled, system_disabled.to_string_lossy().to_string()));
paths.push((
TrayIcon::SystemDisabled,
system_disabled.to_string_lossy().to_string(),
));
}
paths

View File

@ -36,7 +36,11 @@ pub struct SearchItem {
}
pub trait FormUI {
fn show(&self, layout: &str, fields: &HashMap<String, FormField>) -> Result<Option<HashMap<String, String>>>;
fn show(
&self,
layout: &str,
fields: &HashMap<String, FormField>,
) -> Result<Option<HashMap<String, String>>>;
}
#[derive(Debug)]
@ -52,5 +56,5 @@ pub enum FormField {
List {
default: Option<String>,
values: Vec<String>,
}
},
}

View File

@ -19,7 +19,7 @@
use serde::Serialize;
use serde_json::{json, Map, Value};
use std::{collections::HashMap};
use std::collections::HashMap;
use crate::gui::{FormField, FormUI};
@ -31,9 +31,7 @@ pub struct ModuloFormUI<'a> {
impl<'a> ModuloFormUI<'a> {
pub fn new(manager: &'a ModuloManager) -> Self {
Self {
manager,
}
Self { manager }
}
}
@ -62,9 +60,7 @@ impl<'a> FormUI for ModuloFormUI<'a> {
Ok(Some(json))
}
}
Err(error) => {
Err(error.into())
}
Err(error) => Err(error.into()),
}
}
}

View File

@ -77,22 +77,16 @@ impl ModuloManager {
Err(ModuloError::EmptyOutput.into())
}
}
Err(error) => {
Err(ModuloError::Error(error).into())
Err(error) => Err(ModuloError::Error(error).into()),
}
}
}
Err(error) => {
Err(ModuloError::Error(error).into())
}
Err(error) => Err(ModuloError::Error(error).into()),
}
} else {
Err(ModuloError::StdinError.into())
}
}
Err(error) => {
Err(ModuloError::Error(error).into())
}
Err(error) => Err(ModuloError::Error(error).into()),
}
} else {
Err(ModuloError::MissingModulo.into())
@ -102,7 +96,9 @@ impl ModuloManager {
#[derive(Error, Debug)]
pub enum ModuloError {
#[error("attempt to invoke modulo, but this version of espanso is not compiled with support for it")]
#[error(
"attempt to invoke modulo, but this version of espanso is not compiled with support for it"
)]
MissingModulo,
#[error("modulo returned an empty output")]

View File

@ -19,7 +19,7 @@
use serde::Serialize;
use serde_json::Value;
use std::{collections::HashMap};
use std::collections::HashMap;
use crate::gui::{SearchItem, SearchUI};
@ -31,9 +31,7 @@ pub struct ModuloSearchUI<'a> {
impl<'a> ModuloSearchUI<'a> {
pub fn new(manager: &'a ModuloManager) -> Self {
Self {
manager,
}
Self { manager }
}
}
@ -58,9 +56,7 @@ impl<'a> SearchUI for ModuloSearchUI<'a> {
Ok(None)
}
}
Err(error) => {
Err(error.into())
}
Err(error) => Err(error.into()),
}
}
}
@ -82,10 +78,13 @@ struct ModuloSearchItemConfig<'a> {
// TODO: test
fn convert_items(items: &[SearchItem]) -> Vec<ModuloSearchItemConfig> {
items.iter().map(|item| ModuloSearchItemConfig {
items
.iter()
.map(|item| ModuloSearchItemConfig {
id: &item.id,
label: &item.label,
trigger: item.tag.as_deref(),
is_builtin: item.is_builtin,
}).collect()
})
.collect()
}

View File

@ -33,7 +33,6 @@ const WINDOWS_LOGO_ICO_BINARY: &[u8] = include_bytes!("res/windows/logo.ico");
#[cfg(target_os = "windows")]
const WINDOWS_TRAY_EXPLAIN_IMAGE: &[u8] = include_bytes!("res/windows/tray_explain_image.png");
#[cfg(target_os = "macos")]
const MAC_BINARY: &[u8] = include_bytes!("res/macos/icon.png");
#[cfg(target_os = "macos")]
@ -68,14 +67,32 @@ pub struct IconPaths {
#[cfg(target_os = "windows")]
pub fn load_icon_paths(runtime_dir: &Path) -> Result<IconPaths> {
Ok(IconPaths {
form_icon: Some(extract_icon(WINDOWS_LOGO_ICO_BINARY, &runtime_dir.join("form.ico"))?),
form_icon: Some(extract_icon(
WINDOWS_LOGO_ICO_BINARY,
&runtime_dir.join("form.ico"),
)?),
search_icon: Some(extract_icon(ICON_BINARY, &runtime_dir.join("search.png"))?),
wizard_icon: Some(extract_icon(WINDOWS_LOGO_ICO_BINARY, &runtime_dir.join("wizard.ico"))?),
tray_icon_normal: Some(extract_icon(WINDOWS_NORMAL_DARK_ICO_BINARY, &runtime_dir.join("normal.ico"))?),
tray_icon_disabled: Some(extract_icon(WINDOWS_DISABLED_DARK_ICO_BINARY, &runtime_dir.join("disabled.ico"))?),
wizard_icon: Some(extract_icon(
WINDOWS_LOGO_ICO_BINARY,
&runtime_dir.join("wizard.ico"),
)?),
tray_icon_normal: Some(extract_icon(
WINDOWS_NORMAL_DARK_ICO_BINARY,
&runtime_dir.join("normal.ico"),
)?),
tray_icon_disabled: Some(extract_icon(
WINDOWS_DISABLED_DARK_ICO_BINARY,
&runtime_dir.join("disabled.ico"),
)?),
logo: Some(extract_icon(ICON_BINARY, &runtime_dir.join("icon.png"))?),
logo_no_background: Some(extract_icon(LOGO_NO_BACKGROUND_BINARY, &runtime_dir.join("icon_no_background.png"))?),
tray_explain_image: Some(extract_icon(WINDOWS_TRAY_EXPLAIN_IMAGE, &runtime_dir.join("tray_explain_image.png"))?),
logo_no_background: Some(extract_icon(
LOGO_NO_BACKGROUND_BINARY,
&runtime_dir.join("icon_no_background.png"),
)?),
tray_explain_image: Some(extract_icon(
WINDOWS_TRAY_EXPLAIN_IMAGE,
&runtime_dir.join("tray_explain_image.png"),
)?),
..Default::default()
})
}
@ -85,13 +102,31 @@ pub fn load_icon_paths(runtime_dir: &Path) -> Result<IconPaths> {
Ok(IconPaths {
search_icon: Some(extract_icon(ICON_BINARY, &runtime_dir.join("search.png"))?),
tray_icon_normal: Some(extract_icon(MAC_BINARY, &runtime_dir.join("normal.png"))?),
tray_icon_disabled: Some(extract_icon(MAC_DISABLED_BINARY, &runtime_dir.join("disabled.png"))?),
tray_icon_system_disabled: Some(extract_icon(MAC_SYSTEM_DISABLED_BINARY, &runtime_dir.join("systemdisabled.png"))?),
tray_icon_disabled: Some(extract_icon(
MAC_DISABLED_BINARY,
&runtime_dir.join("disabled.png"),
)?),
tray_icon_system_disabled: Some(extract_icon(
MAC_SYSTEM_DISABLED_BINARY,
&runtime_dir.join("systemdisabled.png"),
)?),
logo: Some(extract_icon(ICON_BINARY, &runtime_dir.join("icon.png"))?),
logo_no_background: Some(extract_icon(LOGO_NO_BACKGROUND_BINARY, &runtime_dir.join("icon_no_background.png"))?),
accessibility_image_1: Some(extract_icon(MAC_ACCESSIBILITY_1_BINARY, &runtime_dir.join("accessibility_1.png"))?),
accessibility_image_2: Some(extract_icon(MAC_ACCESSIBILITY_2_BINARY, &runtime_dir.join("accessibility_2.png"))?),
tray_explain_image: Some(extract_icon(MAC_STATUS_ICON_EXPLAIN_IMAGE, &runtime_dir.join("icon_explain_image.png"))?),
logo_no_background: Some(extract_icon(
LOGO_NO_BACKGROUND_BINARY,
&runtime_dir.join("icon_no_background.png"),
)?),
accessibility_image_1: Some(extract_icon(
MAC_ACCESSIBILITY_1_BINARY,
&runtime_dir.join("accessibility_1.png"),
)?),
accessibility_image_2: Some(extract_icon(
MAC_ACCESSIBILITY_2_BINARY,
&runtime_dir.join("accessibility_2.png"),
)?),
tray_explain_image: Some(extract_icon(
MAC_STATUS_ICON_EXPLAIN_IMAGE,
&runtime_dir.join("icon_explain_image.png"),
)?),
..Default::default()
})
}
@ -101,7 +136,10 @@ pub fn load_icon_paths(runtime_dir: &Path) -> Result<IconPaths> {
Ok(IconPaths {
logo: Some(extract_icon(ICON_BINARY, &runtime_dir.join("iconv2.png"))?),
search_icon: Some(extract_icon(ICON_BINARY, &runtime_dir.join("search.png"))?),
logo_no_background: Some(extract_icon(LOGO_NO_BACKGROUND_BINARY, &runtime_dir.join("icon_no_background.png"))?),
logo_no_background: Some(extract_icon(
LOGO_NO_BACKGROUND_BINARY,
&runtime_dir.join("icon_no_background.png"),
)?),
..Default::default()
})
}

View File

@ -18,9 +18,9 @@
*/
use anyhow::Result;
use espanso_ipc::{IPCServer, IPCClient};
use espanso_ipc::{IPCClient, IPCServer};
use serde::{Deserialize, Serialize};
use std::path::Path;
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
pub enum IPCEvent {
@ -40,14 +40,10 @@ pub fn create_ipc_client_to_worker(runtime_dir: &Path) -> Result<impl IPCClient<
create_ipc_client(runtime_dir, "workerv2")
}
fn create_ipc_server(
runtime_dir: &Path,
name: &str,
) -> Result<impl IPCServer<IPCEvent>> {
fn create_ipc_server(runtime_dir: &Path, name: &str) -> Result<impl IPCServer<IPCEvent>> {
espanso_ipc::server(&format!("espanso{}", name), runtime_dir)
}
fn create_ipc_client(runtime_dir: &Path, target_process: &str) -> Result<impl IPCClient<IPCEvent>> {
let client = espanso_ipc::client(&format!("espanso{}", target_process), runtime_dir)?;
Ok(client)

View File

@ -42,8 +42,12 @@ impl Lock {
.write(true)
.create(true)
.open(&lock_file_path)
.unwrap_or_else(|_| panic!("unable to create reference to lock file: {:?}",
lock_file_path));
.unwrap_or_else(|_| {
panic!(
"unable to create reference to lock file: {:?}",
lock_file_path
)
});
if lock_file.try_lock_exclusive().is_ok() {
Some(Lock { lock_file })

View File

@ -76,12 +76,8 @@ impl Write for FileProxy {
Ok(mut lock) => {
match &mut (*lock) {
// Write to the memory buffer until a file is ready
Output::Memory(buffer) => {
buffer.write(buf)
}
Output::File(output) => {
output.write(buf)
}
Output::Memory(buffer) => buffer.write(buf),
Output::File(output) => output.write(buf),
}
}
Err(_) => Err(std::io::Error::new(
@ -93,16 +89,10 @@ impl Write for FileProxy {
fn flush(&mut self) -> std::io::Result<()> {
match self.output.lock() {
Ok(mut lock) => {
match &mut (*lock) {
Output::Memory(buffer) => {
buffer.flush()
}
Output::File(output) => {
output.flush()
}
}
}
Ok(mut lock) => match &mut (*lock) {
Output::Memory(buffer) => buffer.flush(),
Output::File(output) => output.flush(),
},
Err(_) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
"lock poison error",

View File

@ -478,10 +478,7 @@ fn main() {
)];
if !handler.disable_logs_terminal_output {
outputs.insert(
0,
TermLogger::new(log_level, config, TerminalMode::Mixed),
);
outputs.insert(0, TermLogger::new(log_level, config, TerminalMode::Mixed));
}
CombinedLogger::init(outputs).expect("unable to initialize logs");

View File

@ -23,8 +23,8 @@ pub mod generic_terminal_x11;
pub mod kitty_terminal_x11;
pub mod konsole_terminal_x11;
pub mod libreoffice_writer_x11;
pub mod simple_terminal_x11;
pub mod simple_terminal_2_x11;
pub mod simple_terminal_x11;
pub mod terminator_terminal_x11;
pub mod termite_terminal_x11;
pub mod tilix_terminal_x11;

View File

@ -18,7 +18,7 @@
*/
use anyhow::Result;
use std::{path::PathBuf};
use std::path::PathBuf;
use thiserror::Error;
pub fn is_espanso_in_path() -> bool {

View File

@ -50,10 +50,9 @@ pub fn add_espanso_to_path(prompt_when_necessary: bool) -> Result<()> {
target_link_path.to_string_lossy(),
);
let mut child = std::process::Command::new("osascript").args(&[
"-e",
&params,
]).spawn()?;
let mut child = std::process::Command::new("osascript")
.args(&["-e", &params])
.spawn()?;
let result = child.wait()?;
if !result.success() {
@ -90,10 +89,9 @@ pub fn remove_espanso_from_path(prompt_when_necessary: bool) -> Result<()> {
target_link_path.to_string_lossy(),
);
let mut child = std::process::Command::new("osascript").args(&[
"-e",
&params,
]).spawn()?;
let mut child = std::process::Command::new("osascript")
.args(&["-e", &params])
.spawn()?;
let result = child.wait()?;
if !result.success() {

View File

@ -22,24 +22,24 @@ mod macos;
#[cfg(target_os = "macos")]
pub use macos::add_espanso_to_path;
#[cfg(target_os = "macos")]
pub use macos::remove_espanso_from_path;
#[cfg(target_os = "macos")]
pub use macos::is_espanso_in_path;
#[cfg(target_os = "macos")]
pub use macos::remove_espanso_from_path;
#[cfg(target_os = "windows")]
mod win;
#[cfg(target_os = "windows")]
pub use win::add_espanso_to_path;
#[cfg(target_os = "windows")]
pub use win::remove_espanso_from_path;
#[cfg(target_os = "windows")]
pub use win::is_espanso_in_path;
#[cfg(target_os = "windows")]
pub use win::remove_espanso_from_path;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use linux::add_espanso_to_path;
#[cfg(target_os = "linux")]
pub use linux::remove_espanso_from_path;
#[cfg(target_os = "linux")]
pub use linux::is_espanso_in_path;
#[cfg(target_os = "linux")]
pub use linux::remove_espanso_from_path;

View File

@ -72,7 +72,9 @@ impl<KVSType: KVS> Preferences for DefaultPreferences<KVSType> {
}
fn should_display_troubleshoot_for_non_fatal_errors(&self) -> bool {
self.get(SHOULD_DISPLAY_TROUBLESHOOT_FOR_NON_FATAL_ERRORS).unwrap_or(true)
self
.get(SHOULD_DISPLAY_TROUBLESHOOT_FOR_NON_FATAL_ERRORS)
.unwrap_or(true)
}
fn set_should_display_troubleshoot_for_non_fatal_errors(&self, value: bool) {

View File

@ -17,8 +17,8 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::path::Path;
use anyhow::Result;
use std::path::Path;
mod default;