notion-enhancer/repo/integrated-titlebar/rendererIndex.cjs

46 lines
1.3 KiB
JavaScript

/**
* notion-enhancer: integrated titlebar
* (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* (https://notion-enhancer.github.io/) under the MIT license
*/
'use strict';
module.exports = async function ({ registry }, db, __exports, __eval) {
const dragareaSelector = '[style*="-webkit-app-region: drag;"]';
await new Promise((res, rej) => {
let isReadyInt;
isReadyInt = setInterval(isReadyTest, 100);
function isReadyTest() {
if (document.querySelector(dragareaSelector)) {
clearInterval(isReadyInt);
res(true);
}
}
isReadyTest();
});
const tilingMode = await db.get(['tiling']),
dragareaHeight = await db.get(['dragarea_height']),
tabsEnabled = await registry.enabled('e1692c29-475e-437b-b7ff-3eee872e1a42');
if (tabsEnabled) {
} else {
const dragarea = document.querySelector(dragareaSelector);
dragarea.style.top = '2px';
dragarea.style.height = tilingMode ? '0' : `${dragareaHeight}px`;
document.getElementById('notion').addEventListener('ipc-message', (event) => {
switch (event.channel) {
case 'notion-enhancer:sidebar-width':
dragarea.style.left = event.args[0];
break;
case 'notion-enhancer:panel-width':
dragarea.style.right = event.args[0];
break;
}
});
}
};