From d269677b2cbae7f867616b787a1b57cff9341bc6 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Wed, 30 Mar 2022 01:47:24 -0600 Subject: [PATCH] tree-wide: format code --- build.rs | 4 +++- src/frontend/rest/services/authentication.rs | 8 ++++++-- src/frontend/rest/services/install.rs | 16 +++++++++++----- src/frontend/rest/services/verify_path.rs | 9 ++++----- src/frontend/ui/mod.rs | 5 +++-- src/installer.rs | 2 +- src/native/mod.rs | 20 ++++++++++++++------ src/sources/types.rs | 4 +--- src/tasks/check_authorization.rs | 4 +++- src/tasks/download_pkg.rs | 4 +++- src/tasks/install.rs | 9 ++++++--- src/tasks/install_desktop_shortcut.rs | 20 +++++++++++++------- src/tasks/launch_installed_on_exit.rs | 20 +++++++++++--------- src/tasks/mod.rs | 2 +- src/tasks/uninstall_pkg.rs | 2 +- 15 files changed, 81 insertions(+), 48 deletions(-) diff --git a/build.rs b/build.rs index cb64147..c6c3506 100644 --- a/build.rs +++ b/build.rs @@ -105,7 +105,9 @@ fn main() { // bundle the icon let mut f = File::create(output_dir.join("icon-data.bin")).unwrap(); let icon_file = image::open("ui/public/favicon.ico").expect("Unable to read the icon file"); - let icon_data = icon_file.resize_exact(48, 48, FilterType::Triangle).to_rgba8(); + let icon_data = icon_file + .resize_exact(48, 48, FilterType::Triangle) + .to_rgba8(); f.write_all(&icon_data.into_vec()).unwrap(); // Build and deploy frontend files diff --git a/src/frontend/rest/services/authentication.rs b/src/frontend/rest/services/authentication.rs index 2547bfd..cae1613 100644 --- a/src/frontend/rest/services/authentication.rs +++ b/src/frontend/rest/services/authentication.rs @@ -130,8 +130,12 @@ pub fn validate_token( let pub_key = if pub_key_base64.is_empty() { vec![] } else { - base64::decode(&pub_key_base64) - .map_err(|e| format!("Configured public key was not empty and did not decode as base64 {:?}", e))? + base64::decode(&pub_key_base64).map_err(|e| { + format!( + "Configured public key was not empty and did not decode as base64 {:?}", + e + ) + })? }; // Configure validation for audience and issuer if the configuration provides it diff --git a/src/frontend/rest/services/install.rs b/src/frontend/rest/services/install.rs index 68cdc9d..f57441a 100644 --- a/src/frontend/rest/services/install.rs +++ b/src/frontend/rest/services/install.rs @@ -23,13 +23,13 @@ pub fn handle(service: &WebService, req: Request) -> Future { Box::new(req.body().concat2().map(move |b| { let results = form_urlencoded::parse(b.as_ref()) - .into_owned() - .collect::>(); - + .into_owned() + .collect::>(); + let mut to_install = Vec::new(); let mut path: Option = None; let mut force_install = false; - let mut install_desktop_shortcut= false; + let mut install_desktop_shortcut = false; // Transform results into just an array of stuff to install for (key, value) in &results { @@ -66,7 +66,13 @@ pub fn handle(service: &WebService, req: Request) -> Future { framework.set_install_dir(&path); } - if let Err(v) = framework.install(to_install, &sender, new_install, install_desktop_shortcut, force_install) { + if let Err(v) = framework.install( + to_install, + &sender, + new_install, + install_desktop_shortcut, + force_install, + ) { error!("Install error occurred: {:?}", v); if let Err(v) = sender.send(InstallMessage::Error(v)) { error!("Failed to send install error: {:?}", v); diff --git a/src/frontend/rest/services/verify_path.rs b/src/frontend/rest/services/verify_path.rs index f8ca0c3..1550af3 100644 --- a/src/frontend/rest/services/verify_path.rs +++ b/src/frontend/rest/services/verify_path.rs @@ -18,7 +18,6 @@ use crate::logging::LoggingErrors; use std::collections::HashMap; use std::path::PathBuf; - /// Struct used by serde to send a JSON payload to the client containing an optional value. #[derive(Serialize)] struct VerifyResponse { @@ -28,8 +27,8 @@ struct VerifyResponse { pub fn handle(_service: &WebService, req: Request) -> Future { Box::new(req.body().concat2().map(move |b| { let results = form_urlencoded::parse(b.as_ref()) - .into_owned() - .collect::>(); + .into_owned() + .collect::>(); let mut exists = false; if let Some(path) = results.get("path") { let path = PathBuf::from(path); @@ -37,10 +36,10 @@ pub fn handle(_service: &WebService, req: Request) -> Future { } let response = VerifyResponse { exists }; - + let file = serde_json::to_string(&response) .log_expect("Failed to render JSON payload of default path object"); - + Response::new() .with_header(ContentLength(file.len() as u64)) .with_header(ContentType::json()) diff --git a/src/frontend/ui/mod.rs b/src/frontend/ui/mod.rs index 943309d..b0ff600 100644 --- a/src/frontend/ui/mod.rs +++ b/src/frontend/ui/mod.rs @@ -8,7 +8,7 @@ use wry::{ dpi::LogicalSize, event::{Event, StartCause, WindowEvent}, event_loop::{ControlFlow, EventLoop}, - window::{WindowBuilder, Icon}, + window::{Icon, WindowBuilder}, }, webview::{RpcResponse, WebViewBuilder}, }; @@ -32,7 +32,8 @@ pub fn start_ui(app_name: &str, http_address: &str, is_launcher: bool) -> Result }; info!("Spawning web view instance"); - let window_icon = Icon::from_rgba(ICON_DATA.to_vec(), 48, 48).log_expect("Unable to construct window icon"); + let window_icon = + Icon::from_rgba(ICON_DATA.to_vec(), 48, 48).log_expect("Unable to construct window icon"); let event_loop = EventLoop::new(); let window = WindowBuilder::new() .with_title(format!("{} Installer", app_name)) diff --git a/src/installer.rs b/src/installer.rs index 99ddba3..9eae9ff 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -211,7 +211,7 @@ impl InstallerFramework { uninstall_items, fresh_install, create_desktop_shortcuts, - force_install + force_install, }); let mut tree = DependencyTree::build(task); diff --git a/src/native/mod.rs b/src/native/mod.rs index db3566e..71db9fe 100644 --- a/src/native/mod.rs +++ b/src/native/mod.rs @@ -200,10 +200,16 @@ mod natives { .to_str() .log_expect("Unable to convert log path to string") .replace(" ", "\\ "); - - let install_path = path.to_str().log_expect("Unable to convert path to string").replace(" ", "\\ "); - let target_arguments = format!("/C choice /C Y /N /D Y /T 2 & del {} {} & rmdir {}", tool, log, install_path); + let install_path = path + .to_str() + .log_expect("Unable to convert path to string") + .replace(" ", "\\ "); + + let target_arguments = format!( + "/C choice /C Y /N /D Y /T 2 & del {} {} & rmdir {}", + tool, log, install_path + ); info!("Launching cmd with {:?}", target_arguments); @@ -333,13 +339,13 @@ mod natives { #[cfg(not(windows))] mod natives { - use std::fs::{remove_file, remove_dir}; + use std::fs::{remove_dir, remove_file}; use std::env; use crate::logging::LoggingErrors; - use sysinfo::{ProcessExt, SystemExt, PidExt}; + use sysinfo::{PidExt, ProcessExt, SystemExt}; use dirs; @@ -423,7 +429,9 @@ mod natives { /// Cleans up the installer pub fn burn_on_exit(app_name: &str) { let current_exe = env::current_exe().log_expect("Current executable could not be found"); - let exe_dir = current_exe.parent().log_expect("Current executable directory cannot be found"); + let exe_dir = current_exe + .parent() + .log_expect("Current executable directory cannot be found"); if let Err(e) = remove_file(exe_dir.join(format!("{}_installer.log", app_name))) { // No regular logging now. diff --git a/src/sources/types.rs b/src/sources/types.rs index cc16fd9..1547c1b 100644 --- a/src/sources/types.rs +++ b/src/sources/types.rs @@ -23,9 +23,7 @@ impl Version { fn coarse_into_semver(&self) -> SemverVersion { match *self { Version::Semver(ref version) => version.to_owned(), - Version::Integer(ref version) => { - SemverVersion::new(version.to_owned(), 0u64, 0u64) - } + Version::Integer(ref version) => SemverVersion::new(version.to_owned(), 0u64, 0u64), } } diff --git a/src/tasks/check_authorization.rs b/src/tasks/check_authorization.rs index 05e6be6..9c9731a 100644 --- a/src/tasks/check_authorization.rs +++ b/src/tasks/check_authorization.rs @@ -22,7 +22,9 @@ impl Task for CheckAuthorizationTask { ) -> Result { assert_eq!(input.len(), 1); - let params = input.pop().log_expect("Check Authorization Task should have input from resolver!"); + let params = input + .pop() + .log_expect("Check Authorization Task should have input from resolver!"); let (version, file) = match params { TaskParamType::File(v, f) => Ok((v, f)), _ => Err("Unexpected TaskParamType in CheckAuthorization: {:?}"), diff --git a/src/tasks/download_pkg.rs b/src/tasks/download_pkg.rs index 7d033cb..a418b53 100644 --- a/src/tasks/download_pkg.rs +++ b/src/tasks/download_pkg.rs @@ -28,7 +28,9 @@ impl Task for DownloadPackageTask { ) -> Result { assert_eq!(input.len(), 1); - let file = input.pop().log_expect("Download Package Task should have input from resolver!"); + let file = input + .pop() + .log_expect("Download Package Task should have input from resolver!"); let (version, file, auth) = match file { TaskParamType::Authentication(v, f, auth) => (v, f, auth), _ => return Err("Unexpected param type to download package".to_string()), diff --git a/src/tasks/install.rs b/src/tasks/install.rs index 742db64..bb161d5 100644 --- a/src/tasks/install.rs +++ b/src/tasks/install.rs @@ -6,10 +6,10 @@ use crate::tasks::ensure_only_instance::EnsureOnlyInstanceTask; use crate::tasks::install_dir::VerifyInstallDirTask; use crate::tasks::install_global_shortcut::InstallGlobalShortcutsTask; use crate::tasks::install_pkg::InstallPackageTask; +use crate::tasks::launch_installed_on_exit::LaunchOnExitTask; use crate::tasks::remove_target_dir::RemoveTargetDirTask; use crate::tasks::save_executable::SaveExecutableTask; use crate::tasks::uninstall_pkg::UninstallPackageTask; -use crate::tasks::launch_installed_on_exit::LaunchOnExitTask; use crate::tasks::Task; use crate::tasks::TaskDependency; @@ -72,7 +72,10 @@ impl Task for InstallTask { for item in &self.items { elements.push(TaskDependency::build( TaskOrdering::Pre, - Box::new(InstallPackageTask { name: item.clone(), create_desktop_shortcuts: self.create_desktop_shortcuts }), + Box::new(InstallPackageTask { + name: item.clone(), + create_desktop_shortcuts: self.create_desktop_shortcuts, + }), )); } @@ -89,7 +92,7 @@ impl Task for InstallTask { elements.push(TaskDependency::build( TaskOrdering::Post, - Box::new(LaunchOnExitTask {}) + Box::new(LaunchOnExitTask {}), )) } diff --git a/src/tasks/install_desktop_shortcut.rs b/src/tasks/install_desktop_shortcut.rs index 819f63b..f0a39d1 100644 --- a/src/tasks/install_desktop_shortcut.rs +++ b/src/tasks/install_desktop_shortcut.rs @@ -30,7 +30,10 @@ impl Task for InstallDesktopShortcutTask { } messenger(&TaskMessage::DisplayMessage( - &format!("Generating desktop shortcuts for package {:?}...", self.name), + &format!( + "Generating desktop shortcuts for package {:?}...", + self.name + ), 0.0, )); @@ -51,12 +54,12 @@ impl Task for InstallDesktopShortcutTask { .as_ref() .log_expect("Should have packages by now") .packages - { - if self.name == description.name { - metadata = Some(description.clone()); - break; - } + { + if self.name == description.name { + metadata = Some(description.clone()); + break; } + } let package = match metadata { Some(v) => v, @@ -108,6 +111,9 @@ impl Task for InstallDesktopShortcutTask { } fn name(&self) -> String { - format!("InstallDesktopShortcutTask (for {:?}, should_run = {:?})", self.name, self.should_run) + format!( + "InstallDesktopShortcutTask (for {:?}, should_run = {:?})", + self.name, self.should_run + ) } } diff --git a/src/tasks/launch_installed_on_exit.rs b/src/tasks/launch_installed_on_exit.rs index f286932..2655f47 100644 --- a/src/tasks/launch_installed_on_exit.rs +++ b/src/tasks/launch_installed_on_exit.rs @@ -16,7 +16,6 @@ use crate::logging::LoggingErrors; pub struct LaunchOnExitTask {} impl Task for LaunchOnExitTask { - fn execute( &mut self, _: Vec, @@ -25,7 +24,7 @@ impl Task for LaunchOnExitTask { ) -> Result { let pkg = &context.database.packages.first(); if pkg.is_none() { - return Ok(TaskParamType::None) + return Ok(TaskParamType::None); } let pkg = pkg.unwrap(); @@ -41,12 +40,12 @@ impl Task for LaunchOnExitTask { .as_ref() .log_expect("Should have packages by now") .packages - { - if pkg.name == description.name { - metadata = Some(description.clone()); - break; - } + { + if pkg.name == description.name { + metadata = Some(description.clone()); + break; } + } let package_desc = match metadata { Some(v) => v, @@ -58,7 +57,10 @@ impl Task for LaunchOnExitTask { // copy the path to the actual exe into launcher_path so it'll load it on exit context.launcher_path = shortcut.map(|s| { - path.join(s.relative_path.clone()).to_str().map(|t| { t.to_string() }).unwrap() + path.join(s.relative_path.clone()) + .to_str() + .map(|t| t.to_string()) + .unwrap() }); Ok(TaskParamType::None) @@ -71,4 +73,4 @@ impl Task for LaunchOnExitTask { fn name(&self) -> String { "LaunchOnExitTask".to_string() } -} \ No newline at end of file +} diff --git a/src/tasks/mod.rs b/src/tasks/mod.rs index f1d3f67..67d882e 100644 --- a/src/tasks/mod.rs +++ b/src/tasks/mod.rs @@ -19,6 +19,7 @@ pub mod install_global_shortcut; pub mod install_pkg; pub mod install_shortcuts; pub mod launch_installed_on_exit; +pub mod remove_target_dir; pub mod resolver; pub mod save_database; pub mod save_executable; @@ -26,7 +27,6 @@ pub mod uninstall; pub mod uninstall_global_shortcut; pub mod uninstall_pkg; pub mod uninstall_shortcuts; -pub mod remove_target_dir; /// An abstraction over the various parameters that can be passed around. pub enum TaskParamType { diff --git a/src/tasks/uninstall_pkg.rs b/src/tasks/uninstall_pkg.rs index ebdc85f..cfae816 100644 --- a/src/tasks/uninstall_pkg.rs +++ b/src/tasks/uninstall_pkg.rs @@ -64,7 +64,7 @@ impl Task for UninstallPackageTask { )); let mut directories = Vec::new(); - + let max = package.files.len(); for (i, file) in package.files.iter().enumerate() { let name = file.clone();