|
@@ -8,23 +8,41 @@ exports.setup = function () {
|
|
|
storage.iniPreferences();
|
|
storage.iniPreferences();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 快捷键注册
|
|
|
|
|
+ * @param {Object} shortcutObj - shortcut object
|
|
|
|
|
+ * @param {Boolean} force - force register
|
|
|
|
|
+ * @param {Function} fn - callback
|
|
|
|
|
+ * @return {Boolean}
|
|
|
|
|
+ */
|
|
|
exports.register = function (shortcutObj, force = true, fn) {
|
|
exports.register = function (shortcutObj, force = true, fn) {
|
|
|
if (!shortcutObj['id'] || !shortcutObj['name'] || !shortcutObj['cmd']) {
|
|
if (!shortcutObj['id'] || !shortcutObj['name'] || !shortcutObj['cmd']) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
const isRegistered = this.isRegistered(shortcutObj['cmd']);
|
|
const isRegistered = this.isRegistered(shortcutObj['cmd']);
|
|
|
- // console.log('[shortcut] [register] cmd:', [shortcutObj['cmd'], isRegistered]);
|
|
|
|
|
if (isRegistered && !force) {
|
|
if (isRegistered && !force) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
storage.setShortcuts(shortcutObj);
|
|
storage.setShortcuts(shortcutObj);
|
|
|
globalShortcut.register(shortcutObj['cmd'], fn)
|
|
globalShortcut.register(shortcutObj['cmd'], fn)
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 快捷键是否注册成功
|
|
|
|
|
+ * @param {String} cmd - shortcut string
|
|
|
|
|
+ * @return {Boolean}
|
|
|
|
|
+ */
|
|
|
exports.isRegistered = function (cmd) {
|
|
exports.isRegistered = function (cmd) {
|
|
|
return globalShortcut.isRegistered(cmd)
|
|
return globalShortcut.isRegistered(cmd)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 注销全局快捷键
|
|
|
|
|
+ * @param {String} cmd - shortcut string
|
|
|
|
|
+ * @return {Boolean}
|
|
|
|
|
+ */
|
|
|
exports.unregister = function (cmd) {
|
|
exports.unregister = function (cmd) {
|
|
|
globalShortcut.unregister(cmd)
|
|
globalShortcut.unregister(cmd)
|
|
|
}
|
|
}
|