Minor QoL tweaks

This commit is contained in:
James 2018-10-01 11:27:31 +10:00
parent 36179dcf82
commit 245ea31297
9 changed files with 42 additions and 30 deletions

View File

@ -35,6 +35,7 @@ pub fn file_from_string(file_path: &str) -> Option<(String, &'static [u8])> {
"/index.html",
"/favicon.ico",
"/logo.png",
"/how-to-open.png",
"/css/bulma.min.css",
"/css/main.css",
"/fonts/roboto-v18-latin-regular.eot",

View File

@ -9,16 +9,27 @@ use std::time::Duration;
use reqwest::Client;
/// Asserts that a URL is valid HTTPS, else returns an error.
pub fn assert_ssl(url: &str) -> Result<(), String> {
if url.starts_with("https://") {
Ok(())
} else {
Err(format!("Specified URL was not https"))
}
}
/// Builds a customised HTTP client.
pub fn build_client() -> Result<Client, String> {
Client::builder()
.timeout(Duration::from_secs(8))
.build()
.map_err(|x| format!("Unable to build cient: {:?}", x))
.map_err(|x| format!("Unable to build client: {:?}", x))
}
/// Downloads a text file from the specified URL.
pub fn download_text(url: &str) -> Result<String, String> {
assert_ssl(url)?;
let mut client = build_client()?
.get(url)
.send()
@ -34,6 +45,8 @@ pub fn stream_file<F>(url: &str, mut callback: F) -> Result<(), String>
where
F: FnMut(Vec<u8>, u64) -> (),
{
assert_ssl(url)?;
let mut client = build_client()?
.get(url)
.send()

View File

@ -7,7 +7,7 @@ use log;
use std::fmt::Debug;
use std::io;
pub fn setup_logger() -> Result<(), fern::InitError> {
pub fn setup_logger(file_name : String) -> Result<(), fern::InitError> {
fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!(
@ -19,7 +19,7 @@ pub fn setup_logger() -> Result<(), fern::InitError> {
))
}).level(log::LevelFilter::Info)
.chain(io::stdout())
.chain(fern::log_file("installer.log")?)
.chain(fern::log_file(file_name)?)
.apply()?;
Ok(())
}

View File

@ -93,10 +93,10 @@ enum CallbackType {
}
fn main() {
logging::setup_logger().expect("Unable to setup logging!");
let config =
BaseAttributes::from_toml_str(RAW_CONFIG).log_expect("Config file could not be read");
BaseAttributes::from_toml_str(RAW_CONFIG).expect("Config file could not be read");
logging::setup_logger(format!("{}_installer.log", config.name)).expect("Unable to setup logging!");
let app_name = config.name.clone();

View File

@ -70,7 +70,7 @@ mod natives {
}
/// Cleans up the installer
pub fn burn_on_exit() {
pub fn burn_on_exit(app_name : &str) {
let current_exe = env::current_exe().log_expect("Current executable could not be found");
let path = current_exe
.parent()
@ -83,7 +83,7 @@ mod natives {
.log_expect("Unable to convert tool path to string")
.replace(" ", "\\ ");
let log = path.join("installer.log");
let log = path.join(format!("{}_installer.log", app_name));
let log = log
.to_str()
.log_expect("Unable to convert log path to string")
@ -123,7 +123,7 @@ mod natives {
}
/// Cleans up the installer
pub fn burn_on_exit() {
pub fn burn_on_exit(app_name : &str) {
let current_exe = env::current_exe().log_expect("Current executable could not be found");
// Thank god for *nix platforms
@ -134,7 +134,7 @@ mod natives {
let current_dir = env::current_dir().log_expect("Current directory cannot be found");
if let Err(e) = remove_file(current_dir.join("installer.log")) {
if let Err(e) = remove_file(current_dir.join(format!("{}_installer.log", app_name))) {
// No regular logging now.
eprintln!("Failed to delete installer log: {:?}", e);
};

View File

@ -207,7 +207,7 @@ impl Service for WebService {
}
if framework.burn_after_exit {
native::burn_on_exit();
native::burn_on_exit(&framework.base_attributes.name);
}
exit(0);

View File

@ -47,7 +47,7 @@ impl Task for InstallGlobalShortcutsTask {
let shortcut_file = create_shortcut(
&format!("{} maintenance tool", context.base_attributes.name),
&format!(
"Launch the {} maintenance tool to update, modify and uninstall the application.",
"Launch the {} Maintenance Tool to update, modify and uninstall the application.",
context.base_attributes.name
),
tool_path,

View File

@ -31,7 +31,7 @@
</h2>
<h2 class="subtitle" v-if="metadata.preexisting_install">
Welcome to the {{ attrs.name }} maintenance tool.
Welcome to the {{ attrs.name }} Maintenance Tool.
</h2>
</div>

View File

@ -343,23 +343,21 @@ const ModifyView = {
<div class="column has-padding">
<h4 class="subtitle">Choose an option:</h4>
<div class="field is-grouped is-bottom-floating">
<p class="control">
<a class="button is-link is-medium" v-on:click="update">
Update
</a>
</p>
<p class="control">
<a class="button is-medium" v-on:click="modify_packages">
Modify
</a>
</p>
<p class="control">
<a class="button is-danger is-medium" v-on:click="prepare_uninstall">
Uninstall
</a>
</p>
</div>
<a class="button is-dark is-medium" v-on:click="update">
Update
</a>
<br />
<br />
<a class="button is-dark is-medium" v-on:click="modify_packages">
Modify
</a>
<br />
<br />
<a class="button is-dark is-medium" v-on:click="prepare_uninstall">
Uninstall
</a>
<div class="modal is-active" v-if="show_uninstall">
<div class="modal-background"></div>