fix: global shortcut media keys working with accessibility (#24145)
* fix: global shortcut media keys * update patches Co-authored-by: Electron Bot <anonymous@electronjs.org>
This commit is contained in:
parent
d8fe7af703
commit
0efcaec4d6
2 changed files with 92 additions and 2 deletions
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "chrome/common/extensions/command.h"
|
||||
#include "gin/dictionary.h"
|
||||
#include "gin/object_template_builder.h"
|
||||
#include "shell/browser/api/electron_api_system_preferences.h"
|
||||
|
@ -20,6 +21,7 @@
|
|||
#include "base/mac/mac_util.h"
|
||||
#endif
|
||||
|
||||
using extensions::Command;
|
||||
using extensions::GlobalShortcutListener;
|
||||
|
||||
namespace {
|
||||
|
@ -43,6 +45,15 @@ bool RegisteringMediaKeyForUntrustedClient(const ui::Accelerator& accelerator) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MapHasMediaKeys(
|
||||
const std::map<ui::Accelerator, base::Closure>& accelerator_map) {
|
||||
auto media_key = std::find_if(
|
||||
accelerator_map.begin(), accelerator_map.end(),
|
||||
[](const auto& ac) { return Command::IsMediaKey(ac.first); });
|
||||
|
||||
return media_key != accelerator_map.end();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
@ -90,8 +101,12 @@ bool GlobalShortcut::RegisterAll(
|
|||
bool GlobalShortcut::Register(const ui::Accelerator& accelerator,
|
||||
const base::Closure& callback) {
|
||||
#if defined(OS_MAC)
|
||||
if (RegisteringMediaKeyForUntrustedClient(accelerator))
|
||||
return false;
|
||||
if (Command::IsMediaKey(accelerator)) {
|
||||
if (RegisteringMediaKeyForUntrustedClient(accelerator))
|
||||
return false;
|
||||
|
||||
GlobalShortcutListener::SetShouldUseInternalMediaKeyHandling(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!GlobalShortcutListener::GetInstance()->RegisterAccelerator(accelerator,
|
||||
|
@ -107,6 +122,13 @@ void GlobalShortcut::Unregister(const ui::Accelerator& accelerator) {
|
|||
if (accelerator_callback_map_.erase(accelerator) == 0)
|
||||
return;
|
||||
|
||||
#if defined(OS_MAC)
|
||||
if (Command::IsMediaKey(accelerator) &&
|
||||
!MapHasMediaKeys(accelerator_callback_map_)) {
|
||||
GlobalShortcutListener::SetShouldUseInternalMediaKeyHandling(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
GlobalShortcutListener::GetInstance()->UnregisterAccelerator(accelerator,
|
||||
this);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue