-
Notifications
You must be signed in to change notification settings - Fork 15k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: media key globalShortcuts on macOS
- Loading branch information
1 parent
eaa5d37
commit 6ad6307
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
patches/chromium/fix_media_key_usage_with_globalshortcuts.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Shelley Vohr <shelley.vohr@gmail.com> | ||
Date: Mon, 16 Aug 2021 17:55:32 +0200 | ||
Subject: fix: media key usage with globalShortcuts | ||
|
||
This patch enables media keys to work properly with Electron's globalShortcut | ||
module. Chromium's default usage of RemoteCommandCenterDelegate on macOS falls | ||
down into MPRemoteCommandCenter, which makes it such that an app will not | ||
receive remote control events until it begins playing audio. This runs | ||
counter to the design of globalShortcuts, and so we need to instead | ||
use `ui::MediaKeysListener`. | ||
|
||
diff --git a/content/browser/media/media_keys_listener_manager_impl.cc b/content/browser/media/media_keys_listener_manager_impl.cc | ||
index 5938f75742b793868638e693a9a8c8dc686dfc46..bf8782c23095a09dec62c68d7d902df24abcb13e 100644 | ||
--- a/content/browser/media/media_keys_listener_manager_impl.cc | ||
+++ b/content/browser/media/media_keys_listener_manager_impl.cc | ||
@@ -231,7 +231,7 @@ void MediaKeysListenerManagerImpl::StartListeningForMediaKeysIfNecessary() { | ||
media::AudioManager::GetGlobalAppName()); | ||
#endif | ||
|
||
- if (system_media_controls_) { | ||
+ if (/* DISABLES CODE */ (0)) { | ||
system_media_controls_->AddObserver(this); | ||
system_media_controls_notifier_ = | ||
std::make_unique<SystemMediaControlsNotifier>( | ||
@@ -239,8 +239,13 @@ void MediaKeysListenerManagerImpl::StartListeningForMediaKeysIfNecessary() { | ||
} else { | ||
// If we can't access system media controls, then directly listen for media | ||
// key keypresses instead. | ||
+#if defined(OS_MAC) | ||
+ media_keys_listener_ = ui::MediaKeysListener::Create( | ||
+ this, ui::MediaKeysListener::Scope::kGlobalRequiresAccessibility); | ||
+#else | ||
media_keys_listener_ = ui::MediaKeysListener::Create( | ||
this, ui::MediaKeysListener::Scope::kGlobal); | ||
+#endif | ||
DCHECK(media_keys_listener_); | ||
} | ||
|
||
diff --git a/ui/base/accelerators/media_keys_listener.h b/ui/base/accelerators/media_keys_listener.h | ||
index c2b03328c0e508995bdc135031500783f500ceba..1b6b14dc2999c99445cef6ffc04d49a7c1728a54 100644 | ||
--- a/ui/base/accelerators/media_keys_listener.h | ||
+++ b/ui/base/accelerators/media_keys_listener.h | ||
@@ -20,6 +20,7 @@ class Accelerator; | ||
class COMPONENT_EXPORT(UI_BASE) MediaKeysListener { | ||
public: | ||
enum class Scope { | ||
+ kGlobalRequiresAccessibility, // Listener works whenever application in focus or not but requires accessibility permissions on macOS | ||
kGlobal, // Listener works whenever application in focus or not. | ||
kFocused, // Listener only works whan application has focus. | ||
}; | ||
diff --git a/ui/base/accelerators/media_keys_listener_win.cc b/ui/base/accelerators/media_keys_listener_win.cc | ||
index 6c63a88cbb13cfcc9a8ba652554839275ae1ee04..1643eafc094dce77e4ba8752cd02e1ae6c488b56 100644 | ||
--- a/ui/base/accelerators/media_keys_listener_win.cc | ||
+++ b/ui/base/accelerators/media_keys_listener_win.cc | ||
@@ -13,7 +13,7 @@ std::unique_ptr<MediaKeysListener> MediaKeysListener::Create( | ||
MediaKeysListener::Scope scope) { | ||
DCHECK(delegate); | ||
|
||
- if (scope == Scope::kGlobal) { | ||
+ if (scope == Scope::kGlobal || scope == Scope::kGlobalRequiresAccessibility) { | ||
// We should never have more than one global media keys listener. | ||
if (!GlobalMediaKeysListenerWin::has_instance()) | ||
return std::make_unique<GlobalMediaKeysListenerWin>(delegate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters