#204 empty hotkeys won't trigger

This commit is contained in:
dragonwocky 2020-11-11 23:29:48 +11:00
parent c5c02bc7e7
commit bc46ac39b0
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D
5 changed files with 73 additions and 77 deletions

View File

@ -37,6 +37,8 @@ npm link
notion-enhancer apply -y notion-enhancer apply -y
``` ```
to update the dev build, go into the downloaded folder and run `git pull`. (make sure any work-in-progress themes etc. are copied somewhere else safely first.)
to remove the dev build, go into the downloaded folder and run: to remove the dev build, go into the downloaded folder and run:
```sh ```sh

View File

@ -22,6 +22,7 @@ module.exports = (store, __exports) => {
// additional hotkeys // additional hotkeys
if (event.key === 'F5') location.reload(); if (event.key === 'F5') location.reload();
// open menu on hotkey toggle // open menu on hotkey toggle
if (store().menu_toggle) {
const hotkey = toKeyEvent(store().menu_toggle); const hotkey = toKeyEvent(store().menu_toggle);
let triggered = true; let triggered = true;
for (let prop in hotkey) for (let prop in hotkey)
@ -31,11 +32,12 @@ module.exports = (store, __exports) => {
) )
triggered = false; triggered = false;
if (triggered) electron.ipcRenderer.send('enhancer:open-menu'); if (triggered) electron.ipcRenderer.send('enhancer:open-menu');
}
if (tabsEnabled) { if (tabsEnabled) {
const tabStore = () => store('e1692c29-475e-437b-b7ff-3eee872e1a42');
if (tabStore().select_modifier) {
// switch between tabs via key modifier // switch between tabs via key modifier
const select_tab_modifier = toKeyEvent( const select_tab_modifier = toKeyEvent(select_tab_modifier);
store('e1692c29-475e-437b-b7ff-3eee872e1a42').select_modifier
);
let triggered = true; let triggered = true;
for (let prop in select_tab_modifier) for (let prop in select_tab_modifier)
if (select_tab_modifier[prop] !== event[prop]) triggered = false; if (select_tab_modifier[prop] !== event[prop]) triggered = false;
@ -56,22 +58,23 @@ module.exports = (store, __exports) => {
].includes(event.key) ].includes(event.key)
) )
electron.ipcRenderer.sendToHost('enhancer:select-tab', event.key); electron.ipcRenderer.sendToHost('enhancer:select-tab', event.key);
}
if (tabStore().new_tab) {
// create/close tab keybindings // create/close tab keybindings
const new_tab_keybinding = toKeyEvent( const new_tab_keybinding = toKeyEvent(tabStore().new_tab);
store('e1692c29-475e-437b-b7ff-3eee872e1a42').new_tab let triggered = true;
);
triggered = true;
for (let prop in new_tab_keybinding) for (let prop in new_tab_keybinding)
if (new_tab_keybinding[prop] !== event[prop]) triggered = false; if (new_tab_keybinding[prop] !== event[prop]) triggered = false;
if (triggered) electron.ipcRenderer.sendToHost('enhancer:new-tab'); if (triggered) electron.ipcRenderer.sendToHost('enhancer:new-tab');
const close_tab_keybinding = toKeyEvent( }
store('e1692c29-475e-437b-b7ff-3eee872e1a42').close_tab if (tabStore().close_tab) {
); const close_tab_keybinding = toKeyEvent(tabStore().close_tab);
triggered = true; let triggered = true;
for (let prop in close_tab_keybinding) for (let prop in close_tab_keybinding)
if (close_tab_keybinding[prop] !== event[prop]) triggered = false; if (close_tab_keybinding[prop] !== event[prop]) triggered = false;
if (triggered) electron.ipcRenderer.sendToHost('enhancer:close-tab'); if (triggered) electron.ipcRenderer.sendToHost('enhancer:close-tab');
} }
}
}); });
const attempt_interval = setInterval(enhance, 500); const attempt_interval = setInterval(enhance, 500);

View File

@ -145,6 +145,7 @@ window['__start'] = async () => {
) )
$popup.classList.remove('visible'); $popup.classList.remove('visible');
// close window on hotkey toggle // close window on hotkey toggle
if (coreStore().menu_toggle) {
const hotkey = toKeyEvent(coreStore().menu_toggle); const hotkey = toKeyEvent(coreStore().menu_toggle);
let triggered = true; let triggered = true;
for (let prop in hotkey) for (let prop in hotkey)
@ -155,6 +156,7 @@ window['__start'] = async () => {
triggered = false; triggered = false;
if (triggered || ((event.ctrlKey || event.metaKey) && event.key === 'w')) if (triggered || ((event.ctrlKey || event.metaKey) && event.key === 'w'))
electron.remote.getCurrentWindow().close(); electron.remote.getCurrentWindow().close();
}
// focus search // focus search
const meta = const meta =
!(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey; !(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey;

View File

@ -1010,19 +1010,6 @@ module.exports = (store, __exports) => {
document.body.className = `notion-${theme}-theme`; document.body.className = `notion-${theme}-theme`;
}); });
// open menu on hotkey toggle
document.addEventListener('keyup', (event) => {
const hotkey = toKeyEvent(store().menu_toggle);
let triggered = true;
for (let prop in hotkey)
if (
hotkey[prop] !== event[prop] &&
!(prop === 'key' && event[prop] === 'Dead')
)
triggered = false;
if (triggered) electron.ipcRenderer.send('enhancer:open-menu');
});
const parsed = url.parse(window.location.href, true), const parsed = url.parse(window.location.href, true),
notionUrl = notionUrl =
parsed.query.path || parsed.query.path ||

View File

@ -246,11 +246,13 @@ module.exports = (store, __exports) => {
else showWindows(windows); else showWindows(windows);
} }
tray.on('click', toggleWindows); tray.on('click', toggleWindows);
if (store().hotkey) {
electron.globalShortcut.register(store().hotkey, () => { electron.globalShortcut.register(store().hotkey, () => {
const windows = getAllWindows(); const windows = getAllWindows();
if (windows.some((win) => win.isFocused() && win.isVisible())) if (windows.some((win) => win.isFocused() && win.isVisible()))
hideWindows(windows); hideWindows(windows);
else showWindows(windows); else showWindows(windows);
}); });
}
}); });
}; };