diff --git a/repo/alwaysontop/mod.js b/repo/alwaysontop/mod.js new file mode 100644 index 0000000..6972b63 --- /dev/null +++ b/repo/alwaysontop/mod.js @@ -0,0 +1,20 @@ +/* + * always on top + * (c) 2020 dragonwocky (https://dragonwocky.me/) + * under the MIT license + */ + +'use strict'; + +// this is actually just a pseudo mod to "separate" the button +// from the core module, but the core still handles actually +// making it work. +module.exports = { + id: '72886371-dada-49a7-9afc-9f275ecf29d3', + tags: ['extension'], + name: 'always on top', + desc: + "add an arrow/button to show the notion window on top of other windows even if it's not focused.", + version: '0.1.1', + author: 'dragonwocky', +}; diff --git a/repo/core/buttons.js b/repo/core/buttons.js index e0cd54c..376f1b4 100644 --- a/repo/core/buttons.js +++ b/repo/core/buttons.js @@ -15,7 +15,10 @@ module.exports = (store) => { buttons = { element: helpers.createElement('
'), insert: [ - 'alwaysontop', + ...((store('mods')['72886371-dada-49a7-9afc-9f275ecf29d3'] || {}) + .enabled + ? ['alwaysontop'] + : []), ...(store().frameless && !store().tiling_mode && !is_mac ? ['minimize', 'maximize', 'close'] : []), diff --git a/repo/core/css/menu.css b/repo/core/css/menu.css index 8138f92..805bb72 100644 --- a/repo/core/css/menu.css +++ b/repo/core/css/menu.css @@ -105,19 +105,18 @@ s { #menu-titlebar { display: flex; - padding: 0.4em; -webkit-app-region: drag; } #menu-titlebar button { -webkit-app-region: no-drag; } -#menu-titlebar :first-child { - margin-left: auto; -} #menu-titlebar { background: var(--theme--dragarea); } -#menu-titlebar:empty { +#menu-titlebar > .window-buttons-area { + margin: 0.4em 0.4em 0.4em auto; +} +#menu-titlebar > .window-buttons-area:empty { display: none; } diff --git a/repo/core/menu.js b/repo/core/menu.js index 95aae9c..2577e9c 100644 --- a/repo/core/menu.js +++ b/repo/core/menu.js @@ -15,32 +15,44 @@ const store = require('../../pkg/store.js'), browser = electron.remote.getCurrentWindow(); window['__start'] = async () => { - if (!store(id).tiling_mode) { - const buttons = require('./buttons.js')(() => ({ frameless: true })); - document.querySelector('#menu-titlebar').appendChild(buttons.element); - } + 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: true, + })); + document.querySelector('#menu-titlebar').appendChild(buttons.element); document.defaultView.addEventListener('keyup', (event) => { if (event.code === 'F5') location.reload(); - if (!(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey) { + 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 ( - document.activeElement.parentElement.id === 'tags' && - event.key === 'Enter' + ['Escape', 'Enter'].includes(event.key) && + document.activeElement.type !== 'checkbox' && + (document.activeElement.parentElement.id !== 'search' || + event.key === 'Escape') ) - 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 (event.key === '/') - document.querySelector('#search > input').focus(); - } + document.activeElement.blur(); + } else if ( + (meta && event.key === '/') || + ((event.ctrlKey || event.metaKey) && + event.key === 'f' && + !event.altKey && + !event.shiftKey) + ) + document.querySelector('#search > input').focus(); }); electron.ipcRenderer.send('enhancer:get-theme-vars');