From a2b93cb513d7dc4bb2100e9c23d10b2fd466e1af Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Tue, 28 Sep 2021 00:11:47 +1000 Subject: [PATCH] init menu with twind + notifications --- extension/api/env.mjs | 10 + extension/api/registry.mjs | 22 +- extension/api/storage.mjs | 2 +- extension/api/web.mjs | 4 +- extension/dep/style-vendorizer.mjs | 58 ++ extension/launcher.js | 15 +- .../client.mjs | 33 +- .../menu-old.css | 513 ++++++++++++++++++ .../menu.css | 502 +---------------- .../menu.html | 27 +- .../menu.js | 76 +-- .../menu.mjs | 145 +++++ .../mod.json | 2 +- .../client.mjs | 11 +- .../variables.css | 1 - 15 files changed, 786 insertions(+), 635 deletions(-) create mode 100644 extension/dep/style-vendorizer.mjs create mode 100644 extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu-old.css create mode 100644 extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.mjs diff --git a/extension/api/env.mjs b/extension/api/env.mjs index ce7ef28..7d90ae4 100644 --- a/extension/api/env.mjs +++ b/extension/api/env.mjs @@ -38,3 +38,13 @@ export const focusNotion = () => chrome.runtime.sendMessage({ action: 'focusNoti /** reload all notion and enhancer menu tabs to apply changes */ export const reloadTabs = () => chrome.runtime.sendMessage({ action: 'reloadTabs' }); + +/** a notification displayed when the menu is opened for the first time */ +export const welcomeNotification = { + id: '84e2d49b-c3dc-44b4-a154-cf589676bfa0', + color: 'blue', + icon: 'message-circle', + message: 'Welcome! Come chat with us on Discord.', + link: 'https://discord.gg/sFWPXtA', + version, +}; diff --git a/extension/api/registry.mjs b/extension/api/registry.mjs index 8fb6d5b..e9719eb 100644 --- a/extension/api/registry.mjs +++ b/extension/api/registry.mjs @@ -50,9 +50,7 @@ async function validate(mod) { const test = await is( type === 'file' && value ? `repo/${mod._dir}/${value}` : value, type, - { - extension, - } + { extension } ); if (!test) { if (optional && (await is(value, 'undefined'))) return true; @@ -288,3 +286,21 @@ export const optionDefault = async (id, key) => { return undefined; } }; + +/** + * access the storage partition of a mod in the current profile + * @param {string} id - the uuid of the mod + * @returns {object} an object with the wrapped get/set functions + */ +export const db = async (id) => { + return storage.db( + ['profiles', await storage.get(['currentprofile'], 'default'), id], + async (path, fallback = undefined) => { + if (path.length === 4) { + // profiles -> profile -> mod -> option + fallback = (await optionDefault(id, path[3])) ?? fallback; + } + return storage.get(path, fallback); + } + ); +}; diff --git a/extension/api/storage.mjs b/extension/api/storage.mjs index 13d9f91..15a63a2 100644 --- a/extension/api/storage.mjs +++ b/extension/api/storage.mjs @@ -54,7 +54,7 @@ export const set = (path, value) => { } const pathClone = [...path], namespace = path.shift(); - chrome.storage.sync.get([], async (values) => { + chrome.storage.sync.get(async (values) => { const update = values[namespace] ?? {}; let pointer = update, old; diff --git a/extension/api/web.mjs b/extension/api/web.mjs index aa58913..017e810 100644 --- a/extension/api/web.mjs +++ b/extension/api/web.mjs @@ -148,9 +148,7 @@ export const loadStylesheet = (path) => { export const icon = (name, attrs = {}) => { if (!_$featherStylesheet) { _$featherStylesheet = html`