Repository: electron/electron (language: cpp)

Issue:
[Bug]: Thumbnail toolbar buttons are removed when Explorer is restarted
### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

25.4.0

### What operating system are you using?

Windows

### Operating System Version

Windows 10 Pro 22H2 (19045.3324)

### What arch are you using?

x64

### Last Known Working Electron version

_No response_

### Expected Behavior

After adding buttons with `BrowserWindow.setThumbarButtons`, thumbnail toolbar buttons persist across explorer restarts.

### Actual Behavior

After adding buttons with `BrowserWindow.setThumbarButtons`, thumbnail toolbar buttons are removed when explorer is restarted.
After that, you can't add buttons with `BrowserWindow.setThumbarButtons`.

### Testcase Gist URL

_No response_

### Additional Information

You can restart Explorer by selecting the Explorer context menu from Task Manager.


Discussion / hints:

Fix patch:
diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc
index 028b35c1ceb1c..0ce17d437ab09 100644
--- a/shell/browser/native_window_views.cc
+++ b/shell/browser/native_window_views.cc
@@ -254,6 +254,10 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
 
   if (title_bar_style_ != TitleBarStyle::kNormal)
     set_has_frame(false);
+
+  // If the taskbar is re-created after we start up, we have to rebuild all of
+  // our buttons.
+  taskbar_created_message_ = RegisterWindowMessage(TEXT("TaskbarCreated"));
 #endif
 
   if (enable_larger_than_screen())
diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h
index e97d22ace0ab9..e7d4c30b2ae6d 100644
--- a/shell/browser/native_window_views.h
+++ b/shell/browser/native_window_views.h
@@ -318,6 +318,10 @@ class NativeWindowViews : public NativeWindow,
   // Controls Overlay if enabled on Windows.
   SkColor overlay_button_color_;
   SkColor overlay_symbol_color_;
+
+  // The message ID of the "TaskbarCreated" message, sent to us when we need to
+  // reset our thumbar buttons.
+  UINT taskbar_created_message_ = 0;
 #endif
 
   // Handles unhandled keyboard messages coming back from the renderer process.
diff --git a/shell/browser/native_window_views_win.cc b/shell/browser/native_window_views_win.cc
index e4288d047c304..f782dbbbad310 100644
--- a/shell/browser/native_window_views_win.cc
+++ b/shell/browser/native_window_views_win.cc
@@ -221,6 +221,12 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
     return true;
   }
 
+  if (message == taskbar_created_message_) {
+    // We need to reset all of our buttons because the taskbar went away.
+    taskbar_host_.RestoreThumbarButtons(GetAcceleratedWidget());
+    return true;
+  }
+
   switch (message) {
     // Screen readers send WM_GETOBJECT in order to get the accessibility
     // object, so take this opportunity to push Chromium into accessible


Test patch: