Desktop: Fix missing taskbar icon on Windows (#3490)

* fix missing taskbar icon

* focus window after init
This commit is contained in:
Timon
2025-12-18 12:51:01 +00:00
committed by GitHub
parent 6733a24e47
commit 14b8cdf4cb
7 changed files with 61 additions and 29 deletions
+13 -7
View File
@@ -1,9 +1,10 @@
use winit::dpi::PhysicalSize;
use windows::Win32::System::Com::{COINIT_APARTMENTTHREADED, CoInitializeEx};
use windows::Win32::UI::Shell::SetCurrentProcessExplicitAppUserModelID;
use windows::core::HSTRING;
use winit::event_loop::ActiveEventLoop;
use winit::icon::Icon;
use winit::platform::windows::{WinIcon, WindowAttributesWindows};
use winit::window::{Window, WindowAttributes};
use crate::consts::APP_ID;
use crate::event::AppEventScheduler;
pub(super) struct NativeWindowImpl {
@@ -11,11 +12,16 @@ pub(super) struct NativeWindowImpl {
}
impl super::NativeWindow for NativeWindowImpl {
fn init() {
let app_id = HSTRING::from(APP_ID);
unsafe {
let _ = CoInitializeEx(None, COINIT_APARTMENTTHREADED).ok();
SetCurrentProcessExplicitAppUserModelID(&app_id).ok();
}
}
fn configure(attributes: WindowAttributes, _event_loop: &dyn ActiveEventLoop) -> WindowAttributes {
let icon = WinIcon::from_resource(1, Some(PhysicalSize::new(256, 256))).ok().map(|icon| Icon(std::sync::Arc::new(icon)));
let win_window = WindowAttributesWindows::default().with_taskbar_icon(icon);
let icon = WinIcon::from_resource(1, None).ok().map(|icon| Icon(std::sync::Arc::new(icon)));
attributes.with_window_icon(icon).with_platform_attributes(Box::new(win_window))
attributes
}
fn new(window: &dyn Window, _app_event_scheduler: AppEventScheduler) -> Self {