Files
linkatplugandClaude Opus 5.5 4b20c6bdb2 Nouveau logo, images dans l'interface, dossier de données modifiable, fenêtre mémorisée
- Logo (assets/logo.jpg) décliné par build.rs : exe, zone de notification
  (connecté / déconnecté / silence), fenêtre, identité des notifications
- Icônes des applis et images jointes (bigImageUrl) dans la fenêtre, option pour les masquer
- Dossier des données au choix (sélecteur Windows) avec migration et retour par défaut
- Taille, position et état maximisé de la fenêtre mémorisés

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 17:58:55 +01:00

133 lines
5.0 KiB
Rust

//! Prépare les icônes à partir de assets/logo.jpg :
//! fond sombre rendu transparent, recadrage, déclinaisons (connecté / déconnecté / silence),
//! .ico embarqué dans l'exécutable + images brutes incluses dans le binaire.
use image::{imageops::FilterType, Rgba, RgbaImage};
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=assets/logo.jpg");
println!("cargo:rerun-if-changed=build.rs");
let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
let src = image::open("assets/logo.jpg").expect("assets/logo.jpg").to_rgba8();
let logo = cut_out(&src);
// Icône principale + .ico multi-tailles
let sizes = [16u32, 20, 24, 32, 40, 48, 64, 128, 256];
let mut pngs = Vec::new();
for &s in &sizes {
let img = resize(&logo, s);
let mut buf = Vec::new();
img.write_to(&mut std::io::Cursor::new(&mut buf), image::ImageFormat::Png).unwrap();
pngs.push(buf);
}
write_ico(&out.join("app.ico"), &sizes, &pngs);
std::fs::write(out.join("logo_256.png"), &pngs[sizes.iter().position(|&s| s == 256).unwrap()]).unwrap();
// Images brutes RGBA pour la zone de notification (32 px) et la fenêtre (64 px)
let tray = resize(&logo, 32);
std::fs::write(out.join("tray_connected.rgba"), tray.as_raw()).unwrap();
std::fs::write(out.join("tray_disconnected.rgba"), grey(&tray).as_raw()).unwrap();
std::fs::write(out.join("tray_muted.rgba"), muted(&tray).as_raw()).unwrap();
std::fs::write(out.join("window_64.rgba"), resize(&logo, 64).as_raw()).unwrap();
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
let mut res = winresource::WindowsResource::new();
res.set_icon(out.join("app.ico").to_str().unwrap())
.set("FileDescription", "Gotify Lite")
.set("ProductName", "Gotify Lite")
.set("LegalCopyright", "MIT");
res.compile().unwrap();
}
}
/// Rend transparent le fond uni (couleur du coin), recadre sur le contenu et met au carré.
fn cut_out(src: &RgbaImage) -> RgbaImage {
let bg = *src.get_pixel(4, 4);
let mut img = src.clone();
let (mut x0, mut y0, mut x1, mut y1) = (u32::MAX, u32::MAX, 0, 0);
for (x, y, p) in img.enumerate_pixels_mut() {
let d = (0..3).map(|i| (p[i] as f32 - bg[i] as f32).abs()).fold(0.0, f32::max);
let a = ((d - 18.0) / 50.0).clamp(0.0, 1.0);
if a > 0.0 {
// Retire la teinte du fond mélangée sur les bords (dé-matage).
for i in 0..3 {
let c = (p[i] as f32 - bg[i] as f32 * (1.0 - a)) / a;
p[i] = c.clamp(0.0, 255.0) as u8;
}
}
p[3] = (a * 255.0) as u8;
if a > 0.5 {
x0 = x0.min(x);
y0 = y0.min(y);
x1 = x1.max(x);
y1 = y1.max(y);
}
}
let side = (x1 - x0).max(y1 - y0) + 1;
let pad = side / 20;
let full = side + 2 * pad;
let mut sq = RgbaImage::from_pixel(full, full, Rgba([0, 0, 0, 0]));
let ox = pad + (side - (x1 - x0 + 1)) / 2;
let oy = pad + (side - (y1 - y0 + 1)) / 2;
for y in y0..=y1 {
for x in x0..=x1 {
sq.put_pixel(ox + x - x0, oy + y - y0, *img.get_pixel(x, y));
}
}
sq
}
fn resize(img: &RgbaImage, s: u32) -> RgbaImage {
image::imageops::resize(img, s, s, FilterType::Lanczos3)
}
fn grey(img: &RgbaImage) -> RgbaImage {
let mut o = img.clone();
for p in o.pixels_mut() {
let l = (0.3 * p[0] as f32 + 0.59 * p[1] as f32 + 0.11 * p[2] as f32) as u8;
*p = Rgba([l, l, l, (p[3] as f32 * 0.75) as u8]);
}
o
}
/// Logo atténué + pastille orange en bas à droite.
fn muted(img: &RgbaImage) -> RgbaImage {
let mut o = img.clone();
let s = o.width() as f32;
let (cx, cy, r) = (s * 0.76, s * 0.76, s * 0.22);
for (x, y, p) in o.enumerate_pixels_mut() {
let d = ((x as f32 + 0.5 - cx).powi(2) + (y as f32 + 0.5 - cy).powi(2)).sqrt();
if d <= r + 1.0 {
let a = (r + 1.0 - d).clamp(0.0, 1.0);
let inner = d <= r * 0.45;
let c: [u8; 3] = if inner { [255, 255, 255] } else { [240, 140, 30] };
for i in 0..3 {
p[i] = (c[i] as f32 * a + p[i] as f32 * (1.0 - a)) as u8;
}
p[3] = p[3].max((a * 255.0) as u8);
} else {
p[3] = (p[3] as f32 * 0.8) as u8;
}
}
o
}
fn write_ico(path: &Path, sizes: &[u32], pngs: &[Vec<u8>]) {
let mut ico = vec![0, 0, 1, 0];
ico.extend_from_slice(&(sizes.len() as u16).to_le_bytes());
let mut offset = 6 + 16 * sizes.len() as u32;
for (s, p) in sizes.iter().zip(pngs) {
let d = if *s >= 256 { 0 } else { *s as u8 };
ico.extend_from_slice(&[d, d, 0, 0, 1, 0, 32, 0]);
ico.extend_from_slice(&(p.len() as u32).to_le_bytes());
ico.extend_from_slice(&offset.to_le_bytes());
offset += p.len() as u32;
}
for p in pngs {
ico.extend_from_slice(p);
}
std::fs::write(path, ico).unwrap();
}