feat: support global shortcuts via GlobalShortcutsPortal feature with ozone/wayland (#45297)

This commit is contained in:
trop[bot] 2025-02-27 11:33:12 +01:00 committed by GitHub
parent 4417f74a5b
commit 18007f843e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 591 additions and 9 deletions

View file

@ -12,9 +12,17 @@ shortcuts.
not have the keyboard focus. This module cannot be used before the `ready`
event of the app module is emitted.
Please also note that it is also possible to use Chromium's
`GlobalShortcutsPortal` implementation, which allows apps to bind global
shortcuts when running within a Wayland session.
```js
const { app, globalShortcut } = require('electron')
// Enable usage of Portal's globalShortcuts. This is essential for cases when
// the app runs in a Wayland session.
app.commandLine.appendSwitch('enable-features', 'GlobalShortcutsPortal')
app.whenReady().then(() => {
// Register a 'CommandOrControl+X' shortcut listener.
const ret = globalShortcut.register('CommandOrControl+X', () => {