From 912d9a1741a505356b86032175b20763d982ae3c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 1 Nov 2018 23:03:04 -0700 Subject: [PATCH 1/7] feat: allow registering multiple shortcuts --- atom/browser/api/atom_api_global_shortcut.cc | 16 +++++++++++++++- atom/browser/api/atom_api_global_shortcut.h | 5 ++++- docs/api/global-shortcut.md | 11 +++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_global_shortcut.cc b/atom/browser/api/atom_api_global_shortcut.cc index 4fc7532d9e346..ef34dd6924062 100644 --- a/atom/browser/api/atom_api_global_shortcut.cc +++ b/atom/browser/api/atom_api_global_shortcut.cc @@ -5,6 +5,7 @@ #include "atom/browser/api/atom_api_global_shortcut.h" #include +#include #include "atom/common/native_mate_converters/accelerator_converter.h" #include "atom/common/native_mate_converters/callback.h" @@ -38,8 +39,20 @@ void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) { accelerator_callback_map_[accelerator].Run(); } -bool GlobalShortcut::Register(const ui::Accelerator& accelerator, +bool GlobalShortcut::Register(const std::vector& accelerators, const base::Closure& callback) { + for (auto& accelerator : accelerators) { + GlobalShortcutListener* listener = GlobalShortcutListener::GetInstance(); + if (!listener->RegisterAccelerator(accelerator, this)) + return false; + + accelerator_callback_map_[accelerator] = callback; + } + return true; +} + +bool GlobalShortcut::RegisterAccelerator(const ui::Accelerator& accelerator, + const base::Closure& callback) { if (!GlobalShortcutListener::GetInstance()->RegisterAccelerator(accelerator, this)) { return false; @@ -78,6 +91,7 @@ void GlobalShortcut::BuildPrototype(v8::Isolate* isolate, prototype->SetClassName(mate::StringToV8(isolate, "GlobalShortcut")); mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("register", &GlobalShortcut::Register) + .SetMethod("registerAccelerator", &GlobalShortcut::RegisterAccelerator) .SetMethod("isRegistered", &GlobalShortcut::IsRegistered) .SetMethod("unregister", &GlobalShortcut::Unregister) .SetMethod("unregisterAll", &GlobalShortcut::UnregisterAll); diff --git a/atom/browser/api/atom_api_global_shortcut.h b/atom/browser/api/atom_api_global_shortcut.h index b023aec4a8436..9574adf00aa7c 100644 --- a/atom/browser/api/atom_api_global_shortcut.h +++ b/atom/browser/api/atom_api_global_shortcut.h @@ -7,6 +7,7 @@ #include #include +#include #include "atom/browser/api/trackable_object.h" #include "base/callback.h" @@ -33,8 +34,10 @@ class GlobalShortcut : public extensions::GlobalShortcutListener::Observer, private: typedef std::map AcceleratorCallbackMap; - bool Register(const ui::Accelerator& accelerator, + bool Register(const std::vector& accelerators, const base::Closure& callback); + bool RegisterAccelerator(const ui::Accelerator& accelerator, + const base::Closure& callback); bool IsRegistered(const ui::Accelerator& accelerator); void Unregister(const ui::Accelerator& accelerator); void UnregisterAll(); diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index 6632f851de10f..57480fe840b24 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -44,6 +44,17 @@ The `globalShortcut` module has the following methods: ### `globalShortcut.register(accelerator, callback)` +* `accelerators` String[] - an array of [Accelerator](accelerator.md)s. +* `callback` Function + +Registers a global shortcut of all `accelerator` items in `accelerators`. The `callback` is called when any of the registered shortcuts are pressed by the user. + +When a given accelerator is already taken by other applications, this call will +silently fail. This behavior is intended by operating systems, since they don't +want applications to fight for global shortcuts. + +### `globalShortcut.registerAccelerator(accelerator, callback)` + * `accelerator` [Accelerator](accelerator.md) * `callback` Function From 084b9b16c7f5e73b1c3aa53c7c8e1baad0c5789d Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 1 Nov 2018 23:11:14 -0700 Subject: [PATCH 2/7] add a spec for new/renamed fn --- spec/api-global-shortcut-spec.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/spec/api-global-shortcut-spec.js b/spec/api-global-shortcut-spec.js index 04abee452da33..33797ef41df0e 100644 --- a/spec/api-global-shortcut-spec.js +++ b/spec/api-global-shortcut-spec.js @@ -18,19 +18,36 @@ describe('globalShortcut module', () => { globalShortcut.unregisterAll() }) - it('can register and unregister accelerators', () => { + it('can register and unregister single accelerators', () => { const accelerator = 'CommandOrControl+A+B+C' expect(globalShortcut.isRegistered(accelerator)).to.be.false() - globalShortcut.register(accelerator, () => {}) + globalShortcut.registerAccelerator(accelerator, () => {}) expect(globalShortcut.isRegistered(accelerator)).to.be.true() globalShortcut.unregister(accelerator) expect(globalShortcut.isRegistered(accelerator)).to.be.false() expect(globalShortcut.isRegistered(accelerator)).to.be.false() - globalShortcut.register(accelerator, () => {}) + globalShortcut.registerAccelerator(accelerator, () => {}) expect(globalShortcut.isRegistered(accelerator)).to.be.true() globalShortcut.unregisterAll() expect(globalShortcut.isRegistered(accelerator)).to.be.false() }) + + it('can register andunregistermultiple accelerators', () => { + const accelerators = ['CommandOrControl+X', 'CommandOrControl+Y'] + + expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() + expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() + + globalShortcut.register(accelerators, () => {}) + + expect(globalShortcut.isRegistered(accelerators[0])).to.be.true() + expect(globalShortcut.isRegistered(accelerators[1])).to.be.true() + + globalShortcut.unregisterAll() + + expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() + expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() + }) }) From e4727d59b4c16b913e98df3aca97f2bb5f7633f0 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 1 Nov 2018 23:18:30 -0700 Subject: [PATCH 3/7] naming is hard --- atom/browser/api/atom_api_global_shortcut.cc | 11 ++++++----- atom/browser/api/atom_api_global_shortcut.h | 6 +++--- docs/api/global-shortcut.md | 4 ++-- spec/api-global-shortcut-spec.js | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/atom/browser/api/atom_api_global_shortcut.cc b/atom/browser/api/atom_api_global_shortcut.cc index ef34dd6924062..5caca6e2c6b3a 100644 --- a/atom/browser/api/atom_api_global_shortcut.cc +++ b/atom/browser/api/atom_api_global_shortcut.cc @@ -39,8 +39,9 @@ void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) { accelerator_callback_map_[accelerator].Run(); } -bool GlobalShortcut::Register(const std::vector& accelerators, - const base::Closure& callback) { +bool GlobalShortcut::RegisterAll( + const std::vector& accelerators, + const base::Closure& callback) { for (auto& accelerator : accelerators) { GlobalShortcutListener* listener = GlobalShortcutListener::GetInstance(); if (!listener->RegisterAccelerator(accelerator, this)) @@ -51,8 +52,8 @@ bool GlobalShortcut::Register(const std::vector& accelerators, return true; } -bool GlobalShortcut::RegisterAccelerator(const ui::Accelerator& accelerator, - const base::Closure& callback) { +bool GlobalShortcut::Register(const ui::Accelerator& accelerator, + const base::Closure& callback) { if (!GlobalShortcutListener::GetInstance()->RegisterAccelerator(accelerator, this)) { return false; @@ -90,8 +91,8 @@ void GlobalShortcut::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { prototype->SetClassName(mate::StringToV8(isolate, "GlobalShortcut")); mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + .SetMethod("registerAll", &GlobalShortcut::RegisterAll) .SetMethod("register", &GlobalShortcut::Register) - .SetMethod("registerAccelerator", &GlobalShortcut::RegisterAccelerator) .SetMethod("isRegistered", &GlobalShortcut::IsRegistered) .SetMethod("unregister", &GlobalShortcut::Unregister) .SetMethod("unregisterAll", &GlobalShortcut::UnregisterAll); diff --git a/atom/browser/api/atom_api_global_shortcut.h b/atom/browser/api/atom_api_global_shortcut.h index 9574adf00aa7c..baf6834c17dd6 100644 --- a/atom/browser/api/atom_api_global_shortcut.h +++ b/atom/browser/api/atom_api_global_shortcut.h @@ -34,10 +34,10 @@ class GlobalShortcut : public extensions::GlobalShortcutListener::Observer, private: typedef std::map AcceleratorCallbackMap; - bool Register(const std::vector& accelerators, + bool RegisterAll(const std::vector& accelerators, + const base::Closure& callback); + bool Register(const ui::Accelerator& accelerator, const base::Closure& callback); - bool RegisterAccelerator(const ui::Accelerator& accelerator, - const base::Closure& callback); bool IsRegistered(const ui::Accelerator& accelerator); void Unregister(const ui::Accelerator& accelerator); void UnregisterAll(); diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index 57480fe840b24..09f4f3e2c2d97 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -42,7 +42,7 @@ app.on('will-quit', () => { The `globalShortcut` module has the following methods: -### `globalShortcut.register(accelerator, callback)` +### `globalShortcut.registerAll(accelerator, callback)` * `accelerators` String[] - an array of [Accelerator](accelerator.md)s. * `callback` Function @@ -53,7 +53,7 @@ When a given accelerator is already taken by other applications, this call will silently fail. This behavior is intended by operating systems, since they don't want applications to fight for global shortcuts. -### `globalShortcut.registerAccelerator(accelerator, callback)` +### `globalShortcut.register(accelerator, callback)` * `accelerator` [Accelerator](accelerator.md) * `callback` Function diff --git a/spec/api-global-shortcut-spec.js b/spec/api-global-shortcut-spec.js index 33797ef41df0e..b0c3e85548fa4 100644 --- a/spec/api-global-shortcut-spec.js +++ b/spec/api-global-shortcut-spec.js @@ -22,25 +22,25 @@ describe('globalShortcut module', () => { const accelerator = 'CommandOrControl+A+B+C' expect(globalShortcut.isRegistered(accelerator)).to.be.false() - globalShortcut.registerAccelerator(accelerator, () => {}) + globalShortcut.register(accelerator, () => {}) expect(globalShortcut.isRegistered(accelerator)).to.be.true() globalShortcut.unregister(accelerator) expect(globalShortcut.isRegistered(accelerator)).to.be.false() expect(globalShortcut.isRegistered(accelerator)).to.be.false() - globalShortcut.registerAccelerator(accelerator, () => {}) + globalShortcut.register(accelerator, () => {}) expect(globalShortcut.isRegistered(accelerator)).to.be.true() globalShortcut.unregisterAll() expect(globalShortcut.isRegistered(accelerator)).to.be.false() }) - it('can register andunregistermultiple accelerators', () => { + it('can register and unregister multiple accelerators', () => { const accelerators = ['CommandOrControl+X', 'CommandOrControl+Y'] expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() - globalShortcut.register(accelerators, () => {}) + globalShortcut.registerAll(accelerators, () => {}) expect(globalShortcut.isRegistered(accelerators[0])).to.be.true() expect(globalShortcut.isRegistered(accelerators[1])).to.be.true() From 08b78b9b477a9f65954b4650005c64064bd3f978 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 2 Nov 2018 10:37:08 -0700 Subject: [PATCH 4/7] address feedback from review --- atom/browser/api/atom_api_global_shortcut.cc | 5 ++++- docs/api/global-shortcut.md | 18 +++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/atom/browser/api/atom_api_global_shortcut.cc b/atom/browser/api/atom_api_global_shortcut.cc index 5caca6e2c6b3a..c552ba10df5b1 100644 --- a/atom/browser/api/atom_api_global_shortcut.cc +++ b/atom/browser/api/atom_api_global_shortcut.cc @@ -44,8 +44,11 @@ bool GlobalShortcut::RegisterAll( const base::Closure& callback) { for (auto& accelerator : accelerators) { GlobalShortcutListener* listener = GlobalShortcutListener::GetInstance(); - if (!listener->RegisterAccelerator(accelerator, this)) + if (!listener->RegisterAccelerator(accelerator, this)) { + // unregister all shortcuts if any failed + UnregisterAll(); return false; + } accelerator_callback_map_[accelerator] = callback; } diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index 09f4f3e2c2d97..fe7363aaeb3c0 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -42,26 +42,26 @@ app.on('will-quit', () => { The `globalShortcut` module has the following methods: -### `globalShortcut.registerAll(accelerator, callback)` +### `globalShortcut.register(accelerator, callback)` -* `accelerators` String[] - an array of [Accelerator](accelerator.md)s. +* `accelerator` [Accelerator](accelerator.md) * `callback` Function -Registers a global shortcut of all `accelerator` items in `accelerators`. The `callback` is called when any of the registered shortcuts are pressed by the user. +Registers a global shortcut of `accelerator`. The `callback` is called when +the registered shortcut is pressed by the user. -When a given accelerator is already taken by other applications, this call will +When the accelerator is already taken by other applications, this call will silently fail. This behavior is intended by operating systems, since they don't want applications to fight for global shortcuts. -### `globalShortcut.register(accelerator, callback)` +### `globalShortcut.registerAll(accelerators, callback)` -* `accelerator` [Accelerator](accelerator.md) +* `accelerators` String[] - an array of [Accelerator](accelerator.md)s. * `callback` Function -Registers a global shortcut of `accelerator`. The `callback` is called when -the registered shortcut is pressed by the user. +Registers a global shortcut of all `accelerator` items in `accelerators`. The `callback` is called when any of the registered shortcuts are pressed by the user. -When the accelerator is already taken by other applications, this call will +When a given accelerator is already taken by other applications, this call will silently fail. This behavior is intended by operating systems, since they don't want applications to fight for global shortcuts. From 892b63e07da3535f120a227df33c753445705ca6 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 5 Nov 2018 09:24:29 -0800 Subject: [PATCH 5/7] address failures with new UnregisterSome --- atom/browser/api/atom_api_global_shortcut.cc | 12 +++++++++- atom/browser/api/atom_api_global_shortcut.h | 1 + docs/api/global-shortcut.md | 6 +++++ spec/api-global-shortcut-spec.js | 24 ++++++++++++++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/atom/browser/api/atom_api_global_shortcut.cc b/atom/browser/api/atom_api_global_shortcut.cc index c552ba10df5b1..1cbcaa1ca2157 100644 --- a/atom/browser/api/atom_api_global_shortcut.cc +++ b/atom/browser/api/atom_api_global_shortcut.cc @@ -42,14 +42,16 @@ void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) { bool GlobalShortcut::RegisterAll( const std::vector& accelerators, const base::Closure& callback) { + std::vector registered; for (auto& accelerator : accelerators) { GlobalShortcutListener* listener = GlobalShortcutListener::GetInstance(); if (!listener->RegisterAccelerator(accelerator, this)) { // unregister all shortcuts if any failed - UnregisterAll(); + UnregisterSome(registered); return false; } + registered.push_back(accelerator); accelerator_callback_map_[accelerator] = callback; } return true; @@ -75,6 +77,13 @@ void GlobalShortcut::Unregister(const ui::Accelerator& accelerator) { this); } +void GlobalShortcut::UnregisterSome( + const std::vector& accelerators) { + for (auto& accelerator : accelerators) { + Unregister(accelerator); + } +} + bool GlobalShortcut::IsRegistered(const ui::Accelerator& accelerator) { return ContainsKey(accelerator_callback_map_, accelerator); } @@ -98,6 +107,7 @@ void GlobalShortcut::BuildPrototype(v8::Isolate* isolate, .SetMethod("register", &GlobalShortcut::Register) .SetMethod("isRegistered", &GlobalShortcut::IsRegistered) .SetMethod("unregister", &GlobalShortcut::Unregister) + .SetMethod("unregisterSome", &GlobalShortcut::UnregisterSome) .SetMethod("unregisterAll", &GlobalShortcut::UnregisterAll); } diff --git a/atom/browser/api/atom_api_global_shortcut.h b/atom/browser/api/atom_api_global_shortcut.h index baf6834c17dd6..edcbad3db01e9 100644 --- a/atom/browser/api/atom_api_global_shortcut.h +++ b/atom/browser/api/atom_api_global_shortcut.h @@ -40,6 +40,7 @@ class GlobalShortcut : public extensions::GlobalShortcutListener::Observer, const base::Closure& callback); bool IsRegistered(const ui::Accelerator& accelerator); void Unregister(const ui::Accelerator& accelerator); + void UnregisterSome(const std::vector& accelerators); void UnregisterAll(); // GlobalShortcutListener::Observer implementation. diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index fe7363aaeb3c0..7a4a917c5f704 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -81,6 +81,12 @@ don't want applications to fight for global shortcuts. Unregisters the global shortcut of `accelerator`. +### `globalShortcut.unregisterSome(accelerator)` + +* `accelerators` String[] - an array of [Accelerator](accelerator.md)s. + +Unregisters all shortcuts present in `accelerators`. + ### `globalShortcut.unregisterAll()` Unregisters all of the global shortcuts. diff --git a/spec/api-global-shortcut-spec.js b/spec/api-global-shortcut-spec.js index b0c3e85548fa4..6ba457df7c371 100644 --- a/spec/api-global-shortcut-spec.js +++ b/spec/api-global-shortcut-spec.js @@ -19,7 +19,7 @@ describe('globalShortcut module', () => { }) it('can register and unregister single accelerators', () => { - const accelerator = 'CommandOrControl+A+B+C' + const accelerator = 'CmdOrCtrl+A+B+C' expect(globalShortcut.isRegistered(accelerator)).to.be.false() globalShortcut.register(accelerator, () => {}) @@ -35,7 +35,7 @@ describe('globalShortcut module', () => { }) it('can register and unregister multiple accelerators', () => { - const accelerators = ['CommandOrControl+X', 'CommandOrControl+Y'] + const accelerators = ['CmdOrCtrl+X', 'CmdOrCtrl+Y'] expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() @@ -50,4 +50,24 @@ describe('globalShortcut module', () => { expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() }) + + it('can register and unregister some accelerators', () => { + const accelerators = ['CmdOrCtrl+X', 'CmdOrCtrl+Y', 'CmdOrCtrl+Z'] + + expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() + expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() + expect(globalShortcut.isRegistered(accelerators[2])).to.be.false() + + globalShortcut.registerAll(accelerators, () => {}) + + expect(globalShortcut.isRegistered(accelerators[0])).to.be.true() + expect(globalShortcut.isRegistered(accelerators[1])).to.be.true() + expect(globalShortcut.isRegistered(accelerators[2])).to.be.true() + + globalShortcut.unregisterSome(['CmdOrCtrl+X', 'CmdOrCtrl+Y']) + + expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() + expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() + expect(globalShortcut.isRegistered(accelerators[2])).to.be.true() + }) }) From a2be885cb2b478705cc17067db8a2fa149b05e2e Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 5 Nov 2018 20:45:40 -0800 Subject: [PATCH 6/7] s/accelerator/accelerators/ --- docs/api/global-shortcut.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index 7a4a917c5f704..93fb061dfaa8d 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -81,7 +81,7 @@ don't want applications to fight for global shortcuts. Unregisters the global shortcut of `accelerator`. -### `globalShortcut.unregisterSome(accelerator)` +### `globalShortcut.unregisterSome(accelerators)` * `accelerators` String[] - an array of [Accelerator](accelerator.md)s. From b3fdcefdcf1b67580b740ad3ca698a35e82e38fe Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 5 Nov 2018 22:12:26 -0800 Subject: [PATCH 7/7] don't expose UnRegisterSome to js --- atom/browser/api/atom_api_global_shortcut.cc | 1 - docs/api/global-shortcut.md | 6 ------ spec/api-global-shortcut-spec.js | 20 -------------------- 3 files changed, 27 deletions(-) diff --git a/atom/browser/api/atom_api_global_shortcut.cc b/atom/browser/api/atom_api_global_shortcut.cc index 1cbcaa1ca2157..9f9102b07e45f 100644 --- a/atom/browser/api/atom_api_global_shortcut.cc +++ b/atom/browser/api/atom_api_global_shortcut.cc @@ -107,7 +107,6 @@ void GlobalShortcut::BuildPrototype(v8::Isolate* isolate, .SetMethod("register", &GlobalShortcut::Register) .SetMethod("isRegistered", &GlobalShortcut::IsRegistered) .SetMethod("unregister", &GlobalShortcut::Unregister) - .SetMethod("unregisterSome", &GlobalShortcut::UnregisterSome) .SetMethod("unregisterAll", &GlobalShortcut::UnregisterAll); } diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index 93fb061dfaa8d..fe7363aaeb3c0 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -81,12 +81,6 @@ don't want applications to fight for global shortcuts. Unregisters the global shortcut of `accelerator`. -### `globalShortcut.unregisterSome(accelerators)` - -* `accelerators` String[] - an array of [Accelerator](accelerator.md)s. - -Unregisters all shortcuts present in `accelerators`. - ### `globalShortcut.unregisterAll()` Unregisters all of the global shortcuts. diff --git a/spec/api-global-shortcut-spec.js b/spec/api-global-shortcut-spec.js index 6ba457df7c371..ac8a555bb7d60 100644 --- a/spec/api-global-shortcut-spec.js +++ b/spec/api-global-shortcut-spec.js @@ -50,24 +50,4 @@ describe('globalShortcut module', () => { expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() }) - - it('can register and unregister some accelerators', () => { - const accelerators = ['CmdOrCtrl+X', 'CmdOrCtrl+Y', 'CmdOrCtrl+Z'] - - expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() - expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() - expect(globalShortcut.isRegistered(accelerators[2])).to.be.false() - - globalShortcut.registerAll(accelerators, () => {}) - - expect(globalShortcut.isRegistered(accelerators[0])).to.be.true() - expect(globalShortcut.isRegistered(accelerators[1])).to.be.true() - expect(globalShortcut.isRegistered(accelerators[2])).to.be.true() - - globalShortcut.unregisterSome(['CmdOrCtrl+X', 'CmdOrCtrl+Y']) - - expect(globalShortcut.isRegistered(accelerators[0])).to.be.false() - expect(globalShortcut.isRegistered(accelerators[1])).to.be.false() - expect(globalShortcut.isRegistered(accelerators[2])).to.be.true() - }) })