Skip to content

Commit f7d6ec4

Browse files
authored
Merge pull request #719 from GyulyVGC/window-icon
Add icon to window title bar
2 parents 4784978 + 88da289 commit f7d6ec4

File tree

5 files changed

+140
-4
lines changed

5 files changed

+140
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All Sniffnet releases with the relative changes are documented in this file.
1010
- Ukrainian ([#692](https://github.com/GyulyVGC/sniffnet/pull/692))
1111
- Added new themes _OLED (Night)_ and _OLED (Day)_ based on palettes optimized for OLED displays and users with visual impairments ([#708](https://github.com/GyulyVGC/sniffnet/pull/708))
1212
- Fix _crates.io_ package for Windows ([#718](https://github.com/GyulyVGC/sniffnet/pull/718) — fixes [#681](https://github.com/GyulyVGC/sniffnet/issues/681))
13+
- Add icon to window title bar ([#719](https://github.com/GyulyVGC/sniffnet/pull/719) — fixes [#715](https://github.com/GyulyVGC/sniffnet/issues/715))
1314

1415
## [1.3.2] - 2025-01-06
1516
- Dropdown menus for network host filters ([#659](https://github.com/GyulyVGC/sniffnet/pull/659) — fixes [#354](https://github.com/GyulyVGC/sniffnet/issues/354))

Cargo.lock

Lines changed: 116 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ include = [
2020
"/resources/countries_flags/**/*.svg",
2121
"/resources/DB/*.mmdb",
2222
"/resources/fonts/subset/*.ttf",
23+
"/resources/logos/raw/icon.png",
24+
"/resources/packaging/windows/graphics/sniffnet.ico",
2325
"/resources/sounds/*.mp3",
2426
"/services.txt",
2527
"/build.rs",
@@ -39,7 +41,7 @@ pcap = "2.2.0"
3941
etherparse = "0.17.0"
4042
chrono = { version = "0.4.39", default-features = false, features = ["clock"] }
4143
plotters = { version = "0.3.7", default-features = false, features = ["area_series"] }
42-
iced = { version = "0.13.1", features = ["tokio", "svg", "advanced", "lazy"] }
44+
iced = { version = "0.13.1", features = ["tokio", "svg", "advanced", "lazy", "image"] }
4345
plotters-iced = "0.11.0"
4446
maxminddb = "0.24.0"
4547
confy = "0.6.1"
@@ -79,6 +81,9 @@ phf_shared = "0.11.3"
7981
rustrict = { version = "0.7.33", default-features = false, features = ["censor"] }
8082
once_cell = "1.20.3"
8183

84+
[target."cfg(windows)".build-dependencies]
85+
winres = "0.1.12"
86+
8287
#═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
8388

8489
[badges]

build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(windows)]
2+
extern crate winres;
3+
14
use std::env;
25
use std::fs::File;
36
use std::io::{BufRead, BufReader, BufWriter, Write};
@@ -16,9 +19,19 @@ fn main() {
1619
println!("cargo:rerun-if-changed={WINDOWS_ICON_PATH}");
1720
println!("cargo:rerun-if-changed={SERVICES_LIST_PATH}");
1821

22+
set_icon();
1923
build_services_phf();
2024
}
2125

26+
fn set_icon() {
27+
#[cfg(windows)]
28+
{
29+
let mut res = winres::WindowsResource::new();
30+
res.set_icon(WINDOWS_ICON_PATH);
31+
res.compile().unwrap();
32+
}
33+
}
34+
2235
fn build_services_phf() {
2336
let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join("services.rs");
2437
let mut output = BufWriter::new(File::create(out_path).unwrap());

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::borrow::Cow;
66
use std::sync::{Arc, Mutex};
77
use std::{panic, process, thread};
88

9+
use iced::advanced::graphics::image::image_rs::ImageFormat;
910
#[cfg(target_os = "linux")]
1011
use iced::window::settings::PlatformSpecific;
1112
use iced::{application, window, Font, Pixels, Settings};
@@ -51,6 +52,8 @@ mod utils;
5152
pub const SNIFFNET_LOWERCASE: &str = "sniffnet";
5253
pub const SNIFFNET_TITLECASE: &str = "Sniffnet";
5354

55+
const WINDOW_ICON: &[u8] = include_bytes!("../resources/logos/raw/icon.png");
56+
5457
/// Entry point of application execution
5558
///
5659
/// It initializes shared variables and loads configuration parameters
@@ -122,7 +125,7 @@ pub fn main() -> iced::Result {
122125
resizable: true,
123126
decorations: true,
124127
transparent: false,
125-
icon: None,
128+
icon: window::icon::from_file_data(WINDOW_ICON, Some(ImageFormat::Png)).ok(),
126129
#[cfg(target_os = "linux")]
127130
platform_specific: PlatformSpecific {
128131
application_id: String::from(SNIFFNET_LOWERCASE),

0 commit comments

Comments
 (0)