error notifications + theme conflict resolution

This commit is contained in:
dragonwocky 2021-04-29 14:20:27 +10:00
parent 69b73f6140
commit ecfb3c1e50
6 changed files with 107 additions and 19 deletions

View File

@ -480,7 +480,7 @@ registry.get = async (enabled) => {
const mod = await fs.getJSON(`repo/${dir}/mod.json`);
mod._dir = dir;
mod.tags = mod.tags ?? [];
mod.css = mod.css ?? [];
mod.css = mod.css ?? {};
mod.js = mod.js ?? {};
mod.options = mod.options ?? [];

View File

@ -4,7 +4,7 @@
"version": "0.11.0",
"description": "the enhancer's [graphical](https://github.com) menu, related buttons and shortcuts.",
"preview": "https://raw.githubusercontent.com/notion-enhancer/notion-enhancer/dev/notion-enhancer%20v0.10.0%20banner.jpg",
"tags": ["core"],
"tags": ["theme", "light"],
"authors": [
{
"name": "dragonwocky",

View File

@ -7,7 +7,7 @@
'use strict';
const _id = 'a6621988-551d-495a-97d8-3c568bca2e9e';
import { env, storage, web, fs } from '../../helpers.js';
import { env, storage, web, fs, registry } from '../../helpers.js';
const sidebarSelector =
'#notion-app > div > div.notion-cursor-listener > div.notion-sidebar-container > div > div > div > div:nth-child(4)';
@ -20,6 +20,7 @@ web.whenReady([sidebarSelector]).then(async () => {
</div>
</div>`
),
errors = await registry.errors(),
notifications = {
list: await fs.getJSON('https://notion-enhancer.github.io/notifications.json'),
dismissed: await storage.get(_id, 'notifications', []),
@ -27,11 +28,13 @@ web.whenReady([sidebarSelector]).then(async () => {
notifications.waiting = notifications.list.filter(
({ id }) => !notifications.dismissed.includes(id)
);
if (notifications.waiting.length) {
if (notifications.waiting.length + errors.length) {
$enhancerSidebarElement.classList.add('enhancer--notifications');
$enhancerSidebarElement.children[0].append(
web.createElement(
web.html`<div><div><span>${notifications.waiting.length}</span></div></div>`
web.html`<div><div><span>${
notifications.waiting.length + errors.length
}</span></div></div>`
)
);
}

View File

@ -54,7 +54,7 @@ components.card = {
src="${web.escapeHtml(preview)}"
/>`)
: '',
async name({ name, id, version }) {
async name({ name, id, version, tags }) {
if (registry.CORE.includes(id))
return web.createElement(web.html`<div class="library--title"><h2>
<span>
@ -76,9 +76,28 @@ components.card = {
<span class="library--toggle"></span>
</h2>
</label>`);
$el.addEventListener('change', async (event) =>
storage.set('_enabled', id, !(await storage.get('_enabled', id, false)))
);
$el.addEventListener('change', async (event) => {
storage.set('_enabled', id, event.target.checked);
if (
event.target.checked &&
tags.includes('theme') &&
(await storage.get(_id, 'themes.autoresolve', true))
) {
const themes = (await registry.get()).filter(
(mod) =>
mod.tags.includes('theme') &&
mod.id !== id &&
((mod.tags.includes('dark') && tags.includes('dark')) ||
(mod.tags.includes('light') && tags.includes('light')))
);
for (const theme of themes) {
if (document.body.dataset.view === 'library') {
const $toggle = document.getElementById(`enable--${theme.id}`);
if ($toggle.checked) $toggle.click();
} else storage.set('_enabled', theme.id, false);
}
}
});
return $el;
},
tags: ({ tags = [] }) =>
@ -425,7 +444,8 @@ window.addEventListener('popstate', (event) => {
});
const notifications = {
_generate({ heading, message = '', type = 'information' }, onDismiss = () => {}) {
$list: document.querySelector('.notification--list'),
push({ heading, message = '', type = 'information' }, onDismiss = () => {}) {
let svg = '',
className = 'notification';
switch (type) {
@ -462,7 +482,7 @@ const notifications = {
setTimeout(() => {
$notif.style.opacity = 1;
}, 100);
return $notif;
return this.$list.append($notif);
},
async fetch() {
const notifications = {
@ -473,7 +493,6 @@ const notifications = {
notifications.waiting = notifications.list.filter(
({ id }) => !notifications.dismissed.includes(id)
);
const $list = document.querySelector('.notification--list');
for (let notification of notifications.waiting) {
if (
notification.heading &&
@ -482,16 +501,23 @@ const notifications = {
notification.appears_on.versions.includes(env.version)) &&
notification.appears_on.extension
) {
$list.append(
this._generate(notification, async () => {
const dismissed = await storage.get(_id, 'notifications', []);
storage.set(_id, 'notifications', [...new Set([...dismissed, notification.id])]);
})
);
this.push(notification, async () => {
const dismissed = await storage.get(_id, 'notifications', []);
storage.set('_notifications', 'external', [
...new Set([...dismissed, notification.id]),
]);
});
}
}
},
};
for (const error of await registry.errors()) {
notifications.push({
heading: `error: ${error.source}`,
message: error.message,
type: 'warning',
});
}
notifications.fetch();
async function theme() {

View File

@ -1 +1,6 @@
["menu@a6621988-551d-495a-97d8-3c568bca2e9e", "theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082"]
[
"menu@a6621988-551d-495a-97d8-3c568bca2e9e",
"theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082",
"custom-inserts@2f914210-faae-4803-8e3d-f2bf358a5864",
"tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2"
]

View File

@ -0,0 +1,54 @@
{
"name": "tweaks",
"id": "5174a483-c88d-4bf8-a95f-35cd330b76e2",
"version": "0.11.0",
"description": "the enhancer's [graphical](https://github.com) menu, related buttons and shortcuts.",
"preview": "https://raw.githubusercontent.com/notion-enhancer/notion-enhancer/dev/notion-enhancer%20v0.10.0%20banner.jpg",
"tags": ["theme", "light"],
"authors": [
{
"name": "dragonwocky",
"email": "thedragonring.bod@gmail.com",
"url": "https://dragonwocky.me/",
"icon": "https://dragonwocky.me/avatar.jpg"
}
],
"js": {},
"options": [
{
"type": "toggle",
"key": "toggle",
"label": "toggle",
"value": true,
"tooltip": "a toggle"
},
{
"type": "select",
"key": "select",
"label": "select",
"values": ["option a", "option b", "option c"],
"tooltip": "a select"
},
{
"type": "text",
"key": "text",
"label": "text",
"value": "default",
"tooltip": "a text input"
},
{
"type": "number",
"key": "number",
"label": "number",
"value": 0,
"tooltip": "a number input"
},
{
"type": "file",
"key": "file",
"label": "file picker (.css only)",
"extensions": [".css"],
"tooltip": "a file picker"
}
]
}