Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
50 changes: 25 additions & 25 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
Expand Down
40 changes: 34 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(release, windows_subsystem = "windows")]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use core::mem::MaybeUninit;
use std::{
Expand Down Expand Up @@ -39,6 +39,7 @@ enum Events {
IconParrot,
RunTaskmgr,
ToggleRunOnStart,
ShowAboutDialog,
}

pub fn wchar(string: &str) -> Vec<u16> {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
);
},
}
}
});
Expand Down Expand Up @@ -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::<String, _>("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;
}
Expand Down Expand Up @@ -254,15 +279,18 @@ 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);
}
}
}
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
);
}
}
}
Expand Down
Loading