add tab keybinds: alt+1...9 tab select, ctrl+t new tab, ctrl+w close tab

need to remove ctrl+w from the window menu so it doesn't override and close the whole window
This commit is contained in:
dragonwocky 2020-10-13 23:07:08 +11:00
parent a580315593
commit 21b8c3ca15
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D
6 changed files with 134 additions and 40 deletions

View File

@ -2,7 +2,6 @@
**potential future features (not confirmed)**
- [groupy-like tabbing](https://www.npmjs.com/package/electron-tabs)
- [highlight/mark viewer](https://chrome.google.com/webstore/detail/notion%2B-mark-manager/hipgmnlpnimedfepbfbfiaobohhffcfc)
- [advanced math editor](https://github.com/Manueloccorso/NotionMathEditor_BrowserExtension)
@ -12,14 +11,15 @@ a flexibility update.
- new: mods can be reordered in the menu to control what order styling/scripts are added/executed in.
higher up on the list = higher priority of application = loaded last in order to override others.
(excluding core, which though pinned to the top of the list is always loaded first so theming
(excluding the core, which though pinned to the top of the list is always loaded first so theming
variables can be modified.)
- new: in-page columns disabled/wrapped and wider pages when the window is narrower than 600px
for improved responsiveness.
- new: relaunch button in tray menu.
- new: a core mod option to make transitions snappy/0s.
- new: a core mod option for a default page id/url (all new windows will load it instead of the
normal "most recent" page).
- improved: a core mod option to make transitions snappy/0s.
- new: css variables for increasing line spacing/paragraph margins.
- improved: menu will now respect integrated titlebar setting.
- improved: use keyup listeners instead of a globalShortcut for the enhancements menu toggle.
- bugfix: removed messenger emoji set as the provider no longer supports it.
@ -43,6 +43,14 @@ a flexibility update.
a fork of notion-deb-builder that does generate an app.asar has been created and is once again supported.
// todo
- new: menu shows theme conflicts.
- improved: default option for showing/hiding page properties.
- bugfix: night shift working on macOS.
- bugfix: windows are properly hidden/shown on macOS.
- extension: "tweaks" = common layout changes.
### v0.9.1 (2020-09-26)
- bugfix: font chooser will continue iterating through fonts after encountering a blank option.

View File

@ -47,6 +47,7 @@ then execute the following lines in the terminal:
sudo chmod -R a+wr /usr/local/lib/node_modules
sudo chmod -R a+wr /usr/local/bin
sudo chmod -R a+wr /Applications/Notion/Contents/Resources
sudo chmod -R a+wr /Applications/Notion.app/Contents/Resources
npm i -g notion-enhancer
```

View File

@ -16,18 +16,41 @@ module.exports = (store, __exports) => {
)}/app/helpers/notionIpc.js`),
{ toKeyEvent } = require('keyboardevent-from-electron-accelerator');
// additional hotkeys
document.defaultView.addEventListener('keyup', (event) => {
// additional hotkeys
if (event.code === 'F5') location.reload();
if (
!(store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {}).enabled
) {
// open menu on hotkey toggle
const hotkey = toKeyEvent(store().menu_toggle);
// open menu on hotkey toggle
const hotkey = toKeyEvent(store().menu_toggle);
let triggered = true;
for (let prop in hotkey)
if (hotkey[prop] !== event[prop]) triggered = false;
if (triggered) electron.ipcRenderer.send('enhancer:open-menu');
if ((store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {}).enabled) {
// switch between tabs via key modifier
const select_tab_modifier = toKeyEvent(
store('e1692c29-475e-437b-b7ff-3eee872e1a42').select_modifier
);
let triggered = true;
for (let prop in hotkey)
if (hotkey[prop] !== event[prop]) triggered = false;
if (triggered) electron.ipcRenderer.send('enhancer:open-menu');
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].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;
console.log(triggered, event);
if (triggered) electron.ipcRenderer.sendToHost('enhancer:close-tab');
}
});

View File

@ -52,18 +52,6 @@ module.exports = (store, __exports) => {
},
...rect,
});
electron.session
.fromPartition('persist:notion')
.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': [
"script-src 'self' 'unsafe-inline' 'unsafe-eval' enhancement: https://gist.github.com https://apis.google.com https://api.amplitude.com https://widget.intercom.io https://js.intercomcdn.com https://logs-01.loggly.com https://cdn.segment.com https://analytics.pgncs.notion.so https://checkout.stripe.com https://embed.typeform.com https://admin.typeform.com https://platform.twitter.com https://cdn.syndication.twimg.com; connect-src 'self' https://msgstore.www.notion.so wss://msgstore.www.notion.so https://notion-emojis.s3-us-west-2.amazonaws.com https://s3-us-west-2.amazonaws.com https://s3.us-west-2.amazonaws.com https://notion-production-snapshots-2.s3.us-west-2.amazonaws.com https: http: https://api.amplitude.com https://api.embed.ly https://js.intercomcdn.com https://api-iam.intercom.io wss://nexus-websocket-a.intercom.io https://logs-01.loggly.com https://api.segment.io https://api.pgncs.notion.so https://checkout.stripe.com https://cdn.contentful.com https://preview.contentful.com https://images.ctfassets.net https://api.unsplash.com https://boards-api.greenhouse.io; font-src 'self' data: https://cdnjs.cloudflare.com https://js.intercomcdn.com; img-src 'self' data: blob: https: https://platform.twitter.com https://syndication.twitter.com https://pbs.twimg.com https://ton.twimg.com; style-src 'self' 'unsafe-inline' enhancement: https://cdnjs.cloudflare.com https://github.githubassets.com https://platform.twitter.com https://ton.twimg.com; frame-src https: http:; media-src https: http:",
],
},
});
});
window.once('ready-to-show', function () {
if (
!store().openhidden ||

View File

@ -115,6 +115,33 @@ module.exports = (store, __exports) => {
from[1].classList.remove('slideIn');
this.$dragging = null;
});
document.addEventListener('keyup', (event) => {
// switch between tabs via key modifier
const select_tab_modifier = toKeyEvent(
store('e1692c29-475e-437b-b7ff-3eee872e1a42').select_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].includes(+event.key))
this.selectTab(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) this.newTab();
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;
console.log(triggered, event);
if (triggered) this.closeTab(this.views.current.id);
});
}
componentDidMount() {
@ -192,6 +219,7 @@ module.exports = (store, __exports) => {
? idToNotionURL(store().default_page)
: this.views.current.$el().src
);
this.views.html[id].getWebContents().openDevTools();
}
});
}
@ -228,24 +256,50 @@ module.exports = (store, __exports) => {
}
}
}
selectTab(num) {
num = +num;
if (num == 9) {
document
.querySelector('#tabs')
.children[
document.querySelector('#tabs').children.length - 2
].click();
} else if (
document.querySelector('#tabs').children[num - 1] &&
document.querySelector('#tabs').children.length > num
) {
document.querySelector('#tabs').children[num - 1].click();
}
}
communicateWithView(event) {
if (event.channel === 'enhancer:set-tab-theme') {
for (const style of event.args[0])
document.body.style.setProperty(style[0], style[1]);
}
if (
event.channel === 'enhancer:set-tab-title' &&
this.views.tabs[event.target.id]
) {
this.views.tabs[event.target.id].children[0].innerText =
event.args[0];
const electronWindow = electron.remote.getCurrentWindow();
if (
event.target.id == this.views.current.id &&
electronWindow.getTitle() !== event.args[0]
)
electronWindow.setTitle(event.args[0]);
switch (event.channel) {
case 'enhancer:set-tab-theme':
for (const style of event.args[0])
document.body.style.setProperty(style[0], style[1]);
break;
case 'enhancer:set-tab-title':
if (this.views.tabs[event.target.id]) {
this.views.tabs[event.target.id].children[0].innerText =
event.args[0];
const electronWindow = electron.remote.getCurrentWindow();
if (
event.target.id == this.views.current.id &&
electronWindow.getTitle() !== event.args[0]
)
electronWindow.setTitle(event.args[0]);
}
break;
case 'enhancer:select-tab':
this.selectTab(event.args[0]);
break;
case 'enhancer:new-tab':
this.newTab();
break;
case 'enhancer:close-tab':
if (event.target.id == this.views.current.id)
this.closeTab(+event.target.id);
break;
}
}
startSearch(isPeekView) {

View File

@ -16,4 +16,24 @@ module.exports = {
desc: 'have multiple notion pages open in a single window.',
version: '0.1.0',
author: 'dragonwocky',
options: [
{
key: 'select_modifier',
label: 'tab select modifier (key+1, +2, +3, ... +9):',
type: 'select',
value: ['Alt', 'Command', 'Control', 'Shift', 'Super'],
},
{
key: 'new_tab',
label: 'new tab keybinding:',
type: 'input',
value: 'CommandOrControl+T',
},
{
key: 'close_tab',
label: 'close tab keybinding:',
type: 'input',
value: 'CommandOrControl+W',
},
],
};