diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f381af8..a3d4552 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,6 +37,8 @@ npm link 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: ```sh diff --git a/mods/core/client.js b/mods/core/client.js index a7460e9..7b5b082 100644 --- a/mods/core/client.js +++ b/mods/core/client.js @@ -22,55 +22,58 @@ module.exports = (store, __exports) => { // additional hotkeys if (event.key === 'F5') location.reload(); // open menu on hotkey toggle - 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'); - if (tabsEnabled) { - // switch between tabs via key modifier - const select_tab_modifier = toKeyEvent( - store('e1692c29-475e-437b-b7ff-3eee872e1a42').select_modifier - ); + if (store().menu_toggle) { + const hotkey = toKeyEvent(store().menu_toggle); let triggered = true; - for (let prop in select_tab_modifier) - if (select_tab_modifier[prop] !== event[prop]) triggered = false; - if ( - triggered && - [ - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - 'ArrowRight', - 'ArrowLeft', - ].includes(event.key) - ) - electron.ipcRenderer.sendToHost('enhancer:select-tab', event.key); - // create/close tab keybindings - const new_tab_keybinding = toKeyEvent( - store('e1692c29-475e-437b-b7ff-3eee872e1a42').new_tab - ); - triggered = true; - for (let prop in new_tab_keybinding) - if (new_tab_keybinding[prop] !== event[prop]) triggered = false; - if (triggered) electron.ipcRenderer.sendToHost('enhancer:new-tab'); - const close_tab_keybinding = toKeyEvent( - store('e1692c29-475e-437b-b7ff-3eee872e1a42').close_tab - ); - triggered = true; - for (let prop in close_tab_keybinding) - if (close_tab_keybinding[prop] !== event[prop]) triggered = false; - if (triggered) electron.ipcRenderer.sendToHost('enhancer:close-tab'); + 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'); + } + if (tabsEnabled) { + const tabStore = () => store('e1692c29-475e-437b-b7ff-3eee872e1a42'); + if (tabStore().select_modifier) { + // switch between tabs via key modifier + const select_tab_modifier = toKeyEvent(select_tab_modifier); + let triggered = true; + for (let prop in select_tab_modifier) + if (select_tab_modifier[prop] !== event[prop]) triggered = false; + if ( + triggered && + [ + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + 'ArrowRight', + 'ArrowLeft', + ].includes(event.key) + ) + electron.ipcRenderer.sendToHost('enhancer:select-tab', event.key); + } + if (tabStore().new_tab) { + // create/close tab keybindings + const new_tab_keybinding = toKeyEvent(tabStore().new_tab); + let triggered = true; + for (let prop in new_tab_keybinding) + if (new_tab_keybinding[prop] !== event[prop]) triggered = false; + if (triggered) electron.ipcRenderer.sendToHost('enhancer:new-tab'); + } + if (tabStore().close_tab) { + const close_tab_keybinding = toKeyEvent(tabStore().close_tab); + let triggered = true; + for (let prop in close_tab_keybinding) + if (close_tab_keybinding[prop] !== event[prop]) triggered = false; + if (triggered) electron.ipcRenderer.sendToHost('enhancer:close-tab'); + } } }); diff --git a/mods/core/enhancerMenu.js b/mods/core/enhancerMenu.js index c43b107..72d9edc 100644 --- a/mods/core/enhancerMenu.js +++ b/mods/core/enhancerMenu.js @@ -145,16 +145,18 @@ window['__start'] = async () => { ) $popup.classList.remove('visible'); // close window on hotkey toggle - const hotkey = toKeyEvent(coreStore().menu_toggle); - let triggered = true; - for (let prop in hotkey) - if ( - hotkey[prop] !== event[prop] && - !(prop === 'key' && event[prop] === 'Dead') - ) - triggered = false; - if (triggered || ((event.ctrlKey || event.metaKey) && event.key === 'w')) - electron.remote.getCurrentWindow().close(); + if (coreStore().menu_toggle) { + const hotkey = toKeyEvent(coreStore().menu_toggle); + let triggered = true; + for (let prop in hotkey) + if ( + hotkey[prop] !== event[prop] && + !(prop === 'key' && event[prop] === 'Dead') + ) + triggered = false; + if (triggered || ((event.ctrlKey || event.metaKey) && event.key === 'w')) + electron.remote.getCurrentWindow().close(); + } // focus search const meta = !(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey; diff --git a/mods/core/render.js b/mods/core/render.js index 8911daf..fb1ec76 100644 --- a/mods/core/render.js +++ b/mods/core/render.js @@ -1010,19 +1010,6 @@ module.exports = (store, __exports) => { 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), notionUrl = parsed.query.path || diff --git a/mods/core/tray.js b/mods/core/tray.js index 1adb087..f43f47a 100644 --- a/mods/core/tray.js +++ b/mods/core/tray.js @@ -246,11 +246,13 @@ module.exports = (store, __exports) => { else showWindows(windows); } tray.on('click', toggleWindows); - electron.globalShortcut.register(store().hotkey, () => { - const windows = getAllWindows(); - if (windows.some((win) => win.isFocused() && win.isVisible())) - hideWindows(windows); - else showWindows(windows); - }); + if (store().hotkey) { + electron.globalShortcut.register(store().hotkey, () => { + const windows = getAllWindows(); + if (windows.some((win) => win.isFocused() && win.isVisible())) + hideWindows(windows); + else showWindows(windows); + }); + } }); };