ui/ux: implement "View Local Files" function...

... for Linux/macOS
This commit is contained in:
liushuyu 2020-05-29 21:41:40 -06:00
parent ca994e49d3
commit 322f72609f
4 changed files with 59 additions and 1 deletions

View File

@ -32,6 +32,7 @@ mod static_files;
mod uninstall;
mod update_updater;
mod verify_path;
mod view_folder;
/// Expected incoming Request format from Hyper.
pub type Request = hyper::server::Request;
@ -138,6 +139,7 @@ impl Service for WebService {
(Method::Get, "/api/exit") => exit::handle(self, req),
(Method::Get, "/api/packages") => packages::handle(self, req),
(Method::Get, "/api/installation-status") => installation_status::handle(self, req),
(Method::Get, "/api/view-local-folder") => view_folder::handle(self, req),
(Method::Post, "/api/start-install") => install::handle(self, req),
(Method::Post, "/api/uninstall") => uninstall::handle(self, req),
(Method::Post, "/api/update-updater") => update_updater::handle(self, req),

View File

@ -0,0 +1,35 @@
//! frontend/rest/services/view_folder.rs
//!
//! The /api/view-local-folder returns whether the path exists or not.
//! Side-effect: will open the folder in the default file manager if it exists.
use super::default_future;
use crate::frontend::rest::services::Future;
use crate::frontend::rest::services::Request;
use crate::frontend::rest::services::Response;
use crate::frontend::rest::services::WebService;
use hyper::header::{ContentLength, ContentType};
use crate::logging::LoggingErrors;
use crate::native::open_in_shell;
pub fn handle(service: &WebService, _: Request) -> Future {
let framework = service.get_framework_read();
let mut response = false;
let path = framework.install_path.clone();
if let Some(path) = path {
response = true;
open_in_shell(path.as_path());
}
let file = serde_json::to_string(&response)
.log_expect("Failed to render JSON payload of installation status object");
default_future(
Response::new()
.with_header(ContentLength(file.len() as u64))
.with_header(ContentType::json())
.with_body(file),
)
}

View File

@ -103,6 +103,10 @@ mod natives {
}
}
pub fn open_in_shell(path: &Path) {
// TODO
}
/// 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");
@ -266,6 +270,8 @@ mod natives {
use slug::slugify;
use std::fs::{create_dir_all, File};
use std::io::Write;
use std::path::Path;
use std::process::Command;
#[cfg(target_os = "linux")]
pub fn create_shortcut(
@ -325,6 +331,19 @@ mod natives {
Ok("".to_string())
}
pub fn open_in_shell(path: &Path) {
let shell: &str;
if cfg!(target_os = "linux") {
shell = "xdg-open";
} else if cfg!(target_os = "macos") {
shell = "open";
} else {
warn!("Unsupported platform");
return;
}
Command::new(shell).arg(path).spawn().ok();
}
/// 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");

View File

@ -62,7 +62,9 @@ export default {
uninstall: function () {
this.$router.push('/install/uninstall')
},
view_files: function () {}
view_files: function () {
this.$http.get('/api/view-local-folder')
}
}
}
</script>