diff --git a/src/frontend/rest/services/mod.rs b/src/frontend/rest/services/mod.rs index 76d0407..600e53a 100644 --- a/src/frontend/rest/services/mod.rs +++ b/src/frontend/rest/services/mod.rs @@ -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), diff --git a/src/frontend/rest/services/view_folder.rs b/src/frontend/rest/services/view_folder.rs new file mode 100644 index 0000000..cad0e0e --- /dev/null +++ b/src/frontend/rest/services/view_folder.rs @@ -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), + ) +} diff --git a/src/native/mod.rs b/src/native/mod.rs index 283bd27..246337b 100644 --- a/src/native/mod.rs +++ b/src/native/mod.rs @@ -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"); diff --git a/ui/src/views/ModifyView.vue b/ui/src/views/ModifyView.vue index ebfad50..e2a4a66 100644 --- a/ui/src/views/ModifyView.vue +++ b/ui/src/views/ModifyView.vue @@ -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') + } } }