diff --git a/Cargo.lock b/Cargo.lock index d7b723d..38272cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -201,6 +201,7 @@ name = "cute-borders" version = "1.0.0" dependencies = [ "lazy_static", + "open", "serde", "serde_yaml", "tray-icon", @@ -608,6 +609,25 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is-docker" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" +dependencies = [ + "once_cell", +] + +[[package]] +name = "is-wsl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" +dependencies = [ + "is-docker", + "once_cell", +] + [[package]] name = "itoa" version = "1.0.9" @@ -765,6 +785,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "open" +version = "5.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5ca541f22b1c46d4bb9801014f234758ab4297e7870b904b6a8415b980a7388" +dependencies = [ + "is-wsl", + "libc", + "pathdiff", +] + [[package]] name = "pango" version = "0.16.5" @@ -791,6 +822,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + [[package]] name = "pin-project-lite" version = "0.2.12" diff --git a/Cargo.toml b/Cargo.toml index 26545f4..6bdd500 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] lazy_static = "1.4.0" +open = "5.1.4" serde = "1.0.183" serde_yaml = "0.9.25" tray-icon = "0.8.1" diff --git a/src/main.rs b/src/main.rs index d2b63ee..7ae72ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use config::Config; use config::RuleMatch; use logger::Logger; +use util::get_file_path; use std::ffi::c_ulong; use std::ffi::OsString; use std::os::windows::prelude::OsStringExt; @@ -66,6 +67,11 @@ fn main() { } let tray_menu_builder = Menu::with_items(&[ + &MenuItemBuilder::new() + .text("Open config") + .enabled(true) + .id(MenuId::new("0")) + .build(), &MenuItemBuilder::new() .text("Reload config") .enabled(true) @@ -113,7 +119,9 @@ fn main() { }; MenuEvent::set_event_handler(Some(|event: MenuEvent| { - if event.id == MenuId::new("1") { + if event.id == MenuId::new("0") { + let _ = open::that(get_file_path("config.yaml")); + } else if event.id == MenuId::new("1") { Config::reload(); apply_colors(false); } else if event.id == MenuId::new("2") { diff --git a/src/util.rs b/src/util.rs index 50b9f63..bdb0ac3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,7 +10,7 @@ use winreg::{enums::HKEY_CURRENT_USER, RegKey}; use crate::{logger::Logger, DWMWA_COLOR_DEFAULT}; -pub fn get_file(filename: &str, default_content: &str) -> std::fs::File { +pub fn get_file_path(filename: &str) -> String { let user_profile_path = match std::env::var("USERPROFILE") { Ok(user_profile_path) => user_profile_path, Err(err) => { @@ -29,6 +29,11 @@ pub fn get_file(filename: &str, default_content: &str) -> std::fs::File { std::process::exit(1); } } + return filepath; +} + +pub fn get_file(filename: &str, default_content: &str) -> std::fs::File { + let filepath = get_file_path(filename); if !Path::new(&filepath).exists() { let mut file = match File::create(&filepath) {