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

[Bug]: unable to bind to volume events using globalShortcut from Touch bar #30588

Closed
3 tasks done
has-n opened this issue Aug 18, 2021 · 2 comments
Closed
3 tasks done
Labels
12-x-y blocked/need-repro Needs a test case to reproduce the bug bug 🪲 platform/macOS

Comments

@has-n
Copy link

has-n commented Aug 18, 2021

Preflight Checklist

Electron Version

12.0.16

What operating system are you using?

macOS

Operating System Version

Big Sur 11.4

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Expected Behavior

Binding to VolumeUp, VolumeDown or VolumeMute should work for TouchBar buttons.

Actual Behavior

Only VolumeMute fires.

Testcase Gist URL

No response

Additional Information

App has Accessibility permission. VolumeMute only fires when the permission is provided.

@has-n has-n added the bug 🪲 label Aug 18, 2021
@has-n has-n changed the title [Bug]: unable to bind to volume events using globalShortuct [Bug]: unable to bind to volume events using globalShortuct from Touch bar Aug 18, 2021
@codebytere
Copy link
Member

Thanks for reporting this and helping to make Electron better!

Because of time constraints, triaging code with third-party dependencies is usually not feasible for a small team like Electron's.

Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

I'm adding the blocked/need-repro label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

@codebytere codebytere added blocked/need-repro Needs a test case to reproduce the bug 12-x-y platform/macOS labels Aug 18, 2021
@ckerr ckerr changed the title [Bug]: unable to bind to volume events using globalShortuct from Touch bar [Bug]: unable to bind to volume events using globalShortcut from Touch bar Aug 18, 2021
@codebytere
Copy link
Member

Fixed in #31492, tested with:

// The globalShortcut module can register/unregister a global keyboard shortcut
// with the operating system so that you can customize the operations for various
// shortcuts.
//
// Note: The shortcut is global; it will work even if the app does not have the
// keyboard focus. You should not use this module until the ready event of the
// app module is emitted. In this example, we're using "Accelerators":
// Accelerators are Strings that can contain multiple modifiers and key codes,
// combined by the + character, and are used to define keyboard shortcuts
// throughout your application.
//
// For more info, see:
// https://electronjs.org/docs/api/accelerator
// https://electronjs.org/docs/api/global-shortcut

const { app, globalShortcut } = require('electron')

app.whenReady().then(() => {
  // Register a 'CommandOrControl+Y' shortcut listener.
  //
  // On Linux and Windows, the Command key does not have any effect, so use
  // CommandOrControl which represents Command on macOS and Control on
  // Linux and Windows to define some accelerators.
  globalShortcut.register('CommandOrControl+Y', () => {
    console.log('The global shortkey was pressed!')
  })

  // It supports "special names". Check out the API documentation for a full
  // list.
  globalShortcut.register('VolumeUp', () => console.log('Turn it up!'))
  globalShortcut.register('VolumeDown', () => console.log('Turn it down!'))
  globalShortcut.register('MediaPlayPause', () => console.log('Stop media!'))
})

app.on('will-quit', () => {
  // Unregister a shortcut.
  globalShortcut.unregister('CommandOrControl+Y')

  // Unregister all shortcuts.
  globalShortcut.unregisterAll()
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
12-x-y blocked/need-repro Needs a test case to reproduce the bug bug 🪲 platform/macOS
Projects
None yet
Development

No branches or pull requests

2 participants