use winres to set application icon on Windows

This commit is contained in:
GyulyVGC
2025-02-16 14:16:49 +01:00
parent 39b3ac4ecb
commit 88da28995a
3 changed files with 38 additions and 2 deletions

23
Cargo.lock generated
View File

@@ -822,7 +822,7 @@ dependencies = [
"directories",
"serde",
"thiserror 1.0.69",
"toml",
"toml 0.8.20",
]
[[package]]
@@ -4596,7 +4596,8 @@ dependencies = [
"serde_test",
"serial_test",
"splines",
"toml",
"toml 0.8.20",
"winres",
]
[[package]]
@@ -5023,6 +5024,15 @@ dependencies = [
"tokio",
]
[[package]]
name = "toml"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]]
name = "toml"
version = "0.8.20"
@@ -6139,6 +6149,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "winres"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c"
dependencies = [
"toml 0.5.11",
]
[[package]]
name = "wit-bindgen-rt"
version = "0.33.0"

View File

@@ -21,6 +21,7 @@ include = [
"/resources/DB/*.mmdb",
"/resources/fonts/subset/*.ttf",
"/resources/logos/raw/icon.png",
"/resources/packaging/windows/graphics/sniffnet.ico",
"/resources/sounds/*.mp3",
"/services.txt",
"/build.rs",
@@ -80,6 +81,9 @@ phf_shared = "0.11.3"
rustrict = { version = "0.7.33", default-features = false, features = ["censor"] }
once_cell = "1.20.3"
[target."cfg(windows)".build-dependencies]
winres = "0.1.12"
#═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
[badges]

View File

@@ -1,3 +1,6 @@
#[cfg(windows)]
extern crate winres;
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter, Write};
@@ -16,9 +19,19 @@ fn main() {
println!("cargo:rerun-if-changed={WINDOWS_ICON_PATH}");
println!("cargo:rerun-if-changed={SERVICES_LIST_PATH}");
set_icon();
build_services_phf();
}
fn set_icon() {
#[cfg(windows)]
{
let mut res = winres::WindowsResource::new();
res.set_icon(WINDOWS_ICON_PATH);
res.compile().unwrap();
}
}
fn build_services_phf() {
let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join("services.rs");
let mut output = BufWriter::new(File::create(out_path).unwrap());