Skip to content

refactor(windows): read default_window_icon from app resources#15274

Open
Legend-Master wants to merge 20 commits into
tauri-apps:devfrom
Legend-Master:windows-app-icon-for-default-window-icon
Open

refactor(windows): read default_window_icon from app resources#15274
Legend-Master wants to merge 20 commits into
tauri-apps:devfrom
Legend-Master:windows-app-icon-for-default-window-icon

Conversation

@Legend-Master
Copy link
Copy Markdown
Contributor

@Legend-Master Legend-Master commented Apr 21, 2026

Reference #14596, #15241

Read default_window_icon Image from the app's resources so we don't need to embed the raw pixels

We should look into keeping the resource HICON handle instead of reading out the RGBA values and then creating new icons in tao/muda/tray-icon, it will require some API changes around default_window_icon and or Image though

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

Package Changes Through d08e949

There are 4 changes which include tauri with minor, tauri-build with minor, tauri-codegen with minor, tauri-macros with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tauri-codegen 2.6.0 2.7.0
tauri-macros 2.6.0 2.7.0
tauri-build 2.6.0 2.7.0
tauri 2.11.0 2.12.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Comment thread crates/tauri-codegen/src/context.rs Outdated
let icon = CachedIcon::new(&root, &icon_path)?;
quote!(::std::option::Option::Some(#icon))
}
quote!(#root::image::Image::from_app_icon(64).ok())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at

https://learn.microsoft.com/en-us/windows/apps/design/iconography/app-icon-construction#icon-scaling

64 (~16KB of memory) should be a ceiling to use, we could go for a bit lower if we want

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, because this is most likely to be loaded from the very beginning, LoadImageW for the first time will actually take a bit of time (~1.5ms on my machine), not sure if this is worth the trade offs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that sounds pretty meh to be honest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes

@Legend-Master Legend-Master force-pushed the windows-app-icon-for-default-window-icon branch from 1bb0ad2 to dc3cf20 Compare April 22, 2026 02:33
For `LR_DEFAULTSIZE` we never use the default size
and `LR_SHARED` requires standard size whatever that is
@Legend-Master Legend-Master marked this pull request as ready for review April 23, 2026 07:05
@Legend-Master Legend-Master requested a review from a team as a code owner April 23, 2026 07:05
@Legend-Master Legend-Master added this to the 2.11 milestone Apr 29, 2026
@Qodo-Free-For-OSS
Copy link
Copy Markdown

Hi, Image::from_icon_resource calls GetIconInfo but never frees ICONINFO.hbmColor/hbmMask, leaking GDI objects on every call (startup path on Windows via default window icon). This can exhaust the per-process GDI handle limit and cause UI/resource creation failures.

Severity: action required | Category: reliability

How to fix: Free ICONINFO bitmaps

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

On Windows, GetIconInfo returns ICONINFO containing hbmColor and hbmMask bitmap handles that are owned by the caller. Image::from_icon_resource currently never releases these handles, leaking GDI objects per invocation.

Issue Context

This path is now used for the Windows default default_window_icon (via Image::from_app_icon_resource(...).ok()), so the leak can occur during normal app startup.

Fix Focus Areas

  • crates/tauri/src/image/mod.rs[141-207]

What to change

  • Ensure icon_info.hbmColor and icon_info.hbmMask are released with DeleteObject on all exit paths (success and error).
  • Prefer a small RAII guard (custom struct with Drop) to avoid missing cleanup on early returns.
  • Add the necessary Windows import for DeleteObject (and any handle types needed).

We noticed a couple of other issues in this PR as well - happy to share if helpful.


Found by Qodo code review. FYI, Qodo is free for open-source.

@Legend-Master Legend-Master modified the milestones: 2.11, 2.12 May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants