mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-06 05:29:02 +00:00
force one theme per mode, move notif cache outside of profile, cleanup test data
This commit is contained in:
parent
775d8412d0
commit
ccbcdaf76a
@ -98,6 +98,19 @@ async function validate(mod) {
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
(mod.tags.includes('theme') &&
|
||||
!(mod.tags.includes('light') || mod.tags.includes('dark'))) ||
|
||||
(mod.tags.includes('light') && mod.tags.includes('dark'))
|
||||
) {
|
||||
_errors.push({
|
||||
source: mod._dir,
|
||||
message: `invalid tags (themes must be either 'light' or 'dark', not neither or both): ${JSON.stringify(
|
||||
mod.tags
|
||||
)}`,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return mod.tags.map((tag) => check('tags.tag', tag, 'string'));
|
||||
}),
|
||||
check('authors', mod.authors, 'array').then((passed) => {
|
||||
|
@ -3,7 +3,6 @@
|
||||
"id": "cb6fd684-f113-4a7a-9423-8f0f0cff069f",
|
||||
"version": "0.2.0",
|
||||
"description": "go straight to the normal full view when opening a page.",
|
||||
"preview": "https://cdn.pixabay.com/photo/2021/09/17/15/17/fruit-6633086_960_720.jpg",
|
||||
"tags": ["extension", "automation"],
|
||||
"authors": [
|
||||
{
|
||||
@ -11,12 +10,6 @@
|
||||
"email": "thedragonring.bod@gmail.com",
|
||||
"homepage": "https://dragonwocky.me/",
|
||||
"avatar": "https://dragonwocky.me/avatar.jpg"
|
||||
},
|
||||
{
|
||||
"name": "fake person",
|
||||
"email": "thedragonring.bod@gmail.com",
|
||||
"homepage": "https://dragonwocky.me/",
|
||||
"avatar": "https://cdn.pixabay.com/photo/2015/04/20/13/28/lizard-731336_960_720.jpg"
|
||||
}
|
||||
],
|
||||
"js": {
|
||||
@ -25,55 +18,5 @@
|
||||
"css": {
|
||||
"client": ["client.css"]
|
||||
},
|
||||
"options": [
|
||||
{
|
||||
"type": "toggle",
|
||||
"key": "toggle",
|
||||
"label": "toggle",
|
||||
"tooltip": "toggle",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"type": "select",
|
||||
"key": "select",
|
||||
"label": "select",
|
||||
"tooltip": "select",
|
||||
"values": ["option A", "option B", "option C"]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"key": "text",
|
||||
"label": "text",
|
||||
"tooltip": "text",
|
||||
"value": "default"
|
||||
},
|
||||
{
|
||||
"type": "hotkey",
|
||||
"key": "hotkey",
|
||||
"label": "hotkey",
|
||||
"tooltip": "hotkey",
|
||||
"value": "Ctrl+Shift+H"
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"key": "number",
|
||||
"label": "number",
|
||||
"tooltip": "number",
|
||||
"value": 14
|
||||
},
|
||||
{
|
||||
"type": "color",
|
||||
"key": "color",
|
||||
"label": "color",
|
||||
"tooltip": "color",
|
||||
"value": "rgba(125, 26, 250, 0.7)"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"key": "file",
|
||||
"label": "file",
|
||||
"tooltip": "file",
|
||||
"extensions": [".css"]
|
||||
}
|
||||
]
|
||||
"options": []
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
'use strict';
|
||||
|
||||
export default async function (api, db) {
|
||||
const { env, fs, registry, web } = api;
|
||||
const { env, fs, storage, registry, web } = api;
|
||||
|
||||
web.addHotkeyListener(await db.get(['hotkey']), env.focusMenu);
|
||||
|
||||
@ -31,7 +31,7 @@ export default async function (api, db) {
|
||||
$sidebarLink.addEventListener('click', env.focusMenu);
|
||||
|
||||
const notifications = {
|
||||
cache: await db.get(['notifications'], []),
|
||||
cache: await storage.get(['notifications'], []),
|
||||
provider: [
|
||||
env.welcomeNotification,
|
||||
...(await fs.getJSON('https://notion-enhancer.github.io/notifications.json')),
|
||||
|
@ -159,9 +159,26 @@ const _$modListCache = {},
|
||||
return $fragment;
|
||||
},
|
||||
mod: async (mod) => {
|
||||
const $mod = web.html`<div class="mod"></div>`,
|
||||
const $mod = web.html`<div class="mod" data-id="${web.escape(mod.id)}"></div>`,
|
||||
$toggle = components.toggle('', await registry.enabled(mod.id));
|
||||
$toggle.addEventListener('change', (event) => {
|
||||
$toggle.addEventListener('change', async (event) => {
|
||||
if (event.target.checked && mod.tags.includes('theme')) {
|
||||
const mode = mod.tags.includes('light') ? 'light' : 'dark',
|
||||
id = mod.id,
|
||||
mods = await registry.list(
|
||||
(mod) =>
|
||||
mod.environments.includes(env.name) &&
|
||||
mod.tags.includes('theme') &&
|
||||
mod.tags.includes(mode) &&
|
||||
mod.id !== id
|
||||
);
|
||||
for (const mod of mods) {
|
||||
registry.profileDB.set(['_mods', mod.id], false);
|
||||
document.querySelector(
|
||||
`[data-id="${web.escape(mod.id)}"] .toggle-check`
|
||||
).checked = false;
|
||||
}
|
||||
}
|
||||
registry.profileDB.set(['_mods', mod.id], event.target.checked);
|
||||
notifications.onChange();
|
||||
});
|
||||
@ -202,7 +219,7 @@ const _$modListCache = {},
|
||||
)
|
||||
);
|
||||
},
|
||||
modList: async (category) => {
|
||||
modList: async (category, message = '') => {
|
||||
if (!_$modListCache[category]) {
|
||||
const $search = web.html`<input type="search" class="search"
|
||||
placeholder="Search ('/' to focus)">`,
|
||||
@ -230,6 +247,7 @@ const _$modListCache = {},
|
||||
$search,
|
||||
web.html`${web.icon('search', { class: 'input-icon' })}`
|
||||
),
|
||||
message ? web.html`<p class="main-message">${web.escape(message)}</p>` : '',
|
||||
$list
|
||||
);
|
||||
}
|
||||
@ -295,7 +313,15 @@ router.addView('extensions', async () => {
|
||||
router.addView('themes', async () => {
|
||||
web.empty($main);
|
||||
selectNavItem($themesNavItem);
|
||||
return web.render($main, await generators.modList('theme'));
|
||||
return web.render(
|
||||
$main,
|
||||
await generators.modList(
|
||||
'theme',
|
||||
`Dark themes will only work when Notion is in dark mode,
|
||||
and light themes will only work when Notion is in light mode.
|
||||
Only one theme of each mode can be enabled at a time.`
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
router.loadView('extensions', $main);
|
||||
|
@ -6,14 +6,14 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { env, fs, fmt, registry, web } from '../../api/_.mjs';
|
||||
import { env, fs, storage, fmt, registry, web } from '../../api/_.mjs';
|
||||
const db = await registry.db('a6621988-551d-495a-97d8-3c568bca2e9e');
|
||||
|
||||
import { tw } from './styles.mjs';
|
||||
|
||||
export const notifications = {
|
||||
$container: web.html`<div class="notifications-container"></div>`,
|
||||
cache: await db.get(['notifications'], []),
|
||||
cache: await storage.get(['notifications'], []),
|
||||
provider: [
|
||||
env.welcomeNotification,
|
||||
...(await fs.getJSON('https://notion-enhancer.github.io/notifications.json')),
|
||||
@ -34,7 +34,7 @@ export const notifications = {
|
||||
resolve = async () => {
|
||||
if (id !== undefined) {
|
||||
notifications.cache.push(id);
|
||||
await db.set(['notifications'], notifications.cache);
|
||||
await storage.set(['notifications'], notifications.cache);
|
||||
}
|
||||
$notification.remove();
|
||||
};
|
||||
|
@ -43,6 +43,7 @@ const customClasses = {
|
||||
'nav-item': apply`ml-4 px-3 py-2 rounded-md text-sm font-medium hover:bg-interactive-hover focus:bg-interactive-focus`,
|
||||
'nav-item-selected': apply`ml-4 px-3 py-2 rounded-md text-sm font-medium ring-1 ring-divider bg-notion-secondary`,
|
||||
'main': apply`transition px-4 py-3 overflow-y-auto max-h-full-48 sm:max-h-full-32 lg:max-h-full-16`,
|
||||
'main-message': apply`mx-2.5 my-2.5 px-px text-sm text-foreground-secondary text-justify`,
|
||||
'mods-list': apply`flex flex-wrap`,
|
||||
'mod-container': apply`w-full md:w-1/2 lg:w-1/3 xl:w-1/4 2xl:w-1/5 px-2.5 py-2.5 box-border`,
|
||||
'mod': apply`relative h-full w-full flex flex-col overflow-hidden rounded-lg shadow-lg
|
||||
|
Loading…
Reference in New Issue
Block a user