shortcut.js 806 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const { globalShortcut } = require('electron');
  3. const storage = require('./storage');
  4. exports.setup = function () {
  5. // default
  6. storage.iniPreferences();
  7. }
  8. exports.register = function (shortcutObj, force = true, fn) {
  9. if (!shortcutObj['id'] || !shortcutObj['name'] || !shortcutObj['cmd']) {
  10. return false;
  11. }
  12. const isRegistered = this.isRegistered(shortcutObj['cmd']);
  13. console.log('[shortcut] [register] cmd:', [shortcutObj['cmd'], isRegistered]);
  14. if (isRegistered && !force) {
  15. return false;
  16. }
  17. storage.setShortcuts(shortcutObj);
  18. globalShortcut.register(shortcutObj['cmd'], fn)
  19. }
  20. exports.isRegistered = function (cmd) {
  21. return globalShortcut.isRegistered(cmd)
  22. }
  23. exports.unregister = function (cmd) {
  24. globalShortcut.unregister(cmd)
  25. }
  26. exports = module.exports;