shortcut.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. const { globalShortcut } = require('electron');
  3. const storage = require('./storage');
  4. const shortcutList = {
  5. 'CommandOrControl+Shift+s': 'showWindow',
  6. 'CommandOrControl+Shift+h': 'hideWindow',
  7. }
  8. exports.setup = function () {
  9. // default
  10. //const preferences = storage.getPreferences();
  11. // const shortcuts = preferences.hasOwnProperty('shortcuts') ? preferences.shortcuts : {};
  12. // storage.setShortcuts(shortcuts);
  13. // for (let key in shortcuts) {
  14. // const fn = this.shortcuts[key]();
  15. // console.log(fn.toString());
  16. // this.register(key, fn);
  17. // }
  18. }
  19. exports.register = function (cmd, fn, force = true) {
  20. const isRegistered = this.isRegistered(cmd);
  21. console.log('[shortcut] [register] cmd:', [cmd, isRegistered]);
  22. if (isRegistered && !force) {
  23. return;
  24. }
  25. globalShortcut.register(cmd, fn)
  26. }
  27. exports.isRegistered = function (cmd) {
  28. return globalShortcut.isRegistered(cmd)
  29. }
  30. exports.unregister = function (cmd) {
  31. globalShortcut.unregister(cmd)
  32. }
  33. // function showWindow () {
  34. // MAIN_WINDOW.show()
  35. // }
  36. // function hideWindow () {
  37. // MAIN_WINDOW.hide()
  38. // }
  39. exports = module.exports;