From 9dcbfc213ff559f2a1c8baba1b73bbd2b7d1386f Mon Sep 17 00:00:00 2001
From: dragonwocky <thedragonring.bod@gmail.com>
Date: Sun, 3 Oct 2021 15:08:42 +1100
Subject: [PATCH] menu: store theme outside profile, reload env on profile
 change

---
 extension/api/fs.mjs                                   |  2 ++
 extension/env/fs.mjs                                   | 10 ++++++----
 .../client.mjs                                         |  2 +-
 .../menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.mjs |  8 ++++----
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/extension/api/fs.mjs b/extension/api/fs.mjs
index 7aa05b3..ef05d90 100644
--- a/extension/api/fs.mjs
+++ b/extension/api/fs.mjs
@@ -25,6 +25,7 @@ export const localPath = fs.localPath;
  * fetch and parse a json file's contents
  * @type {function}
  * @param {string} path - a url or within-the-enhancer filepath
+ * @param {object} [opts] - the second argument of a fetch() request
  * @returns {object} the json value of the requested file as a js object
  */
 export const getJSON = fs.getJSON;
@@ -33,6 +34,7 @@ export const getJSON = fs.getJSON;
  * fetch a text file's contents
  * @type {function}
  * @param {string} path - a url or within-the-enhancer filepath
+ * @param {object} [opts] - the second argument of a fetch() request
  * @returns {string} the text content of the requested file
  */
 export const getText = fs.getText;
diff --git a/extension/env/fs.mjs b/extension/env/fs.mjs
index aaa0209..8183ff3 100644
--- a/extension/env/fs.mjs
+++ b/extension/env/fs.mjs
@@ -21,18 +21,20 @@ export const localPath = chrome.runtime.getURL;
 /**
  * fetch and parse a json file's contents
  * @param {string} path - a url or within-the-enhancer filepath
+ * @param {object} [opts] - the second argument of a fetch() request
  * @returns {object} the json value of the requested file as a js object
  */
-export const getJSON = (path) =>
-  fetch(path.startsWith('http') ? path : localPath(path)).then((res) => res.json());
+export const getJSON = (path, opts = {}) =>
+  fetch(path.startsWith('http') ? path : localPath(path), opts).then((res) => res.json());
 
 /**
  * fetch a text file's contents
  * @param {string} path - a url or within-the-enhancer filepath
+ * @param {object} [opts] - the second argument of a fetch() request
  * @returns {string} the text content of the requested file
  */
-export const getText = (path) =>
-  fetch(path.startsWith('http') ? path : localPath(path)).then((res) => res.text());
+export const getText = (path, opts = {}) =>
+  fetch(path.startsWith('http') ? path : localPath(path), opts).then((res) => res.text());
 
 /**
  * check if a file exists
diff --git a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.mjs b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.mjs
index ed48bc0..bee0597 100644
--- a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.mjs
+++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.mjs
@@ -12,7 +12,7 @@ export default async function (api, db) {
   web.addHotkeyListener(await db.get(['hotkey']), env.focusMenu);
 
   const updateTheme = () =>
-    db.set(['theme'], document.querySelector('.notion-dark-theme') ? 'dark' : 'light');
+    storage.set(['theme'], document.querySelector('.notion-dark-theme') ? 'dark' : 'light');
   web.addDocumentObserver((mutation) => {
     if (mutation.target === document.body && document.hasFocus()) updateTheme();
   });
diff --git a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.mjs b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.mjs
index 6679759..e171d69 100644
--- a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.mjs
+++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.mjs
@@ -25,7 +25,7 @@ web.addHotkeyListener(await db.get(['hotkey']), env.focusNotion);
 
 const loadTheme = async () => {
   document.documentElement.className =
-    (await db.get(['theme'], 'light')) === 'dark' ? 'dark' : '';
+    (await storage.get(['theme'], 'light')) === 'dark' ? 'dark' : '';
 };
 document.addEventListener('visibilitychange', loadTheme);
 loadTheme();
@@ -110,7 +110,7 @@ $profile.addEventListener('click', async (event) => {
           const profileUpload = JSON.parse(progress.currentTarget.result);
           if (!profileUpload) throw Error;
           await storage.set(['profiles', $select.value], profileUpload);
-          location.reload();
+          env.reload();
         } catch {
           web.render(web.empty($error), 'Invalid JSON uploaded.');
         }
@@ -151,7 +151,7 @@ $profile.addEventListener('click', async (event) => {
         );
         await storage.set(['profiles', $select.value], undefined);
       }
-      location.reload();
+      env.reload();
     });
     $delete.addEventListener('click', async (event) => {
       await storage.set(['profiles', $select.value], undefined);
@@ -159,7 +159,7 @@ $profile.addEventListener('click', async (event) => {
         ['currentprofile'],
         profileNames.find((profile) => profile !== $select.value) || 'default'
       );
-      location.reload();
+      env.reload();
     });
 
     _$profileConfig = web.render(