Repository: electron/electron (language: cpp)

Issue:
Window with `minimizable: false` still minimizes using "Minimize" menu item on Windows
### 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

35.0.0

### What operating system(s) are you using?

Windows

### Operating System Version

Windows 11

### What arch are you using?

x64

### Last Known Working Electron version

_No response_

### Expected Behavior

After creating a window with `minimizable: false`, the window should not be minimizable by any means

### Actual Behavior

After creating a window with `minimizable: false` on Windows, the window is still minimizable via a menu item with the `minimize` role

### Testcase Gist URL

https://gist.github.com/mlaurencin/288aad20449c92f3749121a496c0011f

### Additional Information

Discovered triaging https://github.com/electron/electron/issues/43130


Discussion / hints:

Fix patch:
diff --git a/lib/browser/api/menu-item-roles.ts b/lib/browser/api/menu-item-roles.ts
index fe2b07ed0fee7..1bb48b636e929 100644
--- a/lib/browser/api/menu-item-roles.ts
+++ b/lib/browser/api/menu-item-roles.ts
@@ -78,7 +78,9 @@ export const roleList: Record<RoleId, Role> = {
   minimize: {
     label: 'Minimize',
     accelerator: 'CommandOrControl+M',
-    windowMethod: w => w.minimize()
+    windowMethod: w => {
+      if (w.minimizable) w.minimize();
+    }
   },
   paste: {
     label: 'Paste',
diff --git a/spec/api-menu-item-spec.ts b/spec/api-menu-item-spec.ts
index e385b4773d63b..dd71140cacabe 100644
--- a/spec/api-menu-item-spec.ts
+++ b/spec/api-menu-item-spec.ts
@@ -2,7 +2,7 @@ import { BrowserWindow, app, Menu, MenuItem, MenuItemConstructorOptions } from '
 
 import { expect } from 'chai';
 
-import { ifdescribe } from './lib/spec-helpers';
+import { ifit, ifdescribe } from './lib/spec-helpers';
 import { closeAllWindows } from './lib/window-helpers';
 import { roleList, execute } from '../lib/browser/api/menu-item-roles';
 
@@ -205,6 +205,22 @@ describe('MenuItems', () => {
       const canExecute = execute(item.role as any, win, win.webContents);
       expect(canExecute).to.be.true('can execute');
     });
+
+    ifit(process.platform === 'win32')('does not execute minimize role when minimizable false', () => {
+      const win = new BrowserWindow({ minimizable: false });
+      const menu = Menu.buildFromTemplate([{
+        label: 'text',
+        role: 'minimize'
+      }]);
+
+      Menu.setApplicationMenu(menu);
+      menu._executeCommand({}, menu.items[0].commandId);
+      expect(win.isMinimized()).to.equal(false);
+
+      win.setMinimizable(true);
+      menu._executeCommand({}, menu.items[0].commandId);
+      expect(win.isMinimized()).to.equal(true);
+    });
   });
 
   describe('MenuItem command id', () => {


Test patch: