This commit is contained in:
gaoshuaixing
2021-06-24 16:11:01 +08:00
parent fc1e83adf1
commit 4cc652f823
7 changed files with 106 additions and 15 deletions

49
electron/lib/shortcut.js Normal file
View File

@@ -0,0 +1,49 @@
'use strict';
const { globalShortcut } = require('electron');
const storage = require('./storage');
const shortcutList = {
'CommandOrControl+Shift+s': 'showWindow',
'CommandOrControl+Shift+h': 'hideWindow',
}
exports.setup = function () {
// default
//const preferences = storage.getPreferences();
// const shortcuts = preferences.hasOwnProperty('shortcuts') ? preferences.shortcuts : {};
// storage.setShortcuts(shortcuts);
// for (let key in shortcuts) {
// const fn = this.shortcuts[key]();
// console.log(fn.toString());
// this.register(key, fn);
// }
}
exports.register = function (cmd, fn, force = true) {
const isRegistered = this.isRegistered(cmd);
console.log('[shortcut] [register] cmd:', [cmd, isRegistered]);
if (isRegistered && !force) {
return;
}
globalShortcut.register(cmd, fn)
}
exports.isRegistered = function (cmd) {
return globalShortcut.isRegistered(cmd)
}
exports.unregister = function (cmd) {
globalShortcut.unregister(cmd)
}
// function showWindow () {
// MAIN_WINDOW.show()
// }
// function hideWindow () {
// MAIN_WINDOW.hide()
// }
exports = module.exports;