From a6831de2865d8ee39b5cf8a62901cf1f8ef1e600 Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Mon, 25 Jan 2021 17:45:57 -0600 Subject: [PATCH] Addon cleanup --- src/addons/README | 17 ------------- src/addons/README.md | 20 +++++++++++++++ src/addons/api.js | 2 +- src/addons/entry-electron.js | 35 --------------------------- src/addons/{entry-web.js => entry.js} | 0 src/addons/settings-store.js | 5 ++++ src/playground/render-interface.jsx | 5 ++-- 7 files changed, 28 insertions(+), 56 deletions(-) delete mode 100644 src/addons/README create mode 100644 src/addons/README.md delete mode 100644 src/addons/entry-electron.js rename src/addons/{entry-web.js => entry.js} (100%) diff --git a/src/addons/README b/src/addons/README deleted file mode 100644 index 43f9db556..000000000 --- a/src/addons/README +++ /dev/null @@ -1,17 +0,0 @@ -Addons, translations, and libraries are from the "Scratch Addons" browser extension. - -These addons are licensed under the GNU General Public License v3.0, not the BSD-3-Clause License. See README.md and LICENSE_GPL in the root of this repository for more information. - -We apply some patches on top of the original source files. These patches are maintained in https://github.com/GarboMuffin/ScratchAddons/tree/tw. We attempt to maintain a minimal diff. - -Any bugs or feature requests in these addons should be sent upstream. - -Folder structure: - + addons - the addons - + addons-l10n - addon translations - + libraries - libraries used by addons loaded with `import` - + libraries-raw - libraries used by addons loaded with `addon.tab.loadScript` - + api-libraries - libraries used by addon API - + settings - the settings page - -addons, addons-l10m, libraries, and libraries-raw and managed by pull.js and any changes may get overwritten. diff --git a/src/addons/README.md b/src/addons/README.md new file mode 100644 index 000000000..0f4cfac20 --- /dev/null +++ b/src/addons/README.md @@ -0,0 +1,20 @@ +# Addons + +Addons and translations are from the [Scratch Addons browser extension](https://scratchaddons.com/). Any bugs or feature requests in these addons should be sent [upstream](https://github.com/ScratchAddons/ScratchAddons/issues). + +Everything in this folder is licensed under the GNU General Public License v3.0, not the BSD-3-Clause License. See README.md and LICENSE_GPL in the root of this repository for more information. + +We apply some patches on top of the original source files. These patches are maintained in https://github.com/GarboMuffin/ScratchAddons/tree/tw. + +entry.js is the script that will actually run the addons. + +pull.js is a magical script that automatically pulls code from GitHub, parses it with regex, and copies everything to the proper folders. + +Directory structure: + + - addons - the addons (managed by pull.js) + - addons-l10n - addon translations (managed by pull.js) + - libraries - libraries used by addons loaded with `import` (managed by pull.js) + - libraries-raw - libraries used by addons loaded with `addon.tab.loadScript` (managed by pull.js) + - api-libraries - libraries used by addon API + - settings - the settings page and its translations diff --git a/src/addons/api.js b/src/addons/api.js index 9d9fdabe1..0cc53637f 100644 --- a/src/addons/api.js +++ b/src/addons/api.js @@ -294,7 +294,7 @@ history.pushState = function (...args) { emitUrlChange(); }; -SettingsStore.addEventListener('reread', () => { +SettingsStore.addEventListener('store-changed', () => { for (const runner of AddonRunner.instances) { runner.settingsChanged(); } diff --git a/src/addons/entry-electron.js b/src/addons/entry-electron.js deleted file mode 100644 index 4d8abf911..000000000 --- a/src/addons/entry-electron.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @license - * Copyright (c) 2021 Thomas Weber - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import {ipcRenderer} from 'electron'; -import AddonRunner from './api'; -import addons from './addon-manifests'; -import SettingsStore from './settings-store'; - -for (const [id, manifest] of Object.entries(addons)) { - if (!SettingsStore.getAddonEnabled(id)) { - continue; - } - const runner = new AddonRunner(id, manifest); - runner.run(); -} - -ipcRenderer.on('addon-settings-changed', (event, settings) => { - SettingsStore.store = settings; - SettingsStore.dispatchEvent(new CustomEvent('reread')); -}); diff --git a/src/addons/entry-web.js b/src/addons/entry.js similarity index 100% rename from src/addons/entry-web.js rename to src/addons/entry.js diff --git a/src/addons/settings-store.js b/src/addons/settings-store.js index 50bc0641b..b3fd609b2 100644 --- a/src/addons/settings-store.js +++ b/src/addons/settings-store.js @@ -288,6 +288,11 @@ class SettingsStore extends EventTarget { } } } + + setStore (store) { + this.store = store; + SettingsStore.dispatchEvent(new CustomEvent('store-changed')); + } } export default new SettingsStore(); diff --git a/src/playground/render-interface.jsx b/src/playground/render-interface.jsx index 1e199dd3f..5e25138d9 100644 --- a/src/playground/render-interface.jsx +++ b/src/playground/render-interface.jsx @@ -55,8 +55,7 @@ window.addEventListener('message', e => { location.reload(); } if (data.type === 'settings-changed') { - SettingsStore.store = data.store; - SettingsStore.dispatchEvent(new CustomEvent('reread')); + SettingsStore.setStore(data.store); } }); @@ -66,7 +65,7 @@ const handleClickAddonSettings = () => { }; const handleLoadAddons = () => { - import(/* webpackChunkName: "addons" */ '../addons/entry-web'); + import(/* webpackChunkName: "addons" */ '../addons/entry'); }; const WrappedMenuBar = compose(