Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nw2 regression: CMD + 1-9 shortcuts not working on OSX when using nw2 mode (disabling nw2 makes it work as it should) #7943

Open
2 of 3 tasks
pd-l2ork opened this issue Aug 15, 2022 · 7 comments

Comments

@pd-l2ork
Copy link

pd-l2ork commented Aug 15, 2022

Issue Type

Before opening an issue, please search and see if it has already been raised.

  • Bug Report

  • Feature Request

  • Successfully reproduced against the latest version of NW.js?

Please use our mailing list or Gitter chatroom to ask questions. The issue tracker is only for bugs and feature requests, in English only. Please note that issues without a repro or code snippet are less likely to be resolved.

Current/Missing Behavior

Creating a menu shortcut in any code on a Mac that uses CMD + 1-9 keys shows properly in the menu, but cannot be triggered from 0.59 onward, including the latest version. Last time it did work was 0.28.3. CMD + 0 (zero) works, as does any other key combination (including CMD + SHIFT + 1-9). Below is edited excerpt from the group email (available at https://mail.google.com/mail/u/0/#search/nwjs/FMfcgzGqPpkjwsqVJGbdlxXNkkTjBDfh):

I have a software project that has nw.js OSX menu shortcuts for select options set to CMD+1 through CMD+5. Up until 0.42.3 these shortcuts worked just fine. However on newer versions (I tried 0.59, 0.62, and all the way up to the latest 0.70.1) this shortcut does not register at all, but only on OSX (I am using 10.14.6 and also tried 11.7). The same appears to have been reported by other users of my software. Please note the same is impossible to test on other OSs (AFAICT) because Win+1 (or Ubuntu key + 1) key is intercepted by the OS and triggers an OS action.

Curiously, if I set the shortcut to CMD+Shift+1, it works, but CMD+1 alone does not. So, out of all the number keys only 0 works. CMD + 1-9 do not (same behavior as above). All other keys (letters) work fine with CMD+ (or any other combination of modifiers), on any OS.

This is true for both built-in laptop (MBP) keyboard, and an external (USB) full-size keyboard.

As I mentioned, no code has been changed in the software project and this works fine on 0.28.3 and up until 0.42.3, but not on anything newer. This is directly related to enabling nw2 by default. UPDATE: running any newer version with disabling nw2 flag makes shortcuts work again. So, this is a nw2 bug.

On Windows and Linux the same project uses Ctrl key and there it all works as it should on all versions of nw.js. I am unable to test the same on Windows and Linux since both have other system things mapped to CMD + 1 and other number keys.

Expected/Proposed Behavior

CMD + 1-9 should trigger the menu item with the associated shortcut.

Additional Info

  • Operating System: Affects only OSX (tried on several different OS versions, so it is not OS-specific).
  • NW.js Version: 0.44.0 and newer has been tested and by default none of them work unless you disable nw2.
  • Repro Link: Just use simple code snippet below instead
  • Code snippet:

package.json


{
  "name": "helloworld",
  "main": "index.html"
}

index.html


<!DOCTYPE html>
<html>
<head>
  <title>Menu</title>
</head>
<body>

<p>Press the CMD+1 and note how on OSX doing so does not activate menu item 1 below. This is a problem only on OSX and affects only CMD + 1-9 options.</p>

<script>
// Load native UI library
var gui = require('nw.gui');

// Create menu
var menu = new gui.Menu({ type: 'menubar' });

// Create sub-menu
var menuItems = new gui.Menu();

menuItems.append(new gui.MenuItem({ label: 'Custom Menu Item 1', key: "1", modifiers: "cmd", click: function() {console.log('1 clicked (cmd+1)');} }));
menuItems.append(new gui.MenuItem({ label: 'Custom Menu Item 2', key: "b", modifiers: "cmd", click: function() {console.log('2 clicked (cmd+b)');} }));
menuItems.append(new gui.MenuItem({ label: 'Custom Menu Item 3', key: "1", modifiers: "cmd+shift", click: function() {console.log('3 clicked (cmd+shift+1)');} }));

// create MacBuiltin
menu.createMacBuiltin('Sample App',{
  hideEdit: true,
    hideWindow: true
});

// Append MenuItem as a Submenu
menu.append(
    new gui.MenuItem({
        label: 'Custom Menu Label',
        submenu: menuItems // menu elements from menuItems object
    })
);

// Append Menu to Window
gui.Window.get().menu = menu;
</script>  
</body>

  • Crash report: No crash and no error generated. Just the shortcut does not work.

Note that this may have some similarity with two stale issues reported earlier #7440 and #7463 but it is not the same.

@pd-l2ork pd-l2ork changed the title CMD + 1-9 shortcuts not working on OSX Regression: CMD + 1-9 shortcuts not working on OSX Aug 17, 2022
@ayushmanchhabra
Copy link
Contributor

@sysrage could you confirm that it's not working?

@ayushmanchhabra ayushmanchhabra added platform-specific has-min-repro Has a minimum reproduction labels Aug 24, 2022
@sysrage
Copy link

sysrage commented Aug 24, 2022

@sysrage could you confirm that it's not working?

I can confirm the example code fails to detect when Command+1 is pressed. It correctly detects Command+Shift+1 and Command+B, but not Command+1.

This appears to have been broken since version 0.42.4.

Works: 0.35.0, 0.40.0, 0.42.0, 0.42.3
Fails: 0.42.4, 0.42.5, 0.43.0, 0.45.0, 0.50.0

@pd-l2ork
Copy link
Author

pd-l2ork commented Nov 8, 2022

@rogerwang this is apparently a nw2 issue only. Please see comments and updated description.

@pd-l2ork pd-l2ork closed this as completed Nov 8, 2022
@pd-l2ork
Copy link
Author

pd-l2ork commented Nov 8, 2022

I just realized this may be because I disabled nw2. Will test and report. Reopening...

@pd-l2ork
Copy link
Author

pd-l2ork commented Nov 8, 2022

Indeed. Reenabling nw2 in any version post 0.42.3 (up until 0.70.1 that is the latest currently available) CMD+(1-9) does not work. When one disables nw2, it works just fine.

@pd-l2ork pd-l2ork changed the title Regression: CMD + 1-9 shortcuts not working on OSX Regression: CMD + 1-9 shortcuts not working on OSX when using nw2 mode (disabling nw2 makes it work as it should) Nov 8, 2022
@pd-l2ork pd-l2ork changed the title Regression: CMD + 1-9 shortcuts not working on OSX when using nw2 mode (disabling nw2 makes it work as it should) nw2 regression: CMD + 1-9 shortcuts not working on OSX when using nw2 mode (disabling nw2 makes it work as it should) Nov 8, 2022
@pd-l2ork
Copy link
Author

pd-l2ork commented Nov 9, 2022

@sysrage would you please add nw2 label to this and #7979 ? Thanks.

@sysrage
Copy link

sysrage commented Nov 9, 2022

@sysrage would you please add nw2 label to this and #7979 ? Thanks.

I am not a maintainer of this repo.

@ayushmanchhabra ayushmanchhabra added nw2 and removed nw2 labels Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants