From c6992832e126971a86bafb303bbcc385806fb001 Mon Sep 17 00:00:00 2001 From: LiJianying Date: Fri, 4 Dec 2026 20:21:19 +0800 Subject: [PATCH] fix(windows): update taskbar thumbnail buttons first when toolbar is already initialized --- .../windows/window_taskbar_windows.cpp | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/platform/windows/window_taskbar_windows.cpp b/src/platform/windows/window_taskbar_windows.cpp index 3dc9e8f..d622b8f 100644 --- a/src/platform/windows/window_taskbar_windows.cpp +++ b/src/platform/windows/window_taskbar_windows.cpp @@ -1089,20 +1089,29 @@ class TaskbarState : public std::enable_shared_from_this { } } - // Attempt ThumbBarAddButtons first on every sync: hiding a window destroys - // its shell taskbar item, so on restore a cached boolean would call - // ThumbBarUpdateButtons (which silently returns S_OK without recreating the - // buttons). When buttons already exist on the active taskbar item, - // ThumbBarAddButtons returns E_INVALIDARG and we fall back to - // ThumbBarUpdateButtons. - HRESULT hr = list->ThumbBarAddButtons(hwnd_, static_cast(kMaxThumbnailButtons), - native_buttons.data()); - if (hr == E_INVALIDARG) { + // The toolbar is created once per shell taskbar item; afterwards its + // buttons can only be changed through ThumbBarUpdateButtons. Newer + // Windows 11 shells (e.g. build 26300) return S_OK from a second + // ThumbBarAddButtons while leaving the existing toolbar untouched, so + // adding first on every sync silently drops later property changes. + // Update first when already initialized, and fall back to + // ThumbBarAddButtons if the shell recreated the taskbar item and returns + // E_INVALIDARG (ReplayAllOnWindowThread also resets thumbbar_initialized_ + // on TaskbarButtonCreated). + HRESULT hr = S_OK; + if (thumbbar_initialized_) { hr = list->ThumbBarUpdateButtons(hwnd_, static_cast(kMaxThumbnailButtons), native_buttons.data()); + if (hr == E_INVALIDARG) { + hr = list->ThumbBarAddButtons(hwnd_, static_cast(kMaxThumbnailButtons), + native_buttons.data()); + } + } else { + hr = list->ThumbBarAddButtons(hwnd_, static_cast(kMaxThumbnailButtons), + native_buttons.data()); } if (SUCCEEDED(hr)) { - thumbbar_initialized_ = !snapshots.empty(); + thumbbar_initialized_ = true; } std::array old_icons{};