Repository: electron/electron
Pull request: fix: crash when generating shortcut text for super accelerator (32-x-y)

Manually backport https://github.com/electron/electron/pull/44341 to 32-x-y. See that for more details.

Notes: fix crash when rendering super menu accelerator on linux.

#### Description of Change


<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Contributors guide: https://github.com/electron/electron/blob/main/CONTRIBUTING.md
-->

#### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [ ] PR description included and stakeholders cc'd
- [ ] `npm test` passes
- [ ] tests are [changed or added](https://github.com/electron/electron/blob/main/docs/development/testing.md)
- [ ] relevant documentation, tutorials, templates and examples are changed or added
- [ ] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).


Changed files:
filename: patches/chromium/.patches
patch: @@ -140,3 +140,4 @@ editcontext_use_empty_control_and_selection_bounds_as_fallbacks.patch
 editcontext_return_physical_pixels_from_firstrectforcharacterrange.patch
 cherry-pick-923797bac925.patch
 cherry-pick-e699ac35ac6c.patch
+ui_add_missing_shortcut_text_for_vkey_command_on_linux.patch

filename: patches/chromium/ui_add_missing_shortcut_text_for_vkey_command_on_linux.patch
patch: @@ -0,0 +1,50 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: deepak1556 <hop2deep@gmail.com>
+Date: Tue, 22 Oct 2024 00:27:27 +0900
+Subject: Add missing shortcut text for VKEY_COMMAND on linux
+
+Backports https://chromium-review.googlesource.com/c/chromium/src/+/5947724
+
+diff --git a/ui/base/accelerators/accelerator.cc b/ui/base/accelerators/accelerator.cc
+index d9445b90dba8f5d7372cd49ae92c2d28f719f288..1109829fed37d60405dae63d1461d44fffdc87f4 100644
+--- a/ui/base/accelerators/accelerator.cc
++++ b/ui/base/accelerators/accelerator.cc
+@@ -419,6 +419,8 @@ std::u16string Accelerator::ApplyLongFormModifiers(
+     result = ApplyModifierToAcceleratorString(result, IDS_APP_SEARCH_KEY);
+ #elif BUILDFLAG(IS_WIN)
+     result = ApplyModifierToAcceleratorString(result, IDS_APP_WINDOWS_KEY);
++#elif BUILDFLAG(IS_LINUX)
++    result = ApplyModifierToAcceleratorString(result, IDS_APP_SUPER_KEY);
+ #else
+     NOTREACHED_IN_MIGRATION();
+ #endif
+diff --git a/ui/base/accelerators/accelerator_unittest.cc b/ui/base/accelerators/accelerator_unittest.cc
+index 246cfe906786c1586e15acbae063a77cb5cc84e7..7627da94c48473870b127b57edad2a2845d76d4c 100644
+--- a/ui/base/accelerators/accelerator_unittest.cc
++++ b/ui/base/accelerators/accelerator_unittest.cc
+@@ -58,6 +58,9 @@ TEST(AcceleratorTest, MAYBE_GetShortcutText) {
+     {VKEY_OEM_COMMA, EF_CONTROL_DOWN, u"Ctrl+Comma", u"⌃,"},
+ #if BUILDFLAG(IS_MAC)
+     {VKEY_T, EF_COMMAND_DOWN | EF_CONTROL_DOWN, nullptr, u"⌃⌘T"},
++#endif
++#if BUILDFLAG(IS_LINUX)
++    {VKEY_T, EF_COMMAND_DOWN | EF_CONTROL_DOWN, u"Super+Ctrl+T", nullptr},
+ #endif
+   };
+ 
+diff --git a/ui/strings/ui_strings.grd b/ui/strings/ui_strings.grd
+index 5e1689755ac4976998a2c36bef04b522811d4b30..33a6f39d23b7a095f422a0e4e01f36a447a9a851 100644
+--- a/ui/strings/ui_strings.grd
++++ b/ui/strings/ui_strings.grd
+@@ -764,6 +764,11 @@ need to be translated for each locale.-->
+           Win
+         </message>
+       </if>
++      <if expr="is_linux">
++        <message name="IDS_APP_SUPER_KEY" desc="Windows key on Windows keyboards, and Command key on Mac keyboards.">
++          Super
++        </message>
++      </if>
+       <if expr="chromeos_ash">
+         <message name="IDS_APP_META_KEY" desc="External Meta key (Search key on ChromeOS keyboards, Windows key on Windows keyboards, and Command key on Mac keyboards)">
+           Meta

filename: spec/api-menu-spec.ts
patch: @@ -926,6 +926,20 @@ describe('Menu module', function () {
       });
       w.show();
     });
+
+    it('does not crash when rendering menu item with Super or meta accelerator', async () => {
+      const menu = Menu.buildFromTemplate([{
+        label: 'Test Super',
+        accelerator: 'Super+Ctrl+T'
+      }, {
+        label: 'Test Meta',
+        accelerator: 'Meta+Ctrl+T'
+      }]);
+      const menuWillClose = once(menu, 'menu-will-close');
+      menu.popup({ window: w });
+      menu.closePopup();
+      await menuWillClose;
+    });
   });
 
   describe('Menu.setApplicationMenu', () => {