api-global-shortcut-spec.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { expect } from 'chai'
  2. import { globalShortcut } from 'electron'
  3. describe('globalShortcut module', () => {
  4. before(function () {
  5. if (isCI && process.platform === 'win32') {
  6. this.skip()
  7. }
  8. })
  9. beforeEach(() => {
  10. globalShortcut.unregisterAll()
  11. })
  12. it('can register and unregister single accelerators', () => {
  13. const accelerator = 'CmdOrCtrl+A+B+C'
  14. expect(globalShortcut.isRegistered(accelerator)).to.be.false('initially registered')
  15. globalShortcut.register(accelerator, () => {})
  16. expect(globalShortcut.isRegistered(accelerator)).to.be.true('registration worked')
  17. globalShortcut.unregister(accelerator)
  18. expect(globalShortcut.isRegistered(accelerator)).to.be.false('unregistration worked')
  19. globalShortcut.register(accelerator, () => {})
  20. expect(globalShortcut.isRegistered(accelerator)).to.be.true('reregistration worked')
  21. globalShortcut.unregisterAll()
  22. expect(globalShortcut.isRegistered(accelerator)).to.be.false('re-unregistration worked')
  23. })
  24. it('can register and unregister multiple accelerators', () => {
  25. const accelerators = ['CmdOrCtrl+X', 'CmdOrCtrl+Y']
  26. expect(globalShortcut.isRegistered(accelerators[0])).to.be.false('first initially unregistered')
  27. expect(globalShortcut.isRegistered(accelerators[1])).to.be.false('second initially unregistered')
  28. globalShortcut.registerAll(accelerators, () => {})
  29. expect(globalShortcut.isRegistered(accelerators[0])).to.be.true('first registration worked')
  30. expect(globalShortcut.isRegistered(accelerators[1])).to.be.true('second registration worked')
  31. globalShortcut.unregisterAll()
  32. expect(globalShortcut.isRegistered(accelerators[0])).to.be.false('first unregistered')
  33. expect(globalShortcut.isRegistered(accelerators[1])).to.be.false('second unregistered')
  34. })
  35. })