diff --git a/mods/core/dark.css b/mods/core/css/dark.css similarity index 100% rename from mods/core/dark.css rename to mods/core/css/dark.css diff --git a/mods/core/light.css b/mods/core/css/light.css similarity index 100% rename from mods/core/light.css rename to mods/core/css/light.css diff --git a/mods/core/scrollbars.css b/mods/core/css/scrollbars.css similarity index 100% rename from mods/core/scrollbars.css rename to mods/core/css/scrollbars.css diff --git a/mods/core/shared.css b/mods/core/css/shared.css similarity index 100% rename from mods/core/shared.css rename to mods/core/css/shared.css diff --git a/mods/core/titlebar.css b/mods/core/css/titlebar.css similarity index 100% rename from mods/core/titlebar.css rename to mods/core/css/titlebar.css diff --git a/mods/core/variables.css b/mods/core/css/variables.css similarity index 100% rename from mods/core/variables.css rename to mods/core/css/variables.css diff --git a/mods/core/menu.html b/mods/core/menu.html new file mode 100644 index 0000000..fcdd055 --- /dev/null +++ b/mods/core/menu.html @@ -0,0 +1,16 @@ + + + + + + Notion Enhancements Menu + + + + yayayay it works! + + diff --git a/mods/core/render.js b/mods/core/render.js index 13656c1..0add42f 100644 --- a/mods/core/render.js +++ b/mods/core/render.js @@ -16,6 +16,8 @@ module.exports = (defaults) => ), default_styles = dragarea.getAttribute('style'); + // document.body.innerText = document.body.innerHTML; + document .getElementById('notion') .addEventListener('ipc-message', (event) => { diff --git a/mods/core/styles.css b/mods/core/styles.css index b2a7b88..e4419e7 100644 --- a/mods/core/styles.css +++ b/mods/core/styles.css @@ -4,9 +4,9 @@ * (https://dragonwocky.me/) under the MIT license */ -@import './variables.css'; -@import './dark.css'; -@import './light.css'; -@import './shared.css'; -@import './scrollbars.css'; -@import './titlebar.css'; +@import './css/variables.css'; +@import './css/dark.css'; +@import './css/light.css'; +@import './css/shared.css'; +@import './css/scrollbars.css'; +@import './css/titlebar.css'; diff --git a/mods/core/tray.js b/mods/core/tray.js index c763ae3..b3d36a0 100644 --- a/mods/core/tray.js +++ b/mods/core/tray.js @@ -5,7 +5,7 @@ * (https://dragonwocky.me/) under the MIT license */ -let tray; +let tray, enhancer_menu; module.exports = (defaults) => function (store, __exports) { @@ -13,7 +13,9 @@ module.exports = (defaults) => path = require('path'), is_mac = process.platform === 'darwin', is_win = process.platform === 'win32', - settings = store(defaults); + settings = store(defaults), + helpers = require('../../pkg/helpers.js'), + __notion = helpers.getNotion(); electron.app.on('ready', () => { tray = new electron.Tray( @@ -27,6 +29,41 @@ module.exports = (defaults) => }) ); + function calculateWindowPos(width, height) { + const screen = electron.screen.getDisplayNearestPoint({ + x: tray.getBounds().x, + y: tray.getBounds().y, + }); + // left + if (screen.workArea.x > 0) + // The workspace starts more on the right + return { + x: screen.workArea.x, + y: screen.workArea.height - height, + }; + // top + if (screen.workArea.y > 0) + return { + x: Math.round( + tray.getBounds().x + tray.getBounds().width / 2 - width / 2 + ), + y: screen.workArea.y, + }; + // right + if (screen.workArea.width < screen.bounds.width) + return { + x: screen.workArea.width - width, + y: screen.bounds.height - height, + }; + // bottom + return { + x: Math.round( + tray.getBounds().x + tray.getBounds().width / 2 - width / 2 + ), + y: screen.workArea.height - height, + }; + } + const contextMenu = electron.Menu.buildFromTemplate([ { type: 'normal', @@ -61,7 +98,34 @@ module.exports = (defaults) => { type: 'normal', label: 'Enhancements', - // will open menu + click: () => { + const window_state = require(`${__notion.replace( + /\\/g, + '/' + )}/app/node_modules/electron-window-state/index.js`)({ + file: 'menu-windowstate.json', + defaultWidth: 275, + defaultHeight: 600, + }); + electron.shell.openExternal(JSON.stringify(window_state)); + enhancer_menu = new electron.BrowserWindow({ + show: true, + frame: false, + x: + window_state.x || + calculateWindowPos(window_state.width, window_state.height).x, + y: + window_state.y || + calculateWindowPos(window_state.width, window_state.height).y, + width: window_state.width, + height: window_state.height, + webPreferences: { + nodeIntegration: true, + session: electron.session.fromPartition('persist:notion'), + }, + }); + enhancer_menu.loadURL('enhancement://core/menu.html'); + }, }, { type: 'separator', @@ -89,25 +153,6 @@ module.exports = (defaults) => tray.on('click', () => { const windows = electron.BrowserWindow.getAllWindows(); - - for (let browser of windows) { - browser.webContents.sendInputEvent({ - type: 'keyDown', - modifiers: ['control', 'shift'], - key: 'L', - }); - browser.webContents.sendInputEvent({ - type: 'char', - modifiers: ['control', 'shift'], - key: 'L', - }); - browser.webContents.sendInputEvent({ - type: 'keyUp', - modifiers: ['control', 'shift'], - key: 'L', - }); - } - if (windows.some((win) => win.isVisible())) hideWindows(); else showWindows(); });