refactor loader

This commit is contained in:
dragonwocky 2020-10-27 10:07:11 +11:00
parent a21bcc9803
commit 64d9394a27
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D
2 changed files with 42 additions and 38 deletions

View File

@ -26,8 +26,7 @@ a flexibility update.
- improved: additional menu option descriptions on hover. - improved: additional menu option descriptions on hover.
- improved: listen to prefers-color-scheme to better change theme in night shift. - improved: listen to prefers-color-scheme to better change theme in night shift.
- bugfix: removed messenger emoji set as the provider no longer supports it. - bugfix: removed messenger emoji set as the provider no longer supports it.
- bugfix: remove shadow around light mode board headers - bugfix: remove shadow around light mode board headers.
\+ minor text colour fixes for night shift theming.
- bugfix: properly detect/respond to `EACCES`/`EBUSY` errors. - bugfix: properly detect/respond to `EACCES`/`EBUSY` errors.
- bugfix: night shift checks every interaction, - bugfix: night shift checks every interaction,
will respond to system changes without any manual changes. will respond to system changes without any manual changes.
@ -52,7 +51,8 @@ a flexibility update.
- theme: "material ocean" = an oceanic colour palette. - theme: "material ocean" = an oceanic colour palette.
- theme: "dracula" = a theme based on the popular dracula color palette - theme: "dracula" = a theme based on the popular dracula color palette
originally by zeno rocha and friends. originally by zeno rocha and friends.
- extension: "tabs" = have multiple notion pages open in a single window. - extension: "tabs" = have multiple notion pages open in a single window. tabs can be controlled
with keyboard shortcuts and dragged/reordered within/between windows.
- extension: "scroll to top" = add an arrow above the help button to scroll back to the top of a page. - extension: "scroll to top" = add an arrow above the help button to scroll back to the top of a page.
- extension: "tweaks" = common style/layout changes. includes: - extension: "tweaks" = common style/layout changes. includes:
- new: make transitions snappy/0s. - new: make transitions snappy/0s.

View File

@ -8,12 +8,12 @@
const fs = require('fs-extra'), const fs = require('fs-extra'),
path = require('path'), path = require('path'),
helpers = require('./helpers.js'), { __notion, getEnhancements, createElement } = require('./helpers.js'),
store = require('./store.js'); store = require('./store.js');
module.exports = function (__file, __exports) { module.exports = function (__file, __exports) {
__file = __file __file = __file
.slice(path.resolve(`${helpers.__notion}/app`).length + 1) .slice(path.resolve(`${__notion}/app`).length + 1)
.replace(/\\/g, '/'); .replace(/\\/g, '/');
if (__file === 'main/security.js') { if (__file === 'main/security.js') {
@ -54,47 +54,51 @@ module.exports = function (__file, __exports) {
]); ]);
} }
const modules = helpers.getEnhancements(); let modules = getEnhancements();
for (let mod of [ modules = [
...modules.loaded.filter((m) => m.tags.includes('core')), ...modules.loaded.filter((m) => m.tags.includes('core')),
...modules.loaded.filter((m) => !m.tags.includes('core')).reverse(), ...modules.loaded.filter((m) => !m.tags.includes('core')).reverse(),
]) { ];
if ( if (__file === 'renderer/preload.js') {
mod.alwaysActive || document.addEventListener('readystatechange', (event) => {
store('mods', { [mod.id]: { enabled: false } })[mod.id].enabled if (document.readyState !== 'complete') return false;
) { for (let mod of modules) {
if ( if (
__file === 'renderer/preload.js' && (mod.alwaysActive ||
fs.pathExistsSync( store('mods', { [mod.id]: { enabled: false } })[mod.id].enabled) &&
path.resolve(`${__dirname}/../mods/${mod.dir}/styles.css`) fs.pathExistsSync(
) path.resolve(`${__dirname}/../mods/${mod.dir}/styles.css`)
) { )
document.addEventListener('readystatechange', (event) => { ) {
if (document.readyState !== 'complete') return false;
for (let rules of [ for (let rules of [
`enhancement://${mod.dir}/styles.css`, `enhancement://${mod.dir}/styles.css`,
...(mod.fonts || []), ...(mod.fonts || []),
]) { ]) {
document document.head.appendChild(
.querySelector('head') createElement(`<link rel="stylesheet" href="${rules}">`)
.appendChild( );
helpers.createElement(`<link rel="stylesheet" href="${rules}">`)
);
} }
}
}
});
}
for (let mod of modules) {
if (
(mod.alwaysActive ||
store('mods', { [mod.id]: { enabled: false } })[mod.id].enabled) &&
mod.hacks &&
mod.hacks[__file]
) {
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.find((m) => m.id === args[0]);
return store(args[0], {
...(other_mod ? other_mod.defaults : {}),
...(args[1] || {}),
}); });
} }, __exports);
if (mod.hacks && mod.hacks[__file]) {
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);
}
} }
} }
}; };