From e158cc25b345b33d6a5a49fe7848dbdd4dd44089 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Wed, 2 Sep 2020 20:40:35 +1000 Subject: [PATCH] remove extension menu hotkey conflict + make configurable --- CHANGELOG.md | 5 +++-- UPDATING.md | 2 +- mods/core/client.js | 2 -- mods/core/menu.js | 5 ++--- mods/core/mod.js | 6 ++++++ mods/core/tray.js | 14 ++++++++++++-- mods/weekly-view/mod.js | 2 +- pkg/helpers.md | 12 ++++++++++++ 8 files changed, 37 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 141b2b9..642a746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - [groupy-like tabbing](https://www.npmjs.com/package/electron-tabs) - [improved responsiveness](https://chrome.google.com/webstore/detail/notion%20%20-responsiveness-f/leadcilhbmibbkgbnjgmmnfgnnhmeddk) - [highlight/mark viewer](https://chrome.google.com/webstore/detail/notion%2B-mark-manager/hipgmnlpnimedfepbfbfiaobohhffcfc) +- [advanced math editor](https://github.com/Manueloccorso/NotionMathEditor_BrowserExtension) ### v0.9.0 (wip) @@ -21,14 +22,14 @@ a feature and cleanup update. - themes: "littlepig" (light + dark) = monospaced themes using emojis and colourful text. - extension: "font chooser" = customize fonts. for each option, type in the name of the font you would like to use, or leave it blank to not change anything. +- bugfix: made the open enhancements menu hotkey configurable and changed the default to `alt + e` + to remove conflict with the inline code highlight shortcut. // todo - improved: added individual text-colour rules for different background colours. - improved: added variables for callout colouring. - improved: tiling window-manager support (can hide titlebars entirely without dragarea/buttons). -- bugfix: made the open enhancements menu hotkey configurable and changed the default to `option/alt + e` - to remove conflict with the inline code highlight shortcut. - bugfix: block-level text colours are now changed properly. - bugfix: update property-layout to match notion changes again. - extension: "calendar scroll" = a button to scroll down to the current week for you. diff --git a/UPDATING.md b/UPDATING.md index d27e589..c0c9831 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -46,7 +46,7 @@ page and the [css theming documentation](DOCUMENTATION.md#variable-theming). "how can I set a custom window visibility toggle hotkey?" these options and more have been moved to the graphical menu, which can be opened from the -tray or with `CMD/CTRL+E` (while the notion app is focused). +tray or with `ALT+E` (while the notion app is focused). ## installing diff --git a/mods/core/client.js b/mods/core/client.js index 6951260..e30b2a3 100644 --- a/mods/core/client.js +++ b/mods/core/client.js @@ -19,8 +19,6 @@ module.exports = (store, __exports) => { // additional hotkeys document.defaultView.addEventListener('keyup', (event) => { if (event.code === 'F5') location.reload(); - if (event.key === 'e' && (event.ctrlKey || event.metaKey)) - electron.ipcRenderer.send('enhancer:open-extension-menu'); }); const attempt_interval = setInterval(enhance, 500); diff --git a/mods/core/menu.js b/mods/core/menu.js index 94435ee..9d3ae39 100644 --- a/mods/core/menu.js +++ b/mods/core/menu.js @@ -19,7 +19,6 @@ window['__start'] = async () => { document.defaultView.addEventListener('keyup', (event) => { if (event.code === 'F5') location.reload(); - if ((event.ctrlKey || event.metaKey) && event.key === 'e') browser.close(); if (!(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey) { if ( document.activeElement.parentElement.id === 'tags' && @@ -458,6 +457,7 @@ window['__start'] = async () => { $opt .querySelector(`#${opt.type}_${mod.id}--${opt.key}`) .addEventListener('change', (event) => { + modified(); if (opt.type === 'toggle') { store(mod.id)[opt.key] = event.target.checked; } else if (opt.type === 'file') { @@ -469,9 +469,8 @@ window['__start'] = async () => { } else store(mod.id)[opt.key] = typeof opt.value === 'number' - ? Number(event.target.value) + ? +event.target.value : event.target.value; - modified(); }); } $options.appendChild($opt); diff --git a/mods/core/mod.js b/mods/core/mod.js index 1f56beb..25a4d27 100644 --- a/mods/core/mod.js +++ b/mods/core/mod.js @@ -56,6 +56,12 @@ module.exports = { type: 'input', value: 'CommandOrControl+Shift+A', }, + { + key: 'menu_toggle', + label: 'open enhancements menu hotkey:', + type: 'input', + value: 'Alt+E', + }, ], hacks: { 'main/main.js': require('./tray.js'), diff --git a/mods/core/tray.js b/mods/core/tray.js index 489452e..0c004e9 100644 --- a/mods/core/tray.js +++ b/mods/core/tray.js @@ -40,7 +40,6 @@ module.exports = (store, __exports) => { webContents.send('enhancer:get-theme-vars', arg) ); }); - electron.ipcMain.on('enhancer:open-extension-menu', openExtensionMenu); function calculateWindowPos(width, height) { const screen = electron.screen.getDisplayNearestPoint({ @@ -157,7 +156,7 @@ module.exports = (store, __exports) => { { type: 'normal', label: 'Enhancements', - accelerator: 'CommandOrControl+E', + accelerator: store().menu_toggle, click: openExtensionMenu, }, { @@ -193,6 +192,17 @@ module.exports = (store, __exports) => { tray.setContextMenu(contextMenu); tray.setToolTip('Notion'); + electron.globalShortcut.register(store().menu_toggle, () => { + if ( + electron.BrowserWindow.getAllWindows() + .filter((win) => win.getTitle() !== 'notion-enhancer menu') + .some((win) => win.isFocused()) + ) { + openExtensionMenu(); + } else if (enhancer_menu && enhancer_menu.isFocused()) + enhancer_menu.close(); + }); + function showWindows() { const windows = electron.BrowserWindow.getAllWindows(); if (is_mac) electron.app.show(); diff --git a/mods/weekly-view/mod.js b/mods/weekly-view/mod.js index 2e66179..e18bede 100644 --- a/mods/weekly-view/mod.js +++ b/mods/weekly-view/mod.js @@ -46,7 +46,7 @@ module.exports = { : 0; for (let day of days) day.parentElement.parentElement.style.height = 0; - today.parentElement.parentElement.style.height = height; + if (today) today.parentElement.parentElement.style.height = height; } } }); diff --git a/pkg/helpers.md b/pkg/helpers.md index 52ba37e..5e84fe0 100644 --- a/pkg/helpers.md +++ b/pkg/helpers.md @@ -120,3 +120,15 @@ if (overwrite) { // do stuff } else console.info(' -- keeping file: skipping step.'); ``` + +--- + +```js +function createElement(html) { + const template = document.createElement('template'); + template.innerHTML = html.trim(); + return template.content.firstElementChild; +} +``` + +use `helpers.createElement(html)` to turn a html-valid string into an element to add to the page.