From add5bb8d9c58456e5d72c78d7b58bf55f665bf8f Mon Sep 17 00:00:00 2001 From: Alejandro Romano Date: Sun, 11 Oct 2020 16:27:16 -0300 Subject: [PATCH 1/6] Add font sizing to page previews (#153) Font sizes remained the same as default for page previews. They are not affected by custom font sizes. This change takes the same variables the full open page and apply it. Tested and working 10/10 Full open pages: .notion-frame Overlay, preview pages: .notion-overlay-container (and .notion-scroller.vertical WITHOUT .horizontal) --- mods/core/css/theme.css | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mods/core/css/theme.css b/mods/core/css/theme.css index 735fad2..faeac8f 100644 --- a/mods/core/css/theme.css +++ b/mods/core/css/theme.css @@ -152,7 +152,8 @@ [style*='SFMono-Regular'] { font-family: var(--theme--font_code) !important; } -.notion-frame .notion-page-block div[placeholder='Untitled'] { +.notion-frame .notion-page-block div[placeholder='Untitled'], +.notion-overlay-container .notion-page-block div[placeholder='Untitled']{ font-size: calc( var(--theme--font_body-size) * (var(--theme--font_heading1-size) / 1em) ) !important; @@ -172,15 +173,16 @@ var(--theme--font_body-size) * (var(--theme--font_heading3-size) / 1em) ) !important; } -.notion-frame .notion-scroller.vertical.horizontal [style*='font-size: 14px'] { +.notion-frame .notion-scroller.vertical.horizontal [style*='font-size: 14px'], +.notion-overlay-container .notion-scroller.vertical [style*='font-size: 14px']{ font-size: var(--theme--font_label-size) !important; } -.notion-frame .notion-scroller.vertical.horizontal .notion-page-content { +.notion-frame .notion-scroller.vertical.horizontal .notion-page-content, +.notion-overlay-container .notion-scroller.vertical .notion-page-content { font-size: var(--theme--font_body-size) !important; } -.notion-frame - .notion-scroller.vertical.horizontal - .notion-page-content[style*='font-size: 14px'] { +.notion-frame .notion-scroller.vertical.horizontal .notion-page-content[style*='font-size: 14px'], +.notion-overlay-container .notion-scroller.vertical .notion-page-content[style*='font-size: 14px'] { font-size: var(--theme--font_body-size_small) !important; } .notion-code-block [placeholder=' '] { From 9da9c2aee4593c09b6a847aff47d33a1bc23931f Mon Sep 17 00:00:00 2001 From: Mimi Shahzad <68070585+mimi-shahzad@users.noreply.github.com> Date: Mon, 12 Oct 2020 04:30:58 -0400 Subject: [PATCH 2/6] squashed last 5 commits together (#154) --- mods/dracula-theme/mod.js | 14 +++++++++----- mods/dracula-theme/styles.css | 30 ++++++++++++++++-------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/mods/dracula-theme/mod.js b/mods/dracula-theme/mod.js index cd3668a..c14b172 100644 --- a/mods/dracula-theme/mod.js +++ b/mods/dracula-theme/mod.js @@ -1,5 +1,4 @@ /* - * dracula-theme * (c) 2020 u/mimi-shahzad * (c) 2020 Dracula Theme * under the MIT license @@ -11,8 +10,13 @@ module.exports = { id: '033bff54-50ba-4cec-bdc0-b2ca7e307086', tags: ['theme', 'dark'], name: 'dracula', - desc: - 'a theme based on the popular dracula color palette originally by zeno rocha and friends. ', - version: '0.1.0', - author: 'mimi-shahzad', + + desc: 'a theme based on the popular Dracula color palette originally by Zeno Rocha and friends. ', + version: '0.1', + author: { + name: 'mimi-shahzad', + link: 'https://github.com/mimi-shahzad', + avatar: 'https://secure.gravatar.com/avatar/86c98dec3a06245dbf2291deb44441f5', + } + }; diff --git a/mods/dracula-theme/styles.css b/mods/dracula-theme/styles.css index 67e9a74..ecb3868 100644 --- a/mods/dracula-theme/styles.css +++ b/mods/dracula-theme/styles.css @@ -1,5 +1,6 @@ /* - * dracula-theme + * Dracula Theme Palette + * (c) 2020 dragonwocky (https://dragonwocky.me/) * (c) 2020 u/mimi-shahzad * (c) 2020 Dracula Theme * under the MIT license @@ -11,17 +12,17 @@ --theme_dark--overlay: #282a36; --theme_dark--dragarea: #282a36; - --theme_dark--font_sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', - Helvetica, 'Apple Color Emoji', Arial, sans-serif, 'Segoe UI Emoji', - 'Segoe UI Symbol'; + --theme_dark--font_sans: -apple-system, BlinkMacSystemFont, + 'Segoe UI', Helvetica, 'Apple Color Emoji', Arial, sans-serif, + 'Segoe UI Emoji', 'Segoe UI Symbol'; - --theme_dark--scrollbar: #282a36; + --theme_dark--scrollbar: #f8f8f2; --theme_dark--scrollbar_hover: #6272a4; - --theme_dark--card: #6272a4; - --theme_dark--gallery: #282a36; + --theme_dark--card: #454158; + --theme_dark--gallery: #6272a4; --theme_dark--table-border: #6272a4; - --theme_dark--interactive_hover: #282a36; + --theme_dark--interactive_hover: #bd93f9; --theme_dark--button_close: #ff5555; --theme_dark--selected: #454158; @@ -37,7 +38,7 @@ --theme_dark--danger_border: #ffb86c; --theme_dark--text: #f8f8f2; - --theme_dark--text_ui: #f8f8f2; + --theme_dark--text_ui: #bd93f9; --theme_dark--text_ui_info: #f8f8f2; --theme_dark--text_gray: #454158; @@ -51,7 +52,7 @@ --theme_dark--text_red: #ff5555; --theme_dark--select-text: #000000; - --theme_dark--select_gray: #454158; + --theme_dark--select_gray: #f8f8f2; --theme_dark--select_brown: #6272a4; --theme_dark--select_orange: #ffb86c; --theme_dark--select_yellow: #f1fa8c; @@ -72,7 +73,7 @@ --theme_dark--bg_pink: var(--theme_dark--select_pink); --theme_dark--bg_red: var(--theme_dark--select_red); - --theme_dark--line-text: #000000; + --theme_dark--line-text: #f8f8f2; --theme_dark--line_gray: #454158; --theme_dark--line_brown: #6272a4; --theme_dark--line_orange: #ffb86c; @@ -83,7 +84,7 @@ --theme_dark--line_pink: #ff79c6; --theme_dark--line_red: #ff5555; - --theme_dark--callout-text: var(--theme_dark--line-text); + --theme_dark--callout-text: var(--theme_dark--line-green); --theme_dark--callout_gray: var(--theme_dark--line_gray); --theme_dark--callout_brown: var(--theme_dark--line_brown); --theme_dark--callout_orange: var(--theme_dark--line_orange); @@ -95,7 +96,7 @@ --theme_dark--callout_red: var(--theme_dark--line_red); --theme_dark--code_inline-text: #50fa7b; - --theme_dark--code_inline-background: #44475a; + --theme_dark--code_inline-background:#44475a; --theme_dark--code-text: var(--theme_dark--text); --theme_dark--code-background: #44475a; --theme_dark--code_function: var(--theme_dark--text_blue); @@ -152,7 +153,8 @@ [style*='height: 4px;'] > .notion-selectable.notion-collection_view_page-block > *, -.notion-dark-theme .notion-calendar-view-day[style*='background: #282a36;'], +.notion-dark-theme + .notion-calendar-view-day[style*='background: #282a36;'], .DayPicker-Day--today, .notion-dark-theme .DayPicker:not(.DayPicker--interactionDisabled) From d2cd8baa7750ab715df6c88d8fa47409f08d211d Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Mon, 12 Oct 2020 19:36:34 +1100 Subject: [PATCH 3/6] un-break titlebar+menu (not sure how it was broken?) --- CHANGELOG.md | 1 + mods/core/menu.js | 120 ++++++++++++++++++++++---------------------- mods/core/render.js | 30 ++++++++--- pkg/helpers.js | 5 ++ pkg/loader.js | 5 -- 5 files changed, 90 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a8738..81a3c9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ a flexibility update. - bugfix: remove focus mode footer from neutral theme. - bugfix: improvements to the colour theming, particularly to make real- and fake-light/dark modes (as applied by the night shift extension) look consistent. +- bugfix: font sizing applied to overlays/previews. - tweak: sticky table/list rows. - theme: "material ocean" = an oceanic colour palette. - theme: "dracula" = a theme based on the popular dracula color palette diff --git a/mods/core/menu.js b/mods/core/menu.js index 5925e28..bb5913f 100644 --- a/mods/core/menu.js +++ b/mods/core/menu.js @@ -14,47 +14,43 @@ const store = require('../../pkg/store.js'), { toKeyEvent } = require('keyboardevent-from-electron-accelerator'); window['__start'] = async () => { + // mod loader + const modules = helpers.getEnhancements(); + if (modules.loaded.length) + console.info( + ` enhancements loaded: ${modules.loaded + .map((mod) => mod.name) + .join(', ')}.` + ); + if (modules.invalid.length) { + createAlert( + 'error', + `invalid mods found: ${modules.invalid + .map((mod) => `${mod}`) + .join(', ')}.` + ).append(); + } + const coreStore = (...args) => { + const mod = modules.loaded.find( + (m) => m.id === '0f0bf8b6-eae6-4273-b307-8fc43f2ee082' + ); + return !args.length + ? store(mod.id, mod.defaults) + : args.length === 1 && typeof args[0] === 'object' + ? store(mod.id, { ...mod.defaults, ...args[0] }) + : store(args[0], { ...mod.defaults, ...args[1] }); + }; + const buttons = require('./buttons.js')(() => ({ '72886371-dada-49a7-9afc-9f275ecf29d3': { enabled: (store('mods')['72886371-dada-49a7-9afc-9f275ecf29d3'] || {}) .enabled, }, - tiling_mode: store('0f0bf8b6-eae6-4273-b307-8fc43f2ee082').tiling_mode, - frameless: store('0f0bf8b6-eae6-4273-b307-8fc43f2ee082').frameless, + tiling_mode: coreStore().tiling_mode, + frameless: coreStore().frameless, })); document.querySelector('#titlebar').appendChild(buttons.element); - document.defaultView.addEventListener('keyup', (event) => { - if (event.code === 'F5') location.reload(); - const meta = - !(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey; - if ( - meta && - document.activeElement.parentElement.id === 'tags' && - event.key === 'Enter' - ) - document.activeElement.click(); - if (document.activeElement.tagName.toLowerCase() === 'input') { - if (document.activeElement.type === 'checkbox' && event.key === 'Enter') - document.activeElement.checked = !document.activeElement.checked; - if ( - ['Escape', 'Enter'].includes(event.key) && - document.activeElement.type !== 'checkbox' && - (document.activeElement.parentElement.id !== 'search' || - event.key === 'Escape') - ) - document.activeElement.blur(); - } else if (meta && event.key === '/') - document.querySelector('#search > input').focus(); - if ( - (event.ctrlKey || event.metaKey) && - event.key === 'f' && - !event.altKey && - !event.shiftKey - ) - document.querySelector('#search > input').focus(); - }); - electron.ipcRenderer.send('enhancer:get-menu-theme'); electron.ipcRenderer.on('enhancer:set-menu-theme', (event, theme) => { for (const style of theme) @@ -120,26 +116,10 @@ window['__start'] = async () => { ).prepend(); }); - // mod loader - const modules = helpers.getEnhancements(); - if (modules.loaded.length) - console.info( - ` enhancements loaded: ${modules.loaded - .map((mod) => mod.name) - .join(', ')}.` - ); - if (modules.invalid.length) { - createAlert( - 'error', - `invalid mods found: ${modules.invalid - .map((mod) => `${mod}`) - .join(', ')}.` - ).append(); - } - - // further-configuration popup const $popup = document.querySelector('#popup'); document.addEventListener('keyup', (event) => { + if (event.code === 'F5') location.reload(); + // further-configuration popup if ( $popup.classList.contains('visible') && ['Enter', 'Escape'].includes(event.key) @@ -147,18 +127,41 @@ window['__start'] = async () => { $popup.classList.remove('visible'); // close window on hotkey toggle console.log(); - const hotkey = toKeyEvent( - store('0f0bf8b6-eae6-4273-b307-8fc43f2ee082', { - menu_toggle: modules.loaded - .find((m) => m.id === '0f0bf8b6-eae6-4273-b307-8fc43f2ee082') - .options.find((o) => o.key === 'menu_toggle').value, - }).menu_toggle - ); + const hotkey = toKeyEvent(coreStore().menu_toggle); let triggered = true; for (let prop in hotkey) if (hotkey[prop] !== event[prop]) triggered = false; if (triggered) electron.remote.getCurrentWindow().close(); + // focus search + const meta = + !(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey; + if ( + meta && + document.activeElement.parentElement.id === 'tags' && + event.key === 'Enter' + ) + document.activeElement.click(); + if (document.activeElement.tagName.toLowerCase() === 'input') { + if (document.activeElement.type === 'checkbox' && event.key === 'Enter') + document.activeElement.checked = !document.activeElement.checked; + if ( + ['Escape', 'Enter'].includes(event.key) && + document.activeElement.type !== 'checkbox' && + (document.activeElement.parentElement.id !== 'search' || + event.key === 'Escape') + ) + document.activeElement.blur(); + } else if (meta && event.key === '/') + document.querySelector('#search > input').focus(); + if ( + (event.ctrlKey || event.metaKey) && + event.key === 'f' && + !event.altKey && + !event.shiftKey + ) + document.querySelector('#search > input').focus(); }); + let colorpicker_target = null; const $colorpicker = colorjoe .rgb('colorpicker') @@ -171,7 +174,6 @@ window['__start'] = async () => { store(colorpicker_target.id)[colorpicker_target.key] = color.css(); }) .update(); - document .querySelector('#colorpicker') .appendChild( diff --git a/mods/core/render.js b/mods/core/render.js index 44e3045..32437df 100644 --- a/mods/core/render.js +++ b/mods/core/render.js @@ -9,7 +9,6 @@ const url = require('url'), path = require('path'), electron = require('electron'), - browserWindow = electron.remote.getCurrentWindow(), { __notion } = require('../../pkg/helpers.js'), config = require(`${__notion}/app/config.js`), constants = require(`${__notion}/app/shared/constants.js`), @@ -219,11 +218,12 @@ module.exports = (store, __exports) => { ) { 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 && - browserWindow.getTitle() !== event.args[0] + electronWindow.getTitle() !== event.args[0] ) - browserWindow.setTitle(event.args[0]); + electronWindow.setTitle(event.args[0]); } } startSearch(isPeekView) { @@ -426,25 +426,41 @@ module.exports = (store, __exports) => { this.setState({ zoomFactor }); } ); + let electronWindow; + try { + electronWindow = electron.remote.getCurrentWindow(); + } catch (error) { + notionIpc.sendToMain('notion:log-error', { + level: 'error', + from: 'index', + type: 'GetCurrentWindowError', + error: error.message, + }); + } + if (!electronWindow) { + this.setState({ error: true }); + this.handleReload(); + return; + } const sendFullScreenChangeEvent = () => { notionIpc.sendIndexToNotion( $notion, 'notion:full-screen-changed' ); }; - browserWindow.addListener( + electronWindow.addListener( 'enter-full-screen', sendFullScreenChangeEvent ); - browserWindow.addListener( + electronWindow.addListener( 'leave-full-screen', sendFullScreenChangeEvent ); - browserWindow.addListener( + electronWindow.addListener( 'enter-html-full-screen', sendFullScreenChangeEvent ); - browserWindow.addListener( + electronWindow.addListener( 'leave-html-full-screen', sendFullScreenChangeEvent ); diff --git a/pkg/helpers.js b/pkg/helpers.js index 325433f..d64c628 100644 --- a/pkg/helpers.js +++ b/pkg/helpers.js @@ -130,6 +130,11 @@ function getEnhancements() { )) ) throw Error; + mod.defaults = {}; + for (let opt of mod.options || []) + mod.defaults[opt.key] = Array.isArray(opt.value) + ? opt.value[0] + : opt.value; modules.IDs.push(mod.id); modules.loaded.push({ ...mod, diff --git a/pkg/loader.js b/pkg/loader.js index 00c7d27..e5c3bcd 100644 --- a/pkg/loader.js +++ b/pkg/loader.js @@ -84,11 +84,6 @@ module.exports = function (__file, __exports) { }); } if (mod.hacks && mod.hacks[__file]) { - mod.defaults = {}; - for (let opt of mod.options || []) - mod.defaults[opt.key] = Array.isArray(opt.value) - ? opt.value[0] - : opt.value; mod.hacks[__file]( (...args) => !args.length From d82dda1ff843c1e6fb6c635d79ff666c426ad87f Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Mon, 12 Oct 2020 19:36:51 +1100 Subject: [PATCH 4/6] Revert "squashed last 5 commits together (#154)" This reverts commit 9da9c2aee4593c09b6a847aff47d33a1bc23931f. --- mods/dracula-theme/mod.js | 14 +++++--------- mods/dracula-theme/styles.css | 30 ++++++++++++++---------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/mods/dracula-theme/mod.js b/mods/dracula-theme/mod.js index c14b172..cd3668a 100644 --- a/mods/dracula-theme/mod.js +++ b/mods/dracula-theme/mod.js @@ -1,4 +1,5 @@ /* + * dracula-theme * (c) 2020 u/mimi-shahzad * (c) 2020 Dracula Theme * under the MIT license @@ -10,13 +11,8 @@ module.exports = { id: '033bff54-50ba-4cec-bdc0-b2ca7e307086', tags: ['theme', 'dark'], name: 'dracula', - - desc: 'a theme based on the popular Dracula color palette originally by Zeno Rocha and friends. ', - version: '0.1', - author: { - name: 'mimi-shahzad', - link: 'https://github.com/mimi-shahzad', - avatar: 'https://secure.gravatar.com/avatar/86c98dec3a06245dbf2291deb44441f5', - } - + desc: + 'a theme based on the popular dracula color palette originally by zeno rocha and friends. ', + version: '0.1.0', + author: 'mimi-shahzad', }; diff --git a/mods/dracula-theme/styles.css b/mods/dracula-theme/styles.css index ecb3868..67e9a74 100644 --- a/mods/dracula-theme/styles.css +++ b/mods/dracula-theme/styles.css @@ -1,6 +1,5 @@ /* - * Dracula Theme Palette - * (c) 2020 dragonwocky (https://dragonwocky.me/) + * dracula-theme * (c) 2020 u/mimi-shahzad * (c) 2020 Dracula Theme * under the MIT license @@ -12,17 +11,17 @@ --theme_dark--overlay: #282a36; --theme_dark--dragarea: #282a36; - --theme_dark--font_sans: -apple-system, BlinkMacSystemFont, - 'Segoe UI', Helvetica, 'Apple Color Emoji', Arial, sans-serif, - 'Segoe UI Emoji', 'Segoe UI Symbol'; + --theme_dark--font_sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', + Helvetica, 'Apple Color Emoji', Arial, sans-serif, 'Segoe UI Emoji', + 'Segoe UI Symbol'; - --theme_dark--scrollbar: #f8f8f2; + --theme_dark--scrollbar: #282a36; --theme_dark--scrollbar_hover: #6272a4; - --theme_dark--card: #454158; - --theme_dark--gallery: #6272a4; + --theme_dark--card: #6272a4; + --theme_dark--gallery: #282a36; --theme_dark--table-border: #6272a4; - --theme_dark--interactive_hover: #bd93f9; + --theme_dark--interactive_hover: #282a36; --theme_dark--button_close: #ff5555; --theme_dark--selected: #454158; @@ -38,7 +37,7 @@ --theme_dark--danger_border: #ffb86c; --theme_dark--text: #f8f8f2; - --theme_dark--text_ui: #bd93f9; + --theme_dark--text_ui: #f8f8f2; --theme_dark--text_ui_info: #f8f8f2; --theme_dark--text_gray: #454158; @@ -52,7 +51,7 @@ --theme_dark--text_red: #ff5555; --theme_dark--select-text: #000000; - --theme_dark--select_gray: #f8f8f2; + --theme_dark--select_gray: #454158; --theme_dark--select_brown: #6272a4; --theme_dark--select_orange: #ffb86c; --theme_dark--select_yellow: #f1fa8c; @@ -73,7 +72,7 @@ --theme_dark--bg_pink: var(--theme_dark--select_pink); --theme_dark--bg_red: var(--theme_dark--select_red); - --theme_dark--line-text: #f8f8f2; + --theme_dark--line-text: #000000; --theme_dark--line_gray: #454158; --theme_dark--line_brown: #6272a4; --theme_dark--line_orange: #ffb86c; @@ -84,7 +83,7 @@ --theme_dark--line_pink: #ff79c6; --theme_dark--line_red: #ff5555; - --theme_dark--callout-text: var(--theme_dark--line-green); + --theme_dark--callout-text: var(--theme_dark--line-text); --theme_dark--callout_gray: var(--theme_dark--line_gray); --theme_dark--callout_brown: var(--theme_dark--line_brown); --theme_dark--callout_orange: var(--theme_dark--line_orange); @@ -96,7 +95,7 @@ --theme_dark--callout_red: var(--theme_dark--line_red); --theme_dark--code_inline-text: #50fa7b; - --theme_dark--code_inline-background:#44475a; + --theme_dark--code_inline-background: #44475a; --theme_dark--code-text: var(--theme_dark--text); --theme_dark--code-background: #44475a; --theme_dark--code_function: var(--theme_dark--text_blue); @@ -153,8 +152,7 @@ [style*='height: 4px;'] > .notion-selectable.notion-collection_view_page-block > *, -.notion-dark-theme - .notion-calendar-view-day[style*='background: #282a36;'], +.notion-dark-theme .notion-calendar-view-day[style*='background: #282a36;'], .DayPicker-Day--today, .notion-dark-theme .DayPicker:not(.DayPicker--interactionDisabled) From 9b49e6034baeb9c057262858251d82af1de56e99 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Mon, 12 Oct 2020 21:44:12 +1100 Subject: [PATCH 5/6] split tabs into separate mod, add opt for default page, load default settings when store()-ing another mod id --- CHANGELOG.md | 2 + mods/core/buttons.js | 2 +- mods/core/client.js | 32 +++++++++----- mods/core/menu.js | 6 ++- mods/core/mod.js | 12 +++--- mods/core/render.js | 99 ++++++++++++++++++++++++++++++++++---------- mods/tabs/mod.js | 19 +++++++++ pkg/loader.js | 21 +++++----- 8 files changed, 142 insertions(+), 51 deletions(-) create mode 100644 mods/tabs/mod.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 81a3c9b..2b1aa58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ a flexibility update. - 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 for a default page id (all new windows will load it instead of the + normal "most recent" page). - improved: a core mod option to make transitions snappy/0s. - improved: menu will now respect integrated titlebar setting. - improved: use keyup listeners instead of a globalShortcut for the enhancements menu toggle. diff --git a/mods/core/buttons.js b/mods/core/buttons.js index e50de06..bae94cd 100644 --- a/mods/core/buttons.js +++ b/mods/core/buttons.js @@ -15,7 +15,7 @@ module.exports = (store) => { buttons = { element: helpers.createElement('
'), insert: [ - ...((store('mods', {})['72886371-dada-49a7-9afc-9f275ecf29d3'] || {}) + ...((store('mods')['72886371-dada-49a7-9afc-9f275ecf29d3'] || {}) .enabled ? ['alwaysontop'] : []), diff --git a/mods/core/client.js b/mods/core/client.js index 4d683ca..3315093 100644 --- a/mods/core/client.js +++ b/mods/core/client.js @@ -19,12 +19,16 @@ module.exports = (store, __exports) => { // additional hotkeys document.defaultView.addEventListener('keyup', (event) => { if (event.code === '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]) triggered = false; - if (triggered) electron.ipcRenderer.send('enhancer:open-menu'); + if ( + !(store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {}).enabled + ) { + // 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'); + } }); const attempt_interval = setInterval(enhance, 500); @@ -43,7 +47,11 @@ module.exports = (store, __exports) => { document.body.classList.add('snappy-transitions'); // frameless - if (store().frameless && !store().tiling_mode && !store().tabs) { + if ( + store().frameless && + !store().tiling_mode && + !(store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {}).enabled + ) { document.body.classList.add('frameless'); // draggable area document @@ -56,7 +64,9 @@ module.exports = (store, __exports) => { } // window buttons - if (!store().tabs) { + if ( + !(store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {}).enabled + ) { const buttons = require('./buttons.js')(store); document .querySelector('.notion-topbar > div[style*="display: flex"]') @@ -153,7 +163,9 @@ module.exports = (store, __exports) => { '--theme--code_inline-background', ].map((rule) => [rule, getStyle(rule)]) ); - if (store().tabs) { + if ( + (store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {}).enabled + ) { electron.ipcRenderer.sendToHost( 'enhancer:set-tab-theme', [ @@ -179,7 +191,7 @@ module.exports = (store, __exports) => { ); electron.ipcRenderer.on('enhancer:get-menu-theme', setThemeVars); - if (store().tabs) { + if ((store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {}).enabled) { let tab_title = ''; __electronApi.setWindowTitle = (title) => { if (tab_title !== title) { diff --git a/mods/core/menu.js b/mods/core/menu.js index bb5913f..60a0d20 100644 --- a/mods/core/menu.js +++ b/mods/core/menu.js @@ -426,11 +426,13 @@ window['__start'] = async () => { }; mod.elem = helpers.createElement(`

${mod.name}` : `class="toggle"> { - if (store().tabs) { + if ((store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {}).enabled) { class Index extends React.PureComponent { constructor() { super(...arguments); @@ -156,22 +157,44 @@ module.exports = (store, __exports) => { const list = new Map(this.state.tabs); while (this.state.tabs.get(id)) id++; list.delete(id); - if (this.views.html[id]) { - this.views.html[id].style.opacity = '0'; - let unhide; - unhide = () => { - this.views.html[id].style.opacity = ''; - this.views.html[id].removeEventListener('did-stop-loading', unhide); - }; - this.views.html[id].addEventListener('did-stop-loading', unhide); - this.views.html[id].loadURL(this.views.current.$el().src); - } - this.openTab(id, list); + console.log( + store().default_page + ? `notion://www.notion.so/${store().default_page}` + : this.views.current.$el().src + ); + this.openTab(id, list, true); } - openTab(id, state = new Map(this.state.tabs)) { + openTab(id, state = new Map(this.state.tabs), load) { if (!id && id !== 0) return; this.views.current.id = id; - this.setState({ tabs: state.set(id, true) }, this.focusTab.bind(this)); + this.setState({ tabs: state.set(id, true) }, async () => { + this.focusTab(); + if (load) { + await new Promise((res, rej) => { + let attempt; + attempt = setInterval(() => { + if (!document.body.contains(this.views.html[id])) return; + clearInterval(attempt); + res(); + }, 50); + }); + this.views.html[id].style.opacity = '0'; + let unhide; + unhide = () => { + this.views.html[id].style.opacity = ''; + this.views.html[id].removeEventListener( + 'did-stop-loading', + unhide + ); + }; + this.views.html[id].addEventListener('did-stop-loading', unhide); + this.views.html[id].loadURL( + store().default_page + ? `notion://www.notion.so/${store().default_page}` + : this.views.current.$el().src + ); + } + }); } closeTab(id) { if ((!id && id !== 0) || !this.state.tabs.get(id)) return; @@ -733,16 +756,28 @@ module.exports = (store, __exports) => { window['__start'] = () => { document.head.innerHTML += ``; + // 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]) triggered = false; + if (triggered) electron.ipcRenderer.send('enhancer:open-menu'); + }); + const parsed = url.parse(window.location.href, true), - notionUrl = - parsed.query.path || - schemeHelpers.getSchemeUrl({ - httpUrl: config.default.baseURL, - protocol: config.default.protocol, - }); + notionUrl = store().default_page + ? `notion://www.notion.so/${store().default_page}` + : parsed.query.path || + schemeHelpers.getSchemeUrl({ + httpUrl: config.default.baseURL, + protocol: config.default.protocol, + }); delete parsed.search; delete parsed.query; - const plainUrl = url.format(parsed); + const plainUrl = store().default_page + ? `notion://www.notion.so/${store().default_page}` + : url.format(parsed); window.history.replaceState(undefined, undefined, plainUrl); document.title = localizationHelper @@ -769,6 +804,26 @@ module.exports = (store, __exports) => { const __start = window['__start']; window['__start'] = () => { __start(); + + if (store().default_page) { + new Promise((res, rej) => { + let attempt; + attempt = setInterval(() => { + if ( + !document.getElementById('notion') || + !document.getElementById('notion').loadURL + ) + return; + clearInterval(attempt); + res(); + }, 50); + }).then(() => { + document + .getElementById('notion') + .loadURL(`notion://www.notion.so/${store().default_page}`); + }); + } + const dragarea = document.querySelector( '#root [style*="-webkit-app-region: drag"]' ), diff --git a/mods/tabs/mod.js b/mods/tabs/mod.js new file mode 100644 index 0000000..1585c43 --- /dev/null +++ b/mods/tabs/mod.js @@ -0,0 +1,19 @@ +/* + * tabs + * (c) 2020 dragonwocky (https://dragonwocky.me/) + * under the MIT license + */ + +'use strict'; + +// this is just a pseudo mod to "separate" the options +// from the core module - the core still handles actually +// making it work. +module.exports = { + id: 'e1692c29-475e-437b-b7ff-3eee872e1a42', + tags: ['core', 'extension'], + name: 'tabs', + desc: 'have multiple notion pages open in a single window.', + version: '0.1.0', + author: 'dragonwocky', +}; diff --git a/pkg/loader.js b/pkg/loader.js index e5c3bcd..93a92ef 100644 --- a/pkg/loader.js +++ b/pkg/loader.js @@ -60,7 +60,7 @@ module.exports = function (__file, __exports) { ...modules.loaded.filter((m) => !m.tags.includes('core')).reverse(), ]) { if ( - (mod.tags || []).includes('core') || + mod.id === '0f0bf8b6-eae6-4273-b307-8fc43f2ee082' || store('mods', { [mod.id]: { enabled: false } })[mod.id].enabled ) { if ( @@ -84,15 +84,16 @@ module.exports = function (__file, __exports) { }); } if (mod.hacks && mod.hacks[__file]) { - mod.hacks[__file]( - (...args) => - !args.length - ? store(mod.id, mod.defaults) - : args.length === 1 && typeof args[0] === 'object' - ? store(mod.id, { ...mod.defaults, ...args[0] }) - : store(args[0], { ...mod.defaults, ...args[1] }), - __exports - ); + mod.hacks[__file]((...args) => { + if (!args.length) return store(mod.id, mod.defaults); + if (args.length === 1 && typeof args[0] === 'object') + return store(mod.id, { ...mod.defaults, ...args[0] }); + const other_mod = modules.loaded.find((m) => m.id === args[0]); + return store(args[0], { + ...(other_mod ? other_mod.defaults : {}), + ...args[1], + }); + }, __exports); } } } From 01bc88a783f1c906dfde80d182ddaf4ec768566b Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Mon, 12 Oct 2020 22:06:03 +1100 Subject: [PATCH 6/6] accept url or id for default page, don't override direct notion:// opens --- CHANGELOG.md | 2 +- mods/core/mod.js | 2 +- mods/core/render.js | 43 +++++++++++++++++++++++-------------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b1aa58..6cc9bf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ a flexibility update. - 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 for a default page id (all new windows will load it instead of the +- 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. - improved: menu will now respect integrated titlebar setting. diff --git a/mods/core/mod.js b/mods/core/mod.js index 6311973..701e2a8 100644 --- a/mods/core/mod.js +++ b/mods/core/mod.js @@ -76,7 +76,7 @@ module.exports = { }, { key: 'default_page', - label: 'open to default page id:', + label: 'open to default page id/url:', type: 'input', value: '', }, diff --git a/mods/core/render.js b/mods/core/render.js index 81363be..4e40181 100644 --- a/mods/core/render.js +++ b/mods/core/render.js @@ -26,7 +26,11 @@ const insertCSP = ` csp.httpEquiv = 'Content-Security-Policy'; csp.content = "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: enhancement: https: http:; 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: http:; frame-src https: http:; media-src https: http:"; document.head.appendChild(csp); -`; +`, + idToNotionURL = (id) => + `notion://www.notion.so/${ + url.parse(id).pathname.split('/').reverse()[0] || '' + }/${url.parse(id).search || ''}`; module.exports = (store, __exports) => { if ((store('mods')['e1692c29-475e-437b-b7ff-3eee872e1a42'] || {}).enabled) { @@ -157,11 +161,6 @@ module.exports = (store, __exports) => { const list = new Map(this.state.tabs); while (this.state.tabs.get(id)) id++; list.delete(id); - console.log( - store().default_page - ? `notion://www.notion.so/${store().default_page}` - : this.views.current.$el().src - ); this.openTab(id, list, true); } openTab(id, state = new Map(this.state.tabs), load) { @@ -190,7 +189,7 @@ module.exports = (store, __exports) => { this.views.html[id].addEventListener('did-stop-loading', unhide); this.views.html[id].loadURL( store().default_page - ? `notion://www.notion.so/${store().default_page}` + ? idToNotionURL(store().default_page) : this.views.current.$el().src ); } @@ -766,18 +765,17 @@ module.exports = (store, __exports) => { }); const parsed = url.parse(window.location.href, true), - notionUrl = store().default_page - ? `notion://www.notion.so/${store().default_page}` - : parsed.query.path || - schemeHelpers.getSchemeUrl({ - httpUrl: config.default.baseURL, - protocol: config.default.protocol, - }); + notionUrl = + parsed.query.path || + (store().default_page + ? idToNotionURL(store().default_page) + : schemeHelpers.getSchemeUrl({ + httpUrl: config.default.baseURL, + protocol: config.default.protocol, + })); delete parsed.search; delete parsed.query; - const plainUrl = store().default_page - ? `notion://www.notion.so/${store().default_page}` - : url.format(parsed); + const plainUrl = url.format(parsed); window.history.replaceState(undefined, undefined, plainUrl); document.title = localizationHelper @@ -818,9 +816,14 @@ module.exports = (store, __exports) => { res(); }, 50); }).then(() => { - document - .getElementById('notion') - .loadURL(`notion://www.notion.so/${store().default_page}`); + if ( + document.getElementById('notion').getAttribute('src') === + 'notion://www.notion.so' + ) { + document + .getElementById('notion') + .loadURL(idToNotionURL(store().default_page)); + } }); }