diff --git a/Cargo.lock b/Cargo.lock index aba0888..dd78b44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "cfg-if" @@ -10,7 +10,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "rust_cat" -version = "1.0.3" +version = "1.0.5" dependencies = [ "trayicon", "winapi", diff --git a/Cargo.toml b/Cargo.toml index 218c68f..3afb8c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust_cat" -version = "1.0.3" +version = "1.0.5" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/build.rs b/build.rs index 16e01e0..b125c30 100644 --- a/build.rs +++ b/build.rs @@ -1,35 +1,35 @@ use std::{io, path::Path}; -#[cfg(windows)] use winres::WindowsResource; fn main() -> io::Result<()> { - #[cfg(windows)] - { - let profile = std::env::var("PROFILE").unwrap(); - if profile == "release" { - println!("cargo:rustc-cfg=release"); - } - let mut res = WindowsResource::new(); - // This path can be absolute, or relative to your crate root. - res.set_icon("assets/appIcon.ico"); + // Get Git commit hash + let output = std::process::Command::new("git") + .args(["rev-parse", "--short", "HEAD"]) + .output(); - // for entry in WalkDir::new("assets/cat") - // .into_iter() - // .chain(WalkDir::new("assets/parrot").into_iter()) - // { - // let entry = entry?; - // if !entry.file_type().is_file() { - // continue; - // } - // let path = entry.path().display().to_string(); - // let name = entry.file_name().to_string_lossy().to_string(); - // if name.ends_with(".ico") { - // res.set_icon_with_id(path.as_str(), name.as_str()); - // } - // } + match output { + Ok(output) if output.status.success() => { + let git_hash = String::from_utf8_lossy(&output.stdout).trim().to_string(); + if !git_hash.is_empty() { + println!("cargo:rustc-env=GIT_HASH={}", git_hash); + } else { + println!("cargo:rustc-env=GIT_HASH=N/A"); + } + } + _ => { + println!("cargo:rustc-env=GIT_HASH=N/A"); + } + } - res.compile()?; + let profile = std::env::var("PROFILE").unwrap(); + if profile == "release" { + println!("cargo:rustc-cfg=release"); } + let mut res = WindowsResource::new(); + // This path can be absolute, or relative to your crate root. + res.set_icon("assets/appIcon.ico"); + + res.compile()?; generate_icon_resources()?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index cada0e0..8d9d5e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -#![cfg_attr(release, windows_subsystem = "windows")] +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use core::mem::MaybeUninit; use std::{ @@ -39,6 +39,7 @@ enum Events { IconParrot, RunTaskmgr, ToggleRunOnStart, + ShowAboutDialog, } pub fn wchar(string: &str) -> Vec { @@ -68,7 +69,13 @@ fn main() { .checkable("&Parrot", !is_cat(icon_id), Events::IconParrot), ) .separator() - .checkable("&Run on Start", run_on_start_enabled, Events::ToggleRunOnStart) + .checkable( + "&Run on Start", + run_on_start_enabled, + Events::ToggleRunOnStart, + ) + .separator() + .item("&About", Events::ShowAboutDialog) .separator() .item("E&xit", Events::Exit) } @@ -150,6 +157,21 @@ fn main() { .set_menu(&build_menu(icon_id.load(Ordering::Relaxed))) .expect("set_menu for ToggleRunOnStart"); } + Events::ShowAboutDialog => unsafe { + let version = env!("CARGO_PKG_VERSION"); + let git_hash = option_env!("GIT_HASH").unwrap_or("N/A"); + let project_page = "https://github.com/bearice/RustCat"; // Hardcoded as per plan + let message = format!( + "RustCat version {} (Git: {})\nProject Page: {}", + version, git_hash, project_page + ); + winuser::MessageBoxW( + winuser::HWND_DESKTOP, + wchar(&message).as_ptr(), + wchar("About RustCat").as_ptr(), + winuser::MB_OK | winuser::MB_ICONINFORMATION, + ); + }, } } }); @@ -217,11 +239,14 @@ fn main() { fn is_run_on_start_enabled() -> bool { use winreg::enums::*; let hkcu = RegKey::predef(HKEY_CURRENT_USER); - if let Ok(run_key) = hkcu.open_subkey_with_flags("Software\\Microsoft\\Windows\\CurrentVersion\\Run", KEY_READ) { + if let Ok(run_key) = hkcu.open_subkey_with_flags( + "Software\\Microsoft\\Windows\\CurrentVersion\\Run", + KEY_READ, + ) { // Attempt to get the value. The type of the value doesn't matter as much as its existence. // We expect it to be a String (REG_SZ) if it exists. if run_key.get_value::("RustCat").is_ok() { - // Optionally, you could check if the value (path) is not empty, + // Optionally, you could check if the value (path) is not empty, // but for simplicity, existence is enough. return true; } @@ -254,7 +279,7 @@ fn set_run_on_start(enable: bool) { } } } else { - if let Err(e) = run_key.delete_value(VALUE_NAME) { + if let Err(_e) = run_key.delete_value(VALUE_NAME) { // It's okay if the value doesn't exist when trying to delete. // You might want to log this for debugging if it's unexpected. // eprintln!("Failed to delete registry value '{}' (this may be okay if it didn't exist): {}", VALUE_NAME, e); @@ -262,7 +287,10 @@ fn set_run_on_start(enable: bool) { } } Err(e) => { - eprintln!("Failed to open or create registry subkey '{}': {}", RUN_KEY_PATH, e); + eprintln!( + "Failed to open or create registry subkey '{}': {}", + RUN_KEY_PATH, e + ); } } }