mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-09 15:09:02 +00:00
error notifications + theme conflict resolution
This commit is contained in:
parent
69b73f6140
commit
ecfb3c1e50
@ -480,7 +480,7 @@ registry.get = async (enabled) => {
|
|||||||
const mod = await fs.getJSON(`repo/${dir}/mod.json`);
|
const mod = await fs.getJSON(`repo/${dir}/mod.json`);
|
||||||
mod._dir = dir;
|
mod._dir = dir;
|
||||||
mod.tags = mod.tags ?? [];
|
mod.tags = mod.tags ?? [];
|
||||||
mod.css = mod.css ?? [];
|
mod.css = mod.css ?? {};
|
||||||
mod.js = mod.js ?? {};
|
mod.js = mod.js ?? {};
|
||||||
mod.options = mod.options ?? [];
|
mod.options = mod.options ?? [];
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"version": "0.11.0",
|
"version": "0.11.0",
|
||||||
"description": "the enhancer's [graphical](https://github.com) menu, related buttons and shortcuts.",
|
"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",
|
"preview": "https://raw.githubusercontent.com/notion-enhancer/notion-enhancer/dev/notion-enhancer%20v0.10.0%20banner.jpg",
|
||||||
"tags": ["core"],
|
"tags": ["theme", "light"],
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "dragonwocky",
|
"name": "dragonwocky",
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const _id = 'a6621988-551d-495a-97d8-3c568bca2e9e';
|
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 =
|
const sidebarSelector =
|
||||||
'#notion-app > div > div.notion-cursor-listener > div.notion-sidebar-container > div > div > div > div:nth-child(4)';
|
'#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>
|
||||||
</div>`
|
</div>`
|
||||||
),
|
),
|
||||||
|
errors = await registry.errors(),
|
||||||
notifications = {
|
notifications = {
|
||||||
list: await fs.getJSON('https://notion-enhancer.github.io/notifications.json'),
|
list: await fs.getJSON('https://notion-enhancer.github.io/notifications.json'),
|
||||||
dismissed: await storage.get(_id, 'notifications', []),
|
dismissed: await storage.get(_id, 'notifications', []),
|
||||||
@ -27,11 +28,13 @@ web.whenReady([sidebarSelector]).then(async () => {
|
|||||||
notifications.waiting = notifications.list.filter(
|
notifications.waiting = notifications.list.filter(
|
||||||
({ id }) => !notifications.dismissed.includes(id)
|
({ id }) => !notifications.dismissed.includes(id)
|
||||||
);
|
);
|
||||||
if (notifications.waiting.length) {
|
if (notifications.waiting.length + errors.length) {
|
||||||
$enhancerSidebarElement.classList.add('enhancer--notifications');
|
$enhancerSidebarElement.classList.add('enhancer--notifications');
|
||||||
$enhancerSidebarElement.children[0].append(
|
$enhancerSidebarElement.children[0].append(
|
||||||
web.createElement(
|
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>`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ components.card = {
|
|||||||
src="${web.escapeHtml(preview)}"
|
src="${web.escapeHtml(preview)}"
|
||||||
/>`)
|
/>`)
|
||||||
: '',
|
: '',
|
||||||
async name({ name, id, version }) {
|
async name({ name, id, version, tags }) {
|
||||||
if (registry.CORE.includes(id))
|
if (registry.CORE.includes(id))
|
||||||
return web.createElement(web.html`<div class="library--title"><h2>
|
return web.createElement(web.html`<div class="library--title"><h2>
|
||||||
<span>
|
<span>
|
||||||
@ -76,9 +76,28 @@ components.card = {
|
|||||||
<span class="library--toggle"></span>
|
<span class="library--toggle"></span>
|
||||||
</h2>
|
</h2>
|
||||||
</label>`);
|
</label>`);
|
||||||
$el.addEventListener('change', async (event) =>
|
$el.addEventListener('change', async (event) => {
|
||||||
storage.set('_enabled', id, !(await storage.get('_enabled', id, false)))
|
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;
|
return $el;
|
||||||
},
|
},
|
||||||
tags: ({ tags = [] }) =>
|
tags: ({ tags = [] }) =>
|
||||||
@ -425,7 +444,8 @@ window.addEventListener('popstate', (event) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const notifications = {
|
const notifications = {
|
||||||
_generate({ heading, message = '', type = 'information' }, onDismiss = () => {}) {
|
$list: document.querySelector('.notification--list'),
|
||||||
|
push({ heading, message = '', type = 'information' }, onDismiss = () => {}) {
|
||||||
let svg = '',
|
let svg = '',
|
||||||
className = 'notification';
|
className = 'notification';
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -462,7 +482,7 @@ const notifications = {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$notif.style.opacity = 1;
|
$notif.style.opacity = 1;
|
||||||
}, 100);
|
}, 100);
|
||||||
return $notif;
|
return this.$list.append($notif);
|
||||||
},
|
},
|
||||||
async fetch() {
|
async fetch() {
|
||||||
const notifications = {
|
const notifications = {
|
||||||
@ -473,7 +493,6 @@ const notifications = {
|
|||||||
notifications.waiting = notifications.list.filter(
|
notifications.waiting = notifications.list.filter(
|
||||||
({ id }) => !notifications.dismissed.includes(id)
|
({ id }) => !notifications.dismissed.includes(id)
|
||||||
);
|
);
|
||||||
const $list = document.querySelector('.notification--list');
|
|
||||||
for (let notification of notifications.waiting) {
|
for (let notification of notifications.waiting) {
|
||||||
if (
|
if (
|
||||||
notification.heading &&
|
notification.heading &&
|
||||||
@ -482,16 +501,23 @@ const notifications = {
|
|||||||
notification.appears_on.versions.includes(env.version)) &&
|
notification.appears_on.versions.includes(env.version)) &&
|
||||||
notification.appears_on.extension
|
notification.appears_on.extension
|
||||||
) {
|
) {
|
||||||
$list.append(
|
this.push(notification, async () => {
|
||||||
this._generate(notification, async () => {
|
const dismissed = await storage.get(_id, 'notifications', []);
|
||||||
const dismissed = await storage.get(_id, 'notifications', []);
|
storage.set('_notifications', 'external', [
|
||||||
storage.set(_id, 'notifications', [...new Set([...dismissed, notification.id])]);
|
...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();
|
notifications.fetch();
|
||||||
|
|
||||||
async function theme() {
|
async function theme() {
|
||||||
|
@ -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"
|
||||||
|
]
|
||||||
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user