load menu.css and variables.css into enhancer menu

This commit is contained in:
dragonwocky 2020-11-11 22:14:05 +11:00
parent 00e5b3f40e
commit 61b6b6deca
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D
9 changed files with 52 additions and 117 deletions

View File

@ -181,7 +181,7 @@ notion's html structure needs some complex selectors to properly modify it,
and it means theme authors don't have to worry about separately updating their theme every time something changes. and it means theme authors don't have to worry about separately updating their theme every time something changes.
the full/up-to-date list of variables and their default values can be found in the the full/up-to-date list of variables and their default values can be found in the
[`variables.css` source file](mods/core/css/variables.css). each variable is named something along the lines of [core `variables.css` file](mods/core/variables.css). each variable is named something along the lines of
`--theme_mode--target_name-property`. still not sure what a variable does? try changing it and seeing what happens. `--theme_mode--target_name-property`. still not sure what a variable does? try changing it and seeing what happens.
these are all made possible by the core module. if you believe this set of variables is buggy or lacking in any way, these are all made possible by the core module. if you believe this set of variables is buggy or lacking in any way,

View File

@ -5,6 +5,5 @@
*/ */
@import './css/theme.css'; @import './css/theme.css';
@import './css/variables.css';
@import './css/scrollbars.css'; @import './css/scrollbars.css';
@import './css/titlebar.css'; @import './css/titlebar.css';

View File

@ -140,81 +140,18 @@ module.exports = (store, __exports) => {
} }
}); });
function setThemeVars() { function setAppTheme() {
electron.ipcRenderer.send( electron.ipcRenderer.send(
'enhancer:set-menu-theme', 'enhancer:set-app-theme',
[ document.querySelector('.notion-dark-theme') ? 'dark' : 'light'
'--theme--main',
'--theme--sidebar',
'--theme--overlay',
'--theme--dragarea',
'--theme--box-shadow_strong',
'--theme--font_sans',
'--theme--font_code',
'--theme--font_label-size',
'--theme--scrollbar',
'--theme--scrollbar-border',
'--theme--scrollbar_hover',
'--theme--card',
'--theme--table-border',
'--theme--interactive_hover',
'--theme--interactive_hover-border',
'--theme--button_close',
'--theme--button_close-fill',
'--theme--selected',
'--theme--primary',
'--theme--primary_click',
'--theme--option-color',
'--theme--option-background',
'--theme--option_active-background',
'--theme--option_active-color',
'--theme--option_hover-color',
'--theme--option_hover-background',
'--theme--text',
'--theme--text_ui',
'--theme--text_ui_info',
'--theme--select_yellow',
'--theme--select_green',
'--theme--select_blue',
'--theme--select_red',
'--theme--line_text',
'--theme--line_yellow',
'--theme--line_yellow-text',
'--theme--line_green',
'--theme--line_green-text',
'--theme--line_blue',
'--theme--line_blue-text',
'--theme--line_red',
'--theme--line_red-text',
'--theme--code_inline-text',
'--theme--code_inline-background',
].map((rule) => [rule, getStyle(rule)])
); );
if (tabsEnabled) {
electron.ipcRenderer.sendToHost(
'enhancer:set-tab-theme',
[
'--theme--main',
'--theme--dragarea',
'--theme--font_sans',
'--theme--table-border',
'--theme--interactive_hover',
'--theme--interactive_hover-border',
'--theme--button_close',
'--theme--button_close-fill',
'--theme--option_active-background',
'--theme--selected',
'--theme--text',
].map((rule) => [rule, getStyle(rule)])
);
}
} }
setThemeVars(); setAppTheme();
new MutationObserver(setThemeVars).observe( new MutationObserver(setAppTheme).observe(
document.querySelector('.notion-app-inner'), document.querySelector('.notion-app-inner'),
{ attributes: true } { attributes: true }
); );
electron.ipcRenderer.on('enhancer:get-menu-theme', setThemeVars); electron.ipcRenderer.on('enhancer:get-app-theme', setAppTheme);
if (tabsEnabled) { if (tabsEnabled) {
let tab_title = { img: '', emoji: '', text: '' }; let tab_title = { img: '', emoji: '', text: '' };

View File

@ -7,7 +7,7 @@
'use strict'; 'use strict';
const store = require('../../pkg/store.js'), const store = require('../../pkg/store.js'),
helpers = require('../../pkg/helpers.js'), { createElement, getEnhancements } = require('../../pkg/helpers.js'),
fs = require('fs-extra'), fs = require('fs-extra'),
path = require('path'), path = require('path'),
electron = require('electron'), electron = require('electron'),
@ -17,13 +17,14 @@ window['__start'] = async () => {
document.body.setAttribute('data-platform', process.platform); document.body.setAttribute('data-platform', process.platform);
// mod loader // mod loader
const modules = helpers.getEnhancements(); const modules = getEnhancements();
if (modules.loaded.length) if (modules.loaded.length) {
console.info( console.info(
`<notion-enhancer> enhancements loaded: ${modules.loaded `<notion-enhancer> enhancements loaded: ${modules.loaded
.map((mod) => mod.name) .map((mod) => mod.name)
.join(', ')}.` .join(', ')}.`
); );
}
if (modules.invalid.length) { if (modules.invalid.length) {
createAlert( createAlert(
'error', 'error',
@ -43,6 +44,28 @@ window['__start'] = async () => {
: store(args[0], { ...mod.defaults, ...args[1] }); : store(args[0], { ...mod.defaults, ...args[1] });
}; };
for (let mod of modules.loaded) {
if (
mod.alwaysActive ||
store('mods', { [mod.id]: { enabled: false } })[mod.id].enabled
) {
const fileExists = (file) => fs.pathExistsSync(path.resolve(file));
for (let sheet of ['menu', 'variables']) {
if (fileExists(`${__dirname}/../${mod.dir}/${sheet}.css`)) {
document.head.appendChild(
createElement(
`<link rel="stylesheet" href="enhancement://${mod.dir}/${sheet}.css">`
)
);
}
}
}
}
electron.ipcRenderer.send('enhancer:get-app-theme');
electron.ipcRenderer.on('enhancer:set-app-theme', (event, theme) => {
document.body.className = `notion-${theme}-theme`;
});
const buttons = require('./buttons.js')(() => ({ const buttons = require('./buttons.js')(() => ({
'72886371-dada-49a7-9afc-9f275ecf29d3': { '72886371-dada-49a7-9afc-9f275ecf29d3': {
enabled: (store('mods')['72886371-dada-49a7-9afc-9f275ecf29d3'] || {}) enabled: (store('mods')['72886371-dada-49a7-9afc-9f275ecf29d3'] || {})
@ -53,16 +76,10 @@ window['__start'] = async () => {
})); }));
document.querySelector('#titlebar').appendChild(buttons.element); document.querySelector('#titlebar').appendChild(buttons.element);
electron.ipcRenderer.send('enhancer:get-menu-theme');
electron.ipcRenderer.on('enhancer:set-menu-theme', (event, theme) => {
for (const style of theme)
document.body.style.setProperty(style[0], style[1]);
});
function createAlert(type, message) { function createAlert(type, message) {
if (!type) if (!type)
throw Error('<notion-enhancer> @ createAlert: no alert type specified'); throw Error('<notion-enhancer> @ createAlert: no alert type specified');
const el = helpers.createElement(` const el = createElement(`
<section class="${type}" role="alert"> <section class="${type}" role="alert">
<p>${message}</p> <p>${message}</p>
</section> </section>
@ -182,9 +199,7 @@ window['__start'] = async () => {
.update(); .update();
document document
.querySelector('#colorpicker') .querySelector('#colorpicker')
.appendChild( .appendChild(createElement('<button class="close-modal"></button>'));
helpers.createElement('<button class="close-modal"></button>')
);
document.querySelectorAll('#popup .close-modal').forEach((el) => document.querySelectorAll('#popup .close-modal').forEach((el) =>
el.addEventListener('click', (event) => { el.addEventListener('click', (event) => {
$popup.classList.remove('visible'); $popup.classList.remove('visible');
@ -325,7 +340,7 @@ window['__start'] = async () => {
throw Error('<notion-enhancer> @ createTag: no tagname specified'); throw Error('<notion-enhancer> @ createTag: no tagname specified');
if (!onclick) if (!onclick)
throw Error('<notion-enhancer> @ createTag: no action specified'); throw Error('<notion-enhancer> @ createTag: no action specified');
const el = helpers.createElement( const el = createElement(
`<span class="selected" ${ `<span class="selected" ${
color ? `style="--tag_color: ${color}" ` : '' color ? `style="--tag_color: ${color}" ` : ''
}tabindex="0">${tagname}</span>` }tabindex="0">${tagname}</span>`
@ -470,7 +485,7 @@ window['__start'] = async () => {
</label> </label>
`; `;
} }
$opt = helpers.createElement(`<p class="${opt.type}">${$opt}</p>`); $opt = createElement(`<p class="${opt.type}">${$opt}</p>`);
if (opt.type === 'color') { if (opt.type === 'color') {
$opt $opt
.querySelector(`#${opt.type}_${id}--${opt.key}`) .querySelector(`#${opt.type}_${id}--${opt.key}`)
@ -498,9 +513,7 @@ window['__start'] = async () => {
for (let font of mod.fonts || []) { for (let font of mod.fonts || []) {
document document
.querySelector('head') .querySelector('head')
.appendChild( .appendChild(createElement(`<link rel="stylesheet" href="${font}">`));
helpers.createElement(`<link rel="stylesheet" href="${font}">`)
);
} }
const enabled = const enabled =
@ -516,7 +529,7 @@ window['__start'] = async () => {
link: `https://github.com/${mod.author}`, link: `https://github.com/${mod.author}`,
avatar: `https://github.com/${mod.author}.png`, avatar: `https://github.com/${mod.author}.png`,
}; };
mod.elem = helpers.createElement(` mod.elem = createElement(`
<section class="${enabled ? 'enabled' : 'disabled'}" id="${mod.id}"> <section class="${enabled ? 'enabled' : 'disabled'}" id="${mod.id}">
<div class="meta"> <div class="meta">
<h3 ${ <h3 ${

View File

@ -4,8 +4,8 @@
* under the MIT license * under the MIT license
*/ */
@import './buttons.css'; @import './css/buttons.css';
@import './scrollbars.css'; @import './css/scrollbars.css';
@keyframes spin { @keyframes spin {
from { from {
@ -44,22 +44,6 @@ body {
color: var(--theme--text); color: var(--theme--text);
} }
body:not([style]) > * {
display: none !important;
}
body:not([style])::after {
content: '';
position: absolute;
left: calc(50% - 13px);
top: calc(50% + 10px);
width: 18px;
height: 18px;
border: 4px solid rgb(34, 34, 34, 0.5);
border-top-color: transparent;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
main { main {
padding: 1em 1em 2.9em 1em; padding: 1em 1em 2.9em 1em;
height: 100%; height: 100%;

View File

@ -6,9 +6,8 @@
<title>notion-enhancer menu</title> <title>notion-enhancer menu</title>
<script src="./colorjoe/min.js"></script> <script src="./colorjoe/min.js"></script>
<link rel="stylesheet" href="./colorjoe/picker.css" /> <link rel="stylesheet" href="./colorjoe/picker.css" />
<link rel="stylesheet" href="./css/menu.css" />
</head> </head>
<body> <body class="notion-dark-theme">
<header id="titlebar"></header> <header id="titlebar"></header>
<main> <main>
<div id="alerts"></div> <div id="alerts"></div>

View File

@ -4,7 +4,7 @@
* under the MIT license * under the MIT license
*/ */
@import './buttons.css'; @import './css/buttons.css';
* { * {
box-sizing: border-box; box-sizing: border-box;

View File

@ -57,15 +57,18 @@ module.exports = (store, __exports) => {
// menu // menu
electron.ipcMain.on('enhancer:open-menu', openEnhancerMenu); electron.ipcMain.on('enhancer:open-menu', openEnhancerMenu);
electron.ipcMain.on('enhancer:set-menu-theme', (event, arg) => { electron.ipcMain.on('enhancer:set-app-theme', (event, arg) => {
if (!enhancer_menu) return;
enhancer_menu.webContents.send('enhancer:set-menu-theme', arg);
});
electron.ipcMain.on('enhancer:get-menu-theme', (event, arg) => {
electron.webContents electron.webContents
.getAllWebContents() .getAllWebContents()
.forEach((webContents) => .forEach((webContents) =>
webContents.send('enhancer:get-menu-theme', arg) webContents.send('enhancer:set-app-theme', arg)
);
});
electron.ipcMain.on('enhancer:get-app-theme', (event, arg) => {
electron.webContents
.getAllWebContents()
.forEach((webContents) =>
webContents.send('enhancer:get-app-theme', arg)
); );
}); });
electron.ipcMain.on('enhancer:close-tab', (event, target, tab) => { electron.ipcMain.on('enhancer:close-tab', (event, target, tab) => {