tree-wide: format code

This commit is contained in:
liushuyu 2022-03-30 01:47:24 -06:00
parent 9a27b24f05
commit d269677b2c
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437
15 changed files with 81 additions and 48 deletions

View File

@ -105,7 +105,9 @@ fn main() {
// bundle the icon // bundle the icon
let mut f = File::create(output_dir.join("icon-data.bin")).unwrap(); 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_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(); f.write_all(&icon_data.into_vec()).unwrap();
// Build and deploy frontend files // Build and deploy frontend files

View File

@ -130,8 +130,12 @@ pub fn validate_token(
let pub_key = if pub_key_base64.is_empty() { let pub_key = if pub_key_base64.is_empty() {
vec![] vec![]
} else { } else {
base64::decode(&pub_key_base64) base64::decode(&pub_key_base64).map_err(|e| {
.map_err(|e| format!("Configured public key was not empty and did not decode as base64 {:?}", 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 // Configure validation for audience and issuer if the configuration provides it

View File

@ -23,13 +23,13 @@ pub fn handle(service: &WebService, req: Request) -> Future {
Box::new(req.body().concat2().map(move |b| { Box::new(req.body().concat2().map(move |b| {
let results = form_urlencoded::parse(b.as_ref()) let results = form_urlencoded::parse(b.as_ref())
.into_owned() .into_owned()
.collect::<HashMap<String, String>>(); .collect::<HashMap<String, String>>();
let mut to_install = Vec::new(); let mut to_install = Vec::new();
let mut path: Option<String> = None; let mut path: Option<String> = None;
let mut force_install = false; 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 // Transform results into just an array of stuff to install
for (key, value) in &results { for (key, value) in &results {
@ -66,7 +66,13 @@ pub fn handle(service: &WebService, req: Request) -> Future {
framework.set_install_dir(&path); 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); error!("Install error occurred: {:?}", v);
if let Err(v) = sender.send(InstallMessage::Error(v)) { if let Err(v) = sender.send(InstallMessage::Error(v)) {
error!("Failed to send install error: {:?}", v); error!("Failed to send install error: {:?}", v);

View File

@ -18,7 +18,6 @@ use crate::logging::LoggingErrors;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::PathBuf; use std::path::PathBuf;
/// Struct used by serde to send a JSON payload to the client containing an optional value. /// Struct used by serde to send a JSON payload to the client containing an optional value.
#[derive(Serialize)] #[derive(Serialize)]
struct VerifyResponse { struct VerifyResponse {
@ -28,8 +27,8 @@ struct VerifyResponse {
pub fn handle(_service: &WebService, req: Request) -> Future { pub fn handle(_service: &WebService, req: Request) -> Future {
Box::new(req.body().concat2().map(move |b| { Box::new(req.body().concat2().map(move |b| {
let results = form_urlencoded::parse(b.as_ref()) let results = form_urlencoded::parse(b.as_ref())
.into_owned() .into_owned()
.collect::<HashMap<String, String>>(); .collect::<HashMap<String, String>>();
let mut exists = false; let mut exists = false;
if let Some(path) = results.get("path") { if let Some(path) = results.get("path") {
let path = PathBuf::from(path); let path = PathBuf::from(path);

View File

@ -8,7 +8,7 @@ use wry::{
dpi::LogicalSize, dpi::LogicalSize,
event::{Event, StartCause, WindowEvent}, event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
window::{WindowBuilder, Icon}, window::{Icon, WindowBuilder},
}, },
webview::{RpcResponse, WebViewBuilder}, 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"); 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 event_loop = EventLoop::new();
let window = WindowBuilder::new() let window = WindowBuilder::new()
.with_title(format!("{} Installer", app_name)) .with_title(format!("{} Installer", app_name))

View File

@ -211,7 +211,7 @@ impl InstallerFramework {
uninstall_items, uninstall_items,
fresh_install, fresh_install,
create_desktop_shortcuts, create_desktop_shortcuts,
force_install force_install,
}); });
let mut tree = DependencyTree::build(task); let mut tree = DependencyTree::build(task);

View File

@ -201,9 +201,15 @@ mod natives {
.log_expect("Unable to convert log path to string") .log_expect("Unable to convert log path to string")
.replace(" ", "\\ "); .replace(" ", "\\ ");
let install_path = path.to_str().log_expect("Unable to convert 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 target_arguments = format!(
"/C choice /C Y /N /D Y /T 2 & del {} {} & rmdir {}",
tool, log, install_path
);
info!("Launching cmd with {:?}", target_arguments); info!("Launching cmd with {:?}", target_arguments);
@ -333,13 +339,13 @@ mod natives {
#[cfg(not(windows))] #[cfg(not(windows))]
mod natives { mod natives {
use std::fs::{remove_file, remove_dir}; use std::fs::{remove_dir, remove_file};
use std::env; use std::env;
use crate::logging::LoggingErrors; use crate::logging::LoggingErrors;
use sysinfo::{ProcessExt, SystemExt, PidExt}; use sysinfo::{PidExt, ProcessExt, SystemExt};
use dirs; use dirs;
@ -423,7 +429,9 @@ mod natives {
/// Cleans up the installer /// Cleans up the installer
pub fn burn_on_exit(app_name: &str) { pub fn burn_on_exit(app_name: &str) {
let current_exe = env::current_exe().log_expect("Current executable could not be found"); 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))) { if let Err(e) = remove_file(exe_dir.join(format!("{}_installer.log", app_name))) {
// No regular logging now. // No regular logging now.

View File

@ -23,9 +23,7 @@ impl Version {
fn coarse_into_semver(&self) -> SemverVersion { fn coarse_into_semver(&self) -> SemverVersion {
match *self { match *self {
Version::Semver(ref version) => version.to_owned(), Version::Semver(ref version) => version.to_owned(),
Version::Integer(ref version) => { Version::Integer(ref version) => SemverVersion::new(version.to_owned(), 0u64, 0u64),
SemverVersion::new(version.to_owned(), 0u64, 0u64)
}
} }
} }

View File

@ -22,7 +22,9 @@ impl Task for CheckAuthorizationTask {
) -> Result<TaskParamType, String> { ) -> Result<TaskParamType, String> {
assert_eq!(input.len(), 1); 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 { let (version, file) = match params {
TaskParamType::File(v, f) => Ok((v, f)), TaskParamType::File(v, f) => Ok((v, f)),
_ => Err("Unexpected TaskParamType in CheckAuthorization: {:?}"), _ => Err("Unexpected TaskParamType in CheckAuthorization: {:?}"),

View File

@ -28,7 +28,9 @@ impl Task for DownloadPackageTask {
) -> Result<TaskParamType, String> { ) -> Result<TaskParamType, String> {
assert_eq!(input.len(), 1); 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 { let (version, file, auth) = match file {
TaskParamType::Authentication(v, f, auth) => (v, f, auth), TaskParamType::Authentication(v, f, auth) => (v, f, auth),
_ => return Err("Unexpected param type to download package".to_string()), _ => return Err("Unexpected param type to download package".to_string()),

View File

@ -6,10 +6,10 @@ use crate::tasks::ensure_only_instance::EnsureOnlyInstanceTask;
use crate::tasks::install_dir::VerifyInstallDirTask; use crate::tasks::install_dir::VerifyInstallDirTask;
use crate::tasks::install_global_shortcut::InstallGlobalShortcutsTask; use crate::tasks::install_global_shortcut::InstallGlobalShortcutsTask;
use crate::tasks::install_pkg::InstallPackageTask; use crate::tasks::install_pkg::InstallPackageTask;
use crate::tasks::launch_installed_on_exit::LaunchOnExitTask;
use crate::tasks::remove_target_dir::RemoveTargetDirTask; use crate::tasks::remove_target_dir::RemoveTargetDirTask;
use crate::tasks::save_executable::SaveExecutableTask; use crate::tasks::save_executable::SaveExecutableTask;
use crate::tasks::uninstall_pkg::UninstallPackageTask; use crate::tasks::uninstall_pkg::UninstallPackageTask;
use crate::tasks::launch_installed_on_exit::LaunchOnExitTask;
use crate::tasks::Task; use crate::tasks::Task;
use crate::tasks::TaskDependency; use crate::tasks::TaskDependency;
@ -72,7 +72,10 @@ impl Task for InstallTask {
for item in &self.items { for item in &self.items {
elements.push(TaskDependency::build( elements.push(TaskDependency::build(
TaskOrdering::Pre, 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( elements.push(TaskDependency::build(
TaskOrdering::Post, TaskOrdering::Post,
Box::new(LaunchOnExitTask {}) Box::new(LaunchOnExitTask {}),
)) ))
} }

View File

@ -30,7 +30,10 @@ impl Task for InstallDesktopShortcutTask {
} }
messenger(&TaskMessage::DisplayMessage( messenger(&TaskMessage::DisplayMessage(
&format!("Generating desktop shortcuts for package {:?}...", self.name), &format!(
"Generating desktop shortcuts for package {:?}...",
self.name
),
0.0, 0.0,
)); ));
@ -51,12 +54,12 @@ impl Task for InstallDesktopShortcutTask {
.as_ref() .as_ref()
.log_expect("Should have packages by now") .log_expect("Should have packages by now")
.packages .packages
{ {
if self.name == description.name { if self.name == description.name {
metadata = Some(description.clone()); metadata = Some(description.clone());
break; break;
}
} }
}
let package = match metadata { let package = match metadata {
Some(v) => v, Some(v) => v,
@ -108,6 +111,9 @@ impl Task for InstallDesktopShortcutTask {
} }
fn name(&self) -> String { fn name(&self) -> String {
format!("InstallDesktopShortcutTask (for {:?}, should_run = {:?})", self.name, self.should_run) format!(
"InstallDesktopShortcutTask (for {:?}, should_run = {:?})",
self.name, self.should_run
)
} }
} }

View File

@ -16,7 +16,6 @@ use crate::logging::LoggingErrors;
pub struct LaunchOnExitTask {} pub struct LaunchOnExitTask {}
impl Task for LaunchOnExitTask { impl Task for LaunchOnExitTask {
fn execute( fn execute(
&mut self, &mut self,
_: Vec<TaskParamType>, _: Vec<TaskParamType>,
@ -25,7 +24,7 @@ impl Task for LaunchOnExitTask {
) -> Result<TaskParamType, String> { ) -> Result<TaskParamType, String> {
let pkg = &context.database.packages.first(); let pkg = &context.database.packages.first();
if pkg.is_none() { if pkg.is_none() {
return Ok(TaskParamType::None) return Ok(TaskParamType::None);
} }
let pkg = pkg.unwrap(); let pkg = pkg.unwrap();
@ -41,12 +40,12 @@ impl Task for LaunchOnExitTask {
.as_ref() .as_ref()
.log_expect("Should have packages by now") .log_expect("Should have packages by now")
.packages .packages
{ {
if pkg.name == description.name { if pkg.name == description.name {
metadata = Some(description.clone()); metadata = Some(description.clone());
break; break;
}
} }
}
let package_desc = match metadata { let package_desc = match metadata {
Some(v) => v, 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 // copy the path to the actual exe into launcher_path so it'll load it on exit
context.launcher_path = shortcut.map(|s| { 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) Ok(TaskParamType::None)

View File

@ -19,6 +19,7 @@ pub mod install_global_shortcut;
pub mod install_pkg; pub mod install_pkg;
pub mod install_shortcuts; pub mod install_shortcuts;
pub mod launch_installed_on_exit; pub mod launch_installed_on_exit;
pub mod remove_target_dir;
pub mod resolver; pub mod resolver;
pub mod save_database; pub mod save_database;
pub mod save_executable; pub mod save_executable;
@ -26,7 +27,6 @@ pub mod uninstall;
pub mod uninstall_global_shortcut; pub mod uninstall_global_shortcut;
pub mod uninstall_pkg; pub mod uninstall_pkg;
pub mod uninstall_shortcuts; pub mod uninstall_shortcuts;
pub mod remove_target_dir;
/// An abstraction over the various parameters that can be passed around. /// An abstraction over the various parameters that can be passed around.
pub enum TaskParamType { pub enum TaskParamType {