Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Implement global shortcuts #66

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,21 +351,20 @@ function onReady () {
break;

// Global Shortcut
case consts.eventNames.globalShortcutCmdRegister:
const isRegistered = globalShortcut.register(json.globalShortcut.accelerator, () => {
client.write(json.targetID, consts.eventNames.globalShortcutEventTriggered, {GlobalShortcut:{accelerator: json.globalShortcut.accelerator}});
case consts.eventNames.globalShortcutEventRegistered:
const isRegistered = globalShortcut.register(json.globalShortcuts.accelerator, () => {
client.write(json.targetID, consts.eventNames.globalShortcutEventTriggered, {GlobalShortcuts:{accelerator: json.globalShortcuts.accelerator}});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use globalShortcuts with a lower g instead of GlobalShortcuts in the json. Same thing below

});
client.write(json.targetID, consts.eventNames.globalShortcutEventProcessFinished, {GlobalShortcut:{isRegistered: isRegistered}});
client.write(json.targetID, consts.eventNames.globalShortcutEventProcessFinished, {GlobalShortcuts:{isRegistered: isRegistered}});
break;
case consts.eventNames.globalShortcutCmdIsRegistered:
const isRegistered2 = globalShortcut.isRegistered(json.globalShortcut.accelerator);
client.write(json.targetID, consts.eventNames.globalShortcutEventProcessFinished, {GlobalShortcut:{isRegistered: isRegistered2}});
case consts.eventNames.globalShortcutEventIsRegistered:
client.write(json.targetID, consts.eventNames.globalShortcutEventProcessFinished, {GlobalShortcuts:{isRegistered: globalShortcut.isRegistered(json.globalShortcuts.accelerator)}});
break;
case consts.eventNames.globalShortcutCmdUnregister:
globalShortcut.unregister(json.globalShortcut.accelerator);
case consts.eventNames.globalShortcutEventUnregistered:
globalShortcut.unregister(json.globalShortcuts.accelerator);
client.write(json.targetID, consts.eventNames.globalShortcutEventProcessFinished);
break
case consts.eventNames.globalShortcutCmdUnregisterAll:
case consts.eventNames.globalShortcutEventUnregisteredAll:
globalShortcut.unregisterAll();
client.write(json.targetID, consts.eventNames.globalShortcutEventProcessFinished);
break
Expand Down
12 changes: 6 additions & 6 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ module.exports = {
dockEventHidden: "dock.event.hidden",
dockEventIconSet: "dock.event.icon.set",
dockEventShown: "dock.event.shown",
globalShortcutCmdRegister: "global.shortcut.cmd.register",
globalShortcutCmdIsRegistered: "global.shortcut.cmd.is.register",
globalShortcutCmdUnregister: "global.shortcut.cmd.unregister",
globalShortcutCmdUnregisterAll: "global.shortcut.cmd.unregister.all",
globalShortcutEventProcessFinished: "global.shortcut.event.process.finished",
globalShortcutEventTriggered: "global.shortcut.event.triggered",
globalShortcutEventRegistered: "global.shortcuts.event.registered",
globalShortcutEventIsRegistered: "global.shortcuts.event.is.registered",
globalShortcutEventUnregistered: "global.shortcuts.event.unregistered",
globalShortcutEventUnregisteredAll: "global.shortcuts.event.unregistered.all",
globalShortcutEventProcessFinished: "global.shortcuts.event.process.finished",
globalShortcutEventTriggered: "global.shortcuts.event.triggered",
Copy link
Owner

@asticode asticode Sep 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We misunderstood each other: could you rollback all globalShortcutCmd... events but replace the globalShortcutEventProcessFinished with:

  • global.shortcuts.event.
  • global.shortcuts.event.is.
  • global.shortcuts.event.
  • global.shortcuts.event.unregistered.all

Also, could you make sure there's an s at the end of globalShortcut in the key?

This should look like this:

globalShortcutsCmdRegister: "global.shortcuts.cmd.register",
globalShortcutsCmdIsRegistered: "global.shortcuts.cmd.is.register",
globalShortcutsCmdUnregister: "global.shortcuts.cmd.unregister",
globalShortcutsCmdUnregisterAll: "global.shortcuts.cmd.unregister.all",
globalShortcutsEventRegistered: "global.shortcuts.event.registered",
globalShortcutsEventIsRegistered: "global.shortcuts.event.is.registered",
globalShortcutsEventUnregistered: "global.shortcuts.event.unregistered",
globalShortcutsEventUnregisteredAll: "global.shortcuts.event.unregistered.all",
globalShortcutsEventProcessFinished: "global.shortcuts.event.process.finished",
globalShortcutsEventTriggered: "global.shortcuts.event.triggered",

globalShortcutsCmd... are the events received by javascript, globalShortcutsEvent... are the events sent by javascript.

ipcCmdLog: "ipc.cmd.log",
ipcCmdMessage: "ipc.cmd.message",
ipcCmdMessageCallback: "ipc.cmd.message.callback",
Expand Down