app: use the tauri-app medallion icon on the window, taskbar and tray
The exe carried no icon resource and the tray drew a stand-in disc, so Explorer, the taskbar and the tray each guessed at what to show. The old front end's medallion was already in the tree and identical to the installer's icon.ico, so the whole shell now draws it: set_app_icon feeds icons/icon_full.png to rune before the event loop, the tray decodes the bundled 32 px, and build.rs bakes icon.ico into the exe for Explorer and shortcuts. The 128 px variants stay in tauri-app, which rune's own resizing makes redundant here.
This commit is contained in:
1 parent
6ca825990d
commit
b173d75e98
7 files changed
+95
-40
No files matched your search
Generated
+44
-2
@@ -1541,6 +1541,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"directories",
|
"directories",
|
||||||
"ffmpeg-sidecar",
|
"ffmpeg-sidecar",
|
||||||
|
"image",
|
||||||
"rune",
|
"rune",
|
||||||
"rune-kit",
|
"rune-kit",
|
||||||
"rune-notify",
|
"rune-notify",
|
||||||
@@ -1551,6 +1552,7 @@ dependencies = [
|
|||||||
"uuid",
|
"uuid",
|
||||||
"windows",
|
"windows",
|
||||||
"winreg",
|
"winreg",
|
||||||
|
"winresource",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3068,6 +3070,15 @@ dependencies = [
|
|||||||
"syn 3.0.10",
|
"syn 3.0.10",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782"
|
||||||
|
dependencies = [
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
@@ -3553,6 +3564,21 @@ dependencies = [
|
|||||||
"syn 3.0.10",
|
"syn 3.0.10",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "1.2.2+spec-1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5426cb1b964690d913f6c5c1a1ae0b42f428ec506bb4d452876d7a209c9bca3b"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"serde_core",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"toml_parser",
|
||||||
|
"toml_writer",
|
||||||
|
"winnow",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "1.1.3+spec-1.1.0"
|
version = "1.1.3+spec-1.1.0"
|
||||||
@@ -3576,13 +3602,19 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_parser"
|
name = "toml_parser"
|
||||||
version = "1.1.5+spec-1.1.0"
|
version = "1.1.6+spec-1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c"
|
checksum = "e6769c452d71ba30696c6b37770c439a9cc9110f47f7d5cdbeda79840ef5ea31"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"winnow",
|
"winnow",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_writer"
|
||||||
|
version = "1.2.0+spec-1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing"
|
name = "tracing"
|
||||||
version = "0.1.44"
|
version = "0.1.44"
|
||||||
@@ -4432,6 +4464,16 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winresource"
|
||||||
|
version = "0.1.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a2bc6d36480b829272a5bdabf08e6dca8004761c1da7e35efef800540c66221b"
|
||||||
|
dependencies = [
|
||||||
|
"toml",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wit-bindgen"
|
name = "wit-bindgen"
|
||||||
version = "0.57.1"
|
version = "0.57.1"
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ license = "MIT"
|
|||||||
name = "leaguerecorder"
|
name = "leaguerecorder"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
# Bakes icons/icon.ico into the exe's resources (build.rs), for Explorer and shortcuts.
|
||||||
|
winresource = "0.1"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rune = { git = "https://github.com/anomalyco/rune", rev = "4ddf696b0f13ec618fdeb80b4c9ea1a6246547f1" }
|
rune = { git = "https://github.com/anomalyco/rune", rev = "4ddf696b0f13ec618fdeb80b4c9ea1a6246547f1" }
|
||||||
rune-kit = { git = "https://github.com/anomalyco/rune", rev = "4ddf696b0f13ec618fdeb80b4c9ea1a6246547f1" }
|
rune-kit = { git = "https://github.com/anomalyco/rune", rev = "4ddf696b0f13ec618fdeb80b4c9ea1a6246547f1" }
|
||||||
@@ -22,6 +26,8 @@ tokio = { version = "1", features = ["rt", "net", "io-util", "time", "sync"] }
|
|||||||
uuid = { version = "1", features = ["v4", "serde"] }
|
uuid = { version = "1", features = ["v4", "serde"] }
|
||||||
ffmpeg-sidecar = "2.7"
|
ffmpeg-sidecar = "2.7"
|
||||||
ureq = "3.5"
|
ureq = "3.5"
|
||||||
|
# PNG decode of the bundled tray icon; the same crate and features rune itself uses.
|
||||||
|
image = { version = "0.25", default-features = false, features = ["png"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winreg = "0.56"
|
winreg = "0.56"
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
//! Bakes `icons/icon.ico` into the exe as its resource, so Explorer, shortcuts and the
|
||||||
|
//! installer show the medallion the window and the tray also draw.
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut resource = winresource::WindowsResource::new();
|
||||||
|
resource.set_icon("icons/icon.ico");
|
||||||
|
resource.compile().expect("the icon resource compiles");
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 797 KiB |
@@ -63,6 +63,7 @@ fn main() {
|
|||||||
if !app::headless() && !rune::single_instance(os::APP_ID) {
|
if !app::headless() && !rune::single_instance(os::APP_ID) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
os::set_app_icon();
|
||||||
os::register_notifications();
|
os::register_notifications();
|
||||||
rune_notify::on_click(|_| rune_notify::bring_to_front());
|
rune_notify::on_click(|_| rune_notify::bring_to_front());
|
||||||
|
|
||||||
|
|||||||
+33
-38
@@ -71,45 +71,28 @@ pub fn notify(id: &str, title: &str, body: &str) {
|
|||||||
rune_notify::post(¬ification);
|
rune_notify::post(¬ification);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A 32 px tray icon: an accent disc with a white play mark.
|
/// The app's icon for the title bar, the taskbar and Alt+Tab: the same medallion the exe
|
||||||
pub fn tray_icon() -> rune::TrayIcon {
|
/// carries and the installer shows. Call once at startup, before the event loop; rune sizes
|
||||||
const SIZE: u32 = 32;
|
/// it for each use and a headless run sets nothing.
|
||||||
let mut pixels = vec![0u8; (SIZE * SIZE * 4) as usize];
|
pub fn set_app_icon() {
|
||||||
let accent = [0x5b, 0x7c, 0xfa];
|
let bytes = include_bytes!("../icons/icon_full.png").as_slice();
|
||||||
let half = SIZE as f32 / 2.0;
|
if let Err(e) = rune::set_app_icon(bytes) {
|
||||||
let radius = half - 1.0;
|
eprintln!("app icon unavailable: {e}");
|
||||||
// Play triangle: apex right of centre, base left of centre.
|
|
||||||
let (ax, ay) = (half + 4.5, half);
|
|
||||||
let (bx, by) = (half - 4.0, half - 6.0);
|
|
||||||
let (cx, cy) = (half - 4.0, half + 6.0);
|
|
||||||
let edge = |px: f32, py: f32, x1: f32, y1: f32, x2: f32, y2: f32| {
|
|
||||||
(x2 - x1) * (py - y1) - (y2 - y1) * (px - x1)
|
|
||||||
};
|
|
||||||
for y in 0..SIZE {
|
|
||||||
for x in 0..SIZE {
|
|
||||||
let px = x as f32 + 0.5;
|
|
||||||
let py = y as f32 + 0.5;
|
|
||||||
let dx = px - half;
|
|
||||||
let dy = py - half;
|
|
||||||
// Three pixels of antialiasing at the disc edge.
|
|
||||||
let coverage = (radius - (dx * dx + dy * dy).sqrt()).clamp(0.0, 1.0);
|
|
||||||
if coverage <= 0.0 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let e1 = edge(px, py, ax, ay, bx, by);
|
|
||||||
let e2 = edge(px, py, bx, by, cx, cy);
|
|
||||||
let e3 = edge(px, py, cx, cy, ax, ay);
|
|
||||||
let inside =
|
|
||||||
(e1 >= 0.0 && e2 >= 0.0 && e3 >= 0.0) || (e1 <= 0.0 && e2 <= 0.0 && e3 <= 0.0);
|
|
||||||
let ink = if inside { [255, 255, 255] } else { accent };
|
|
||||||
let i = ((y * SIZE + x) * 4) as usize;
|
|
||||||
pixels[i] = ink[0];
|
|
||||||
pixels[i + 1] = ink[1];
|
|
||||||
pixels[i + 2] = ink[2];
|
|
||||||
pixels[i + 3] = (coverage * 255.0) as u8;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rune::TrayIcon::rgba(SIZE, SIZE, pixels)
|
}
|
||||||
|
|
||||||
|
/// A 32 px tray icon: the app's medallion, decoded to the straight RGBA rows the tray takes.
|
||||||
|
pub fn tray_icon() -> rune::TrayIcon {
|
||||||
|
let (width, height, pixels) = tray_icon_pixels();
|
||||||
|
rune::TrayIcon::rgba(width, height, pixels)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The medallion at its bundled 32 px: straight RGBA rows for [`rune::TrayIcon`].
|
||||||
|
fn tray_icon_pixels() -> (u32, u32, Vec<u8>) {
|
||||||
|
let image = image::load_from_memory(include_bytes!("../icons/32x32.png"))
|
||||||
|
.expect("the bundled tray icon decodes")
|
||||||
|
.into_rgba8();
|
||||||
|
(image.width(), image.height(), image.into_raw())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The tray menu. `recording` flips the record item's label.
|
/// The tray menu. `recording` flips the record item's label.
|
||||||
@@ -130,3 +113,15 @@ pub fn tray_menu(recording: bool) -> Vec<rune::TrayItem> {
|
|||||||
rune::TrayItem::action("quit", "Quit"),
|
rune::TrayItem::action("quit", "Quit"),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_tray_icon_decodes_to_32_px_of_rgba() {
|
||||||
|
let (width, height, pixels) = tray_icon_pixels();
|
||||||
|
assert_eq!((width, height), (32, 32));
|
||||||
|
assert_eq!(pixels.len(), (32 * 32 * 4) as usize);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user