Skip to content

Commit 3ea6233

Browse files
authored
feat: support global shortcuts via GlobalShortcutsPortal feature with ozone/wayland (electron#45171)
* fix: backport patch to fix systemd unit activation in Chromium This backports a patch from Chromium, which fixes systemd unit activation. That is, a globalShortcuts feature that Chromium has needs to create a systemd unit and rename it properly. Portal's global shortcuts uses that name afterwards to map the app with the shortcuts bound. However, there might be a race between Chromium binding shortcuts and renaming the unit. This is a first step to add Portal's globalShortcuts to Electron. * feat: Support global shortcuts via GlobalShortcutsPortal feature Chromium has a new feature called GlobalShortcutsPortal. It allows clients to use Portal's globalShortcuts to register and listen to shortcuts. This patches adds necessary bits, which allows Electron to use that feature. In order to make it work, one has to add --enable-features=GlobalShortcutsPortal Test: tested manually with a sample app. * docs: add GlobalShortcutsPortal feature to globalShortcuts docs Electron supports Portal's globalShortcuts API now via Chromium, and Electron apps can use that in a Wayland session. Update the docs with the required feature flag that must be passed to be able to use that implementation.
1 parent cf67dc8 commit 3ea6233

File tree

7 files changed

+591
-9
lines changed

7 files changed

+591
-9
lines changed

docs/api/global-shortcut.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@ shortcuts.
1212
not have the keyboard focus. This module cannot be used before the `ready`
1313
event of the app module is emitted.
1414

15+
Please also note that it is also possible to use Chromium's
16+
`GlobalShortcutsPortal` implementation, which allows apps to bind global
17+
shortcuts when running within a Wayland session.
18+
1519
```js
1620
const { app, globalShortcut } = require('electron')
1721

22+
// Enable usage of Portal's globalShortcuts. This is essential for cases when
23+
// the app runs in a Wayland session.
24+
app.commandLine.appendSwitch('enable-features', 'GlobalShortcutsPortal')
25+
1826
app.whenReady().then(() => {
1927
// Register a 'CommandOrControl+X' shortcut listener.
2028
const ret = globalShortcut.register('CommandOrControl+X', () => {

patches/chromium/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,4 @@ refactor_unfilter_unresponsive_events.patch
139139
build_disable_thin_lto_mac.patch
140140
build_add_public_config_simdutf_config.patch
141141
revert_code_health_clean_up_stale_macwebcontentsocclusion.patch
142+
check_for_unit_to_activate_before_notifying_about_success.patch

0 commit comments

Comments
 (0)