Expand description
A Windows executable that permanently changes its own icon.
The model is borrowed from iOS alternate icons: a closed set of icons, declared
at build time, switched by name at runtime. What is not borrowed is where the
icon lives. On iOS and Android the thing that changes is the launcher entry; here
it is the executable file itself, so the new icon is what Explorer shows for the
.exe, and it survives a reboot.
alt_icons::include_icons!();
fn main() -> Result<(), alt_icons::Error> {
alt_icons::init()?;
alt_icons::set_icon(AppIcon::Dark)?;
Ok(())
}Declare the icon set in build.rs with alt_icons::build::configure. The build feature
enables this helper when alt-icons is used as a build-dependency. A build script
runs before macro expansion, so it cannot read a list declared by a macro, and
the default icon has to be baked at build time or the binary you ship has no icon
at all.
§What this costs
Every swap rewrites the executable, so its hash changes. Heuristic antivirus and SmartScreen reputation both notice a binary that rewrites itself. The default icon is baked at build time precisely so this only ever happens when your user asks for a different icon, never on first launch of a fresh download.
Signing is incompatible: rewriting the PE invalidates an Authenticode signature.
Macros§
- include_
icons - Pulls in the generated
AppIconenum. Call once, at the root of your crate.
Structs§
- Options
- Runtime behavior, configured once near the start of the application.
Enums§
- Error
- Everything that can go wrong during a swap.
Traits§
- Icon
- One icon in the set. Implemented by the
AppIconenum thatbuild::configuregenerates; there is no reason to implement it by hand.
Functions§
- current_
icon - init
- No-op away from Windows, so a cross-platform crate still builds.
- init_
with_ options - No-op away from Windows, just like
init. - set_
icon