Skip to content

Commit

Permalink
add open config option to tray. closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
keifufu committed Jun 12, 2024
1 parent 5cab3bf commit ab776f9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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") {
Expand Down
7 changes: 6 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) {
Expand Down

0 comments on commit ab776f9

Please sign in to comment.