diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 3e76c46..38d04d4 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -53,16 +53,16 @@ module.exports = { }; ``` -| key | value | type | -| ------- | -------------------------------------------------------------------------------------------------- | ----------------- | -| id | **required:** uuidv4 | _string_ | -| name | **required:** short name (e.g. 'frameless window') | _string_ | -| tags | **required:** categories/type (e.g. 'extension', 'theme', 'light', 'dark') | _array\_ | -| desc | **optional:** 1-3 sentence description of what the module is/does, with basic markdown formatting. | _string_ | -| version | **required:** semver (e.g. '0.3.7') | _string_ | -| author | **required:** github username | _string_ | -| options | **optional:** see below: options made available in the enhancer menu (accessible from the tray) | _array\_ | -| hacks | **optional:** see below: code inserted at various points | _object_ | +| key | value | type | +| ------- | ----------------------------------------------------------------------------------------------- | ----------------- | +| id | **required:** uuidv4 | _string_ | +| name | **required:** short name (e.g. 'frameless window') | _string_ | +| tags | **required:** categories/type (e.g. 'extension', 'theme', 'light', 'dark') | _array\_ | +| desc | **optional:** 1-3 sentence description of what the module is/does, with basic markdown support. | _string_ | +| version | **required:** semver (e.g. '0.3.7') | _string_ | +| author | **required:** github username | _string_ | +| options | **optional:** see below: options made available in the enhancer menu (accessible from the tray) | _array\_ | +| hacks | **optional:** see below: code inserted at various points | _object_ | #### options @@ -86,7 +86,7 @@ each "hack" is a function taking 2 arguments. 1. the **`store`** argument, which allows access to the module settings/options defined in `mod.js` (those set in the menu, or used internally by the module). - each module store is saved to + automatically syncs with `~/.notion-enhancer/id.json`. + each module store is automatically saved to + loaded from `~/.notion-enhancer/id.json`. it can be initialised with `const settings = store({ defaults })`, then used as if it were a normal object. 2. the **`__exports`** argument, which is the `module.exports` of the file being modded. this can be used to call or replace functions from notion. diff --git a/mods/bracketed-links/mod.js b/mods/bracketed-links/mod.js new file mode 100644 index 0000000..c2ad673 --- /dev/null +++ b/mods/bracketed-links/mod.js @@ -0,0 +1,16 @@ +/* + * notion-enhancer + * (c) 2020 dragonwocky + * (https://dragonwocky.me/) under the MIT license + */ + +'use strict'; + +module.exports = { + id: '60e14feb-a81d-4ffb-9b12-7585d346bad8', + tags: ['extension'], + name: 'bracketed links', + desc: 'render links surrounded with [brackets] instead of __underlined__.', + version: '0.0.1', + author: 'arecsu', +}; diff --git a/mods/core/css/localised.css b/mods/core/css/localised.css new file mode 100644 index 0000000..a7e3585 --- /dev/null +++ b/mods/core/css/localised.css @@ -0,0 +1,206 @@ +/* + * notion-enhancer + * (c) 2020 dragonwocky + * (https://dragonwocky.me/) under the MIT license + */ + +@import './variables.css'; + +.notion-dark-theme { + --theme_local--main: var(--theme_dark--main); + --theme_local--sidebar: var(--theme_dark--sidebar); + --theme_local--overlay: var(--theme_dark--overlay); + --theme_local--dragarea: var(--theme_dark--dragarea); + --theme_local--preview-width: var(--theme_dark--preview-width); + --theme_local--preview_banner-height: var( + --theme_dark--preview_banner-height + ); + --theme_local--page_banner-height: var(--theme_dark--page_banner-height); + + --theme_local--font_sans: var(--theme_dark--font_sans); + --theme_local--font_serif: var(--theme_dark--font_serif); + --theme_local--font_mono: var(--theme_dark--font_mono); + --theme_local--font_code: var(--theme_dark--font_code); + + --theme_local--scrollbar: var(--theme_dark--scrollbar); + --theme_local--scrollbar-border: var(--theme_dark--scrollbar-border); + --theme_local--scrollbar_hover: var(--theme_dark--scrollbar_hover); + + --theme_local--card: var(--theme_dark--card); + --theme_local--card-border: var(--theme_dark--card-border); + --theme_local--table-border: var(--theme_dark--table-border); + --theme_local--button_hover: var(--theme_dark--button_hover); + --theme_local--button_hover-border: var(--theme_dark--button_hover-border); + --theme_local--button_close: var(--theme_dark--button_close); + --theme_local--button_close-fill: var(--theme_dark--button_close-fill); + + --theme_local--selected: var(--theme_dark--selected); + --theme_local--primary: var(--theme_dark--primary); + --theme_local--primary_hover: var(--theme_dark--primary_hover); + --theme_local--primary_click: var(--theme_dark--primary_click); + --theme_local--primary_indicator: var(--theme_dark--primary_indicator); + + --theme_local--todo_empty-border: var(--theme_dark--todo_empty-border); + --theme_local--todo_ticked: var(--theme_dark--todo_ticked); + --theme_local--todo_ticked-fill: var(--theme_dark--todo_ticked-fill); + --theme_local--todo_ticked-background: var( + --theme_dark--todo_ticked-background + ); + --theme_local--todo_hover-background: var( + --theme_dark--todo_hover-background + ); + + --theme_local--danger_text: var(--theme_dark--danger_text); + --theme_local--danger_border: var(--theme_dark--danger_border); + + --theme_local--text: var(--theme_dark--text); + --theme_local--text_ui: var(--theme_dark--text_ui); + --theme_local--text_ui_info: var(--theme_dark--text_ui_info); + + --theme_local--text_gray: var(--theme_dark--text_gray); + --theme_local--text_brown: var(--theme_dark--text_brown); + --theme_local--text_orange: var(--theme_dark--text_orange); + --theme_local--text_yellow: var(--theme_dark--text_yellow); + --theme_local--text_green: var(--theme_dark--text_green); + --theme_local--text_blue: var(--theme_dark--text_blue); + --theme_local--text_purple: var(--theme_dark--text_purple); + --theme_local--text_pink: var(--theme_dark--text_pink); + --theme_local--text_red: var(--theme_dark--text_red); + --theme_local--bg_gray: var(--theme_dark--bg_gray); + --theme_local--bg_brown: var(--theme_dark--bg_brown); + --theme_local--bg_orange: var(--theme_dark--bg_orange); + --theme_local--bg_yellow: var(--theme_dark--bg_yellow); + --theme_local--bg_green: var(--theme_dark--bg_green); + --theme_local--bg_blue: var(--theme_dark--bg_blue); + --theme_local--bg_purple: var(--theme_dark--bg_purple); + --theme_local--bg_pink: var(--theme_dark--bg_pink); + --theme_local--bg_red: var(--theme_dark--bg_red); + --theme_local--line_gray: var(--theme_dark--line_gray); + --theme_local--line_brown: var(--theme_dark--line_brown); + --theme_local--line_orange: var(--theme_dark--line_orange); + --theme_local--line_yellow: var(--theme_dark--line_yellow); + --theme_local--line_green: var(--theme_dark--line_green); + --theme_local--line_blue: var(--theme_dark--line_blue); + --theme_local--line_purple: var(--theme_dark--line_purple); + --theme_local--line_pink: var(--theme_dark--line_pink); + --theme_local--line_red: var(--theme_dark--line_red); + + --theme_local--code_inline-text: var(--theme_dark--code_inline-text); + --theme_local--code_inline-background: var( + --theme_dark--code_inline-background + ); + --theme_local--code_text: var(--theme_dark--code_text); + --theme_local--code-background: var(--theme_dark--code-background); + --theme_local--code_function: var(--theme_dark--code_function); + --theme_local--code_keyword: var(--theme_dark--code_keyword); + --theme_local--code_tag: var(--theme_dark--code_tag); + --theme_local--code_operator: var(--theme_dark--code_operator); + --theme_local--code_property: var(--theme_dark--code_property); + --theme_local--code_builtin: var(--theme_dark--code_builtin); + --theme_local--code_attr-name: var(--theme_dark--code_attr-name); + --theme_local--code_comment: var(--theme_dark--code_comment); + --theme_local--code_punctuation: var(--theme_dark--code_punctuation); + --theme_local--code_doctype: var(--theme_dark--code_doctype); + --theme_local--code_number: var(--theme_dark--code_number); + --theme_local--code_string: var(--theme_dark--code_string); + --theme_local--code_attr-value: var(--theme_dark--code_attr-value); +} +.notion-light-theme { + --theme_local--main: var(--theme_light--main); + --theme_local--sidebar: var(--theme_light--sidebar); + --theme_local--overlay: var(--theme_light--overlay); + --theme_local--dragarea: var(--theme_light--dragarea); + --theme_local--preview-width: var(--theme_light--preview-width); + --theme_local--preview_banner-height: var( + --theme_light--preview_banner-height + ); + --theme_local--page_banner-height: var(--theme_light--page_banner-height); + + --theme_local--font_sans: var(--theme_light--font_sans); + --theme_local--font_serif: var(--theme_light--font_serif); + --theme_local--font_mono: var(--theme_light--font_mono); + --theme_local--font_code: var(--theme_light--font_code); + + --theme_local--scrollbar: var(--theme_light--scrollbar); + --theme_local--scrollbar-border: var(--theme_light--scrollbar-border); + --theme_local--scrollbar_hover: var(--theme_light--scrollbar_hover); + + --theme_local--card: var(--theme_light--card); + --theme_local--card-border: var(--theme_light--card-border); + --theme_local--table-border: var(--theme_light--table-border); + --theme_local--button_hover: var(--theme_light--button_hover); + --theme_local--button_hover-border: var(--theme_light--button_hover-border); + --theme_local--button_close: var(--theme_light--button_close); + --theme_local--button_close-fill: var(--theme_light--button_close-fill); + + --theme_local--selected: var(--theme_light--selected); + --theme_local--primary: var(--theme_light--primary); + --theme_local--primary_hover: var(--theme_light--primary_hover); + --theme_local--primary_click: var(--theme_light--primary_click); + --theme_local--primary_indicator: var(--theme_light--primary_indicator); + + --theme_local--todo_empty-border: var(--theme_light--todo_empty-border); + --theme_local--todo_ticked: var(--theme_light--todo_ticked); + --theme_local--todo_ticked-fill: var(--theme_light--todo_ticked-fill); + --theme_local--todo_ticked-background: var( + --theme_light--todo_ticked-background + ); + --theme_local--todo_hover-background: var( + --theme_light--todo_hover-background + ); + + --theme_local--danger_text: var(--theme_light--danger_text); + --theme_local--danger_border: var(--theme_light--danger_border); + + --theme_local--text: var(--theme_light--text); + --theme_local--text_ui: var(--theme_light--text_ui); + --theme_local--text_ui_info: var(--theme_light--text_ui_info); + + --theme_local--text_gray: var(--theme_light--text_gray); + --theme_local--text_brown: var(--theme_light--text_brown); + --theme_local--text_orange: var(--theme_light--text_orange); + --theme_local--text_yellow: var(--theme_light--text_yellow); + --theme_local--text_green: var(--theme_light--text_green); + --theme_local--text_blue: var(--theme_light--text_blue); + --theme_local--text_purple: var(--theme_light--text_purple); + --theme_local--text_pink: var(--theme_light--text_pink); + --theme_local--text_red: var(--theme_light--text_red); + --theme_local--bg_gray: var(--theme_light--bg_gray); + --theme_local--bg_brown: var(--theme_light--bg_brown); + --theme_local--bg_orange: var(--theme_light--bg_orange); + --theme_local--bg_yellow: var(--theme_light--bg_yellow); + --theme_local--bg_green: var(--theme_light--bg_green); + --theme_local--bg_blue: var(--theme_light--bg_blue); + --theme_local--bg_purple: var(--theme_light--bg_purple); + --theme_local--bg_pink: var(--theme_light--bg_pink); + --theme_local--bg_red: var(--theme_light--bg_red); + --theme_local--line_gray: var(--theme_light--line_gray); + --theme_local--line_brown: var(--theme_light--line_brown); + --theme_local--line_orange: var(--theme_light--line_orange); + --theme_local--line_yellow: var(--theme_light--line_yellow); + --theme_local--line_green: var(--theme_light--line_green); + --theme_local--line_blue: var(--theme_light--line_blue); + --theme_local--line_purple: var(--theme_light--line_purple); + --theme_local--line_pink: var(--theme_light--line_pink); + --theme_local--line_red: var(--theme_light--line_red); + + --theme_local--code_inline-text: var(--theme_light--code_inline-text); + --theme_local--code_inline-background: var( + --theme_light--code_inline-background + ); + --theme_local--code_text: var(--theme_light--code_text); + --theme_local--code-background: var(--theme_light--code-background); + --theme_local--code_function: var(--theme_light--code_function); + --theme_local--code_keyword: var(--theme_light--code_keyword); + --theme_local--code_tag: var(--theme_light--code_tag); + --theme_local--code_operator: var(--theme_light--code_operator); + --theme_local--code_property: var(--theme_light--code_property); + --theme_local--code_builtin: var(--theme_light--code_builtin); + --theme_local--code_attr-name: var(--theme_light--code_attr-name); + --theme_local--code_comment: var(--theme_light--code_comment); + --theme_local--code_punctuation: var(--theme_light--code_punctuation); + --theme_local--code_doctype: var(--theme_light--code_doctype); + --theme_local--code_number: var(--theme_light--code_number); + --theme_local--code_string: var(--theme_light--code_string); + --theme_local--code_attr-value: var(--theme_light--code_attr-value); +} diff --git a/mods/core/css/menu.css b/mods/core/css/menu.css index 65b8afd..8eea81a 100644 --- a/mods/core/css/menu.css +++ b/mods/core/css/menu.css @@ -6,6 +6,7 @@ @import './buttons.css'; @import './scrollbars.css'; +@import './localised.css'; @keyframes spin { from { @@ -21,6 +22,10 @@ word-break: break-word; text-decoration: none; text-size-adjust: 100%; + outline-color: var(--theme_local--card-border); +} +*:active { + outline: none; } html, body { @@ -29,6 +34,7 @@ body { margin: 0; padding: 0; overflow: hidden; + background: var(--theme_local--main); } body:not([style]) > * { @@ -47,29 +53,11 @@ body:not([style])::after { animation: spin 0.8s linear infinite; } -.notion-dark-theme * { - outline-color: var(--theme_dark--card-border); -} -.notion-light-theme * { - outline-color: var(--theme_light--card-border); -} -*:active { - outline: none; -} - -.notion-dark-theme { - background: var(--theme_dark--main); -} -.notion-light-theme { - background: var(--theme_light--main); -} - main { - padding: 1em; + padding: 1em 1em 2.9em 1em; height: 100%; overflow: auto; } - main section { border-radius: 2px; padding: 0.75em; @@ -78,36 +66,24 @@ main section { /* inline formatting */ +body, +button { + color: var(--theme_local--text); + font-family: var(--theme_local--font_sans); +} + code { border-radius: 0.1em; padding: 0.2em 0.4em; -} -.notion-dark-theme code { - font: 0.85em var(--theme_dark--font_code); - /* color: var(--theme_dark--code_inline-text); */ - background: var(--theme_dark--code_inline-background); -} -.notion-light-theme code { - font: 0.85em var(--theme_light--font_code); - /* color: var(--theme_light--code_inline-text); */ - background: var(--theme_light--code_inline-background); + font: 0.85em var(--theme_local--font_code); + /* color: var(--theme_local--code_inline-text); */ + background: var(--theme_local--code_inline-background); } u { text-decoration: underline; } -.notion-dark-theme, -.notion-dark-theme button { - color: var(--theme_dark--text); - font-family: var(--theme_dark--font_sans); -} -.notion-light-theme, -.notion-light-theme button { - color: var(--theme_light--text); - font-family: var(--theme_light--font_sans); -} - /* titlebar */ #menu-titlebar::before { @@ -131,11 +107,8 @@ u { #menu-titlebar :first-child { margin-left: auto; } -.notion-dark-theme #menu-titlebar { - background: var(--theme_dark--dragarea); -} -.notion-light-theme #menu-titlebar { - background: var(--theme_light--dragarea); +#menu-titlebar { + background: var(--theme_local--dragarea); } /* alerts */ @@ -155,13 +128,40 @@ u { font-size: 1rem; margin: auto 0; padding-left: 0.5em; + color: var(--theme_local--text_ui); } -.notion-dark-theme #alerts [role='alert'] p { - color: var(--theme_dark--text_ui); +#alerts .error::before { + color: var(--theme_local--bg_red); } -.notion-light-theme #alerts [role='alert'] p { - color: var(--theme_light--text_ui); +#alerts .error { + border: 1px solid var(--theme_local--bg_red); + background: var(--theme_local--line_red); +} + +#alerts .warning::before { + color: var(--theme_local--bg_yellow); +} +#alerts .warning { + border: 1px solid var(--theme_local--bg_yellow); + background: var(--theme_local--line_yellow); +} + +#alerts .info::before { + color: var(--theme_local--bg_blue); +} +#alerts .info { + border: 1px solid var(--theme_local--bg_blue); + background: var(--theme_local--line_blue); +} + +#alerts .success::before { + content: '✓'; + color: var(--theme_local--bg_green); +} +#alerts .success { + border: 1px solid var(--theme_local--bg_green); + background: var(--theme_local--line_green); } .notion-light-theme #alerts [role='alert']::before { @@ -171,62 +171,11 @@ u { border: 1px solid rgba(0, 0, 0, 0.1); } -.notion-dark-theme #alerts .error { - border: 1px solid var(--theme_dark--bg_red); - background: var(--theme_dark--line_red); -} -.notion-dark-theme #alerts .error::before { - color: var(--theme_dark--bg_red); -} -.notion-light-theme #alerts .error { - background: var(--theme_light--line_red); -} +/* module meta */ -.notion-dark-theme #alerts .warning { - border: 1px solid var(--theme_dark--bg_yellow); - background: var(--theme_dark--line_yellow); -} -.notion-dark-theme #alerts .warning::before { - color: var(--theme_dark--bg_yellow); -} -.notion-light-theme #alerts .warning { - background: var(--theme_light--line_yellow); -} - -.notion-dark-theme #alerts .info { - border: 1px solid var(--theme_dark--bg_blue); - background: var(--theme_dark--line_blue); -} -.notion-dark-theme #alerts .info::before { - color: var(--theme_dark--bg_blue); -} -.notion-light-theme #alerts .info { - background: var(--theme_light--line_blue); -} - -#alerts .success::before { - content: '✓'; -} -.notion-dark-theme #alerts .success { - border: 1px solid var(--theme_dark--bg_green); - background: var(--theme_dark--line_green); -} -.notion-dark-theme #alerts .success::before { - color: var(--theme_dark--bg_green); -} -.notion-light-theme #alerts .success { - background: var(--theme_light--line_green); -} - -/* modules */ - -.notion-dark-theme #modules section { - background: var(--theme_dark--sidebar); - border: 1px solid var(--theme_dark--table-border); -} -.notion-light-theme #modules section { - background: var(--theme_light--sidebar); - border: 1px solid var(--theme_light--card-border); +#modules section { + background: var(--theme_local--sidebar); + border: 1px solid var(--theme_local--table-border); } #modules section h3, @@ -272,12 +221,54 @@ u { #modules section .tags, #modules section .version { font-size: 0.85em; + color: var(--theme_local--text_ui); } -.notion-dark-theme #modules section .tags, -.notion-dark-theme #modules section .version { - color: var(--theme_dark--text_ui); + +/* module options */ + +.toggle * { + cursor: pointer; } -.notion-light-theme #modules section .tags, -.notion-light-theme #modules section .version { - color: var(--theme_light--text_ui); +.toggle input { + display: none; +} +.toggle input + label .switch { + position: relative; + margin-top: 0.5em; + float: right; + height: 0.65em; + width: 2em; + background: var(--theme_local--card); + border-radius: 5px; +} +.toggle input + label .switch:before { + content: ''; + position: absolute; + left: 0; + top: 0; + right: 0; + bottom: 0; + border-radius: inherit; + background: linear-gradient( + 90deg, + var(--theme_local--primary), + var(--theme_local--primary_click) + ); + opacity: var(--menu--toggle_opacity, 0); + transition: opacity 300ms; +} +.toggle input + label .switch .dot { + position: absolute; + width: 1em; + height: 1em; + top: -0.15em; + border-radius: 50%; + transform: translateX(var(--menu--toggle_offset, 0)); + transition: transform 350ms, box-shadow 350ms; + background: var(--theme_local--todo_ticked-fill); + box-shadow: 2px 1px 4px var(--theme_local--table-border); +} +.toggle input:checked + label { + --menu--toggle_offset: 1em; + --menu--toggle_opacity: 1; } diff --git a/mods/core/menu.js b/mods/core/menu.js index 37ccf5e..739f2dc 100644 --- a/mods/core/menu.js +++ b/mods/core/menu.js @@ -18,10 +18,7 @@ window['__start'] = async () => { document.defaultView.addEventListener('keyup', (event) => { if (event.code === 'F5') window.reload(); - if (event.key === 'e' && (event.ctrlKey || event.metaKey)) { - electron.remote.BrowserWindow.getAllWindows()[0].show(); - browser.close(); - } + if (event.key === 'e' && (event.ctrlKey || event.metaKey)) browser.close(); }); electron.ipcRenderer.on('enhancer:set-theme', (event, theme) => { @@ -113,28 +110,69 @@ window['__start'] = async () => { // mod options function markdown(string) { - return snarkdown( - string - .split('\n') - .map((line) => line.trim()) - .join('
') - ).replace(/([^\\])?~~([^\n]*[^\\])~~/g, '$1$2'); + return string + .split('\n') + .map((line) => + line + // todo: stop e.g. whole chunk of ~~thin~~g~~ being selected + .trim() + // ~~strikethrough~~ + .replace(/([^\\])?~~([^\n]*[^\\])~~/g, '$1$2') + // __underline__ + .replace(/([^\\])?__([^\n]*[^\\])__/g, '$1$2') + // **bold** + .replace(/([^\\])?\*\*([^\n]*[^\\])\*\*/g, '$1$2') + // *italic* + .replace(/([^\\])?\*([^\n]*[^\\])\*/g, '$1$2') + // _italic_ + .replace(/([^\\])?_([^\n]*[^\\])_/g, '$1$2') + // `code` + .replace(/([^\\])?`([^\n]*[^\\])`/g, '$1$2') + // ![image_title](source) + .replace( + /([^\\])?\!\[([^\n]*[^\\]?)\]\(([^\n]*[^\\])\)/g, + '$1$2' + ) + // [link](destination) + .replace( + /([^\\])?\[([^\n]*[^\\])\]\(([^\n]*[^\\])\)/g, + '$1$2' + ) + ) + .join('
'); } const $modules = document.querySelector('#modules'); - for (let mod of modules.loaded.sort((a, b) => - store('mods', { [mod.id]: { pinned: false } }).pinned + for (let mod of modules.loaded.sort((a, b) => { + return a.tags.includes('core') || + store('mods', { [a.id]: { pinned: false } }).pinned + ? -1 + : b.tags.includes('core') || + store('mods', { [b.id]: { pinned: false } }).pinned ? 1 - : a.name.localeCompare(b.name) - )) { - $modules.append( - createElement(` + : a.name.localeCompare(b.name); + })) { + const menuStore = store('mods', { [mod.id]: { enabled: false } }); + mod.store = store(mod.id); + mod.elem = createElement(` - `) - ); + `); + const $enable = mod.elem.querySelector(`#enable_${mod.id}`); + if ($enable) + $enable.addEventListener('click', (event) => { + menuStore[mod.id].enabled = $enable.checked; + }); + $modules.append(mod.elem); } }; diff --git a/mods/core/mod.js b/mods/core/mod.js index 894d854..66a3c58 100644 --- a/mods/core/mod.js +++ b/mods/core/mod.js @@ -20,12 +20,10 @@ module.exports = { id: '0f0bf8b6-eae6-4273-b307-8fc43f2ee082', tags: ['core', 'extension'], name: 'notion-enhancer core', - desc: `the **modloader** itself, _including_: the [CLI](https://github.com), the menu, and ~~enabling/disabling/insertion/updating of~~ mods. + desc: `the **modloader** itself, _including_: the [CLI](https://github.com), the \`menu\`, and ~~enabling/disabling/insertion/updating of~~ mods. ![](https://preview.redd.it/vtiw9ulqlt951.png?width=1368&format=png&auto=webp&s=733d8b27ec62151c7858b4eca463f809ead6395a)`, version: require('../../package.json').version, author: 'dragonwocky', - thumb: - 'https://camo.githubusercontent.com/5c5bca9e987d986b8cc7e51066f90c6f8a84af08/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3733313634373938343332333931393933332f3733313732373235393239353032333132342f494d475f323137302e6a7067', options: [], hacks: { 'main/main.js': require('./tray.js')(defaults), diff --git a/pkg/loader.js b/pkg/loader.js index e318eb1..d5213af 100644 --- a/pkg/loader.js +++ b/pkg/loader.js @@ -35,23 +35,23 @@ module.exports = function (__file, __exports) { const modules = helpers.getEnhancements(); for (let mod of modules.loaded) { if ( - __file === 'renderer/preload.js' && - fs.pathExistsSync( - path.resolve(`${__dirname}/../mods/${mod.dir}/styles.css`) - ) - ) { - document.addEventListener('readystatechange', (event) => { - if (document.readyState !== 'complete') return false; - const style = document.createElement('link'); - style.rel = 'stylesheet'; - style.href = `enhancement://${mod.dir}/styles.css`; - document.querySelector('head').appendChild(style); - }); - } - if ( - mod.type === 'core' || - store('mods', { [mod.id]: { enabled: false } })[mod.id] + (mod.tags || []).includes('core') || + store('mods', { [mod.id]: { enabled: false } })[mod.id].enabled ) { + if ( + __file === 'renderer/preload.js' && + fs.pathExistsSync( + path.resolve(`${__dirname}/../mods/${mod.dir}/styles.css`) + ) + ) { + document.addEventListener('readystatechange', (event) => { + if (document.readyState !== 'complete') return false; + const style = document.createElement('link'); + style.rel = 'stylesheet'; + style.href = `enhancement://${mod.dir}/styles.css`; + document.querySelector('head').appendChild(style); + }); + } if (mod.hacks && mod.hacks[__file]) mod.hacks[__file]( (...args) => diff --git a/pkg/store.js b/pkg/store.js index 5255129..9d8e45d 100644 --- a/pkg/store.js +++ b/pkg/store.js @@ -15,19 +15,25 @@ module.exports = (namespace, defaults = {}) => { namespace = path.resolve(`${data_folder}/${namespace}.json`); fs.ensureDirSync(data_folder); - const getData = () => ({ ...defaults, ...getJSON(namespace) }); - // fs.writeJsonSync(namespace, getData()); - - return new Proxy(defaults, { - get(obj, prop) { - obj = getData(); - return obj[prop]; - }, - set(obj, prop, val) { - obj = getData(); - obj[prop] = val; - fs.writeJsonSync(namespace, obj); - return true; - }, - }); + let data; + const saveData = () => fs.writeJsonSync(namespace, data), + handler = { + get(obj, prop) { + if (prop === 'isProxy') return true; + if ( + typeof obj[prop] === 'object' && + obj[prop] !== null && + !obj[prop].isProxy + ) + obj[prop] = new Proxy(obj[prop], handler); + return obj[prop]; + }, + set(obj, prop, val) { + obj[prop] = val; + saveData(); + return true; + }, + }; + data = new Proxy({ ...defaults, ...getJSON(namespace) }, handler); + return data; };