diff options
| author | marios8543 <marios8543@gmail.com> | 2023-10-17 16:07:43 +0300 |
|---|---|---|
| committer | marios8543 <marios8543@gmail.com> | 2023-10-17 17:08:23 +0300 |
| commit | 796b8b49f41657a44764c8557b5413bb3935e790 (patch) | |
| tree | 7447f3a2c56f639943d50b18195f6b9e4d0ddfab | |
| parent | 1b9d674a81ab01c52c480cbb6a812938b0e87666 (diff) | |
| download | decky-loader-796b8b49f41657a44764c8557b5413bb3935e790.tar.gz decky-loader-796b8b49f41657a44764c8557b5413bb3935e790.zip | |
Drop support for legacy plugins
| -rw-r--r-- | .github/workflows/build-win.yml | 4 | ||||
| -rw-r--r-- | .github/workflows/build.yml | 2 | ||||
| -rw-r--r-- | backend/src/helpers.py | 2 | ||||
| -rw-r--r-- | backend/src/loader.py | 48 | ||||
| -rw-r--r-- | backend/src/main.py | 1 | ||||
| -rw-r--r-- | backend/src/plugin.py | 5 | ||||
| -rw-r--r-- | frontend/src/components/LegacyPlugin.tsx | 11 | ||||
| -rw-r--r-- | frontend/src/plugin-loader.tsx | 19 |
8 files changed, 9 insertions, 83 deletions
diff --git a/.github/workflows/build-win.yml b/.github/workflows/build-win.yml index 1ce47d4a..b9be5934 100644 --- a/.github/workflows/build-win.yml +++ b/.github/workflows/build-win.yml @@ -44,10 +44,10 @@ jobs: run: pnpm run build - name: Build Python Backend 🛠️ - run: pyinstaller --noconfirm --onefile --name "PluginLoader" --add-data "./backend/static;/static" --add-data "./backend/locales;/locales" --add-data "./backend/src/legacy;/src/legacy" --add-data "./plugin;/plugin" --hidden-import=sqlite3 ./backend/main.py + run: pyinstaller --noconfirm --onefile --name "PluginLoader" --add-data "./backend/static;/static" --add-data "./backend/locales;/locales" --add-data "./plugin;/plugin" --hidden-import=sqlite3 ./backend/main.py - name: Build Python Backend (noconsole) 🛠️ - run: pyinstaller --noconfirm --noconsole --onefile --name "PluginLoader_noconsole" --add-data "./backend/static;/static" --add-data "./backend/locales;/locales" --add-data "./backend/src/legacy;/src/legacy" --add-data "./plugin;/plugin" --hidden-import=sqlite3 ./backend/main.py + run: pyinstaller --noconfirm --noconsole --onefile --name "PluginLoader_noconsole" --add-data "./backend/static;/static" --add-data "./backend/locales;/locales" --add-data "./plugin;/plugin" --hidden-import=sqlite3 ./backend/main.py - name: Upload package artifact ⬆️ uses: actions/upload-artifact@v3 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a2b1e29f..1b1396c1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,7 +87,7 @@ jobs: run: pnpm run build - name: Build Python Backend 🛠️ - run: pyinstaller --noconfirm --onefile --name "PluginLoader" --add-data ./backend/static:/static --add-data ./backend/locales:/locales --add-data ./backend/src/legacy:/src/legacy --add-data ./plugin/*:/ --hidden-import=sqlite3 ./backend/main.py + run: pyinstaller --noconfirm --onefile --name "PluginLoader" --add-data ./backend/static:/static --add-data ./backend/locales:/locales --add-data ./plugin/*:/ --hidden-import=sqlite3 ./backend/main.py - name: Upload package artifact ⬆️ if: ${{ !env.ACT }} diff --git a/backend/src/helpers.py b/backend/src/helpers.py index f8796bd8..0acfd929 100644 --- a/backend/src/helpers.py +++ b/backend/src/helpers.py @@ -32,7 +32,7 @@ def get_csrf_token(): @middleware async def csrf_middleware(request: Request, handler: Handler): - if str(request.method) == "OPTIONS" or request.headers.get('Authentication') == csrf_token or str(request.rel_url) == "/auth/token" or str(request.rel_url).startswith("/plugins/load_main/") or str(request.rel_url).startswith("/static/") or str(request.rel_url).startswith("/legacy/") or str(request.rel_url).startswith("/steam_resource/") or str(request.rel_url).startswith("/frontend/") or assets_regex.match(str(request.rel_url)) or frontend_regex.match(str(request.rel_url)): + if str(request.method) == "OPTIONS" or request.headers.get('Authentication') == csrf_token or str(request.rel_url) == "/auth/token" or str(request.rel_url).startswith("/plugins/load_main/") or str(request.rel_url).startswith("/static/") or str(request.rel_url).startswith("/steam_resource/") or str(request.rel_url).startswith("/frontend/") or assets_regex.match(str(request.rel_url)) or frontend_regex.match(str(request.rel_url)): return await handler(request) return Response(text='Forbidden', status=403) diff --git a/backend/src/loader.py b/backend/src/loader.py index e59cbcaf..f1ba662f 100644 --- a/backend/src/loader.py +++ b/backend/src/loader.py @@ -91,12 +91,7 @@ class Loader: web.get("/plugins/{plugin_name}/frontend_bundle", self.handle_frontend_bundle), web.post("/plugins/{plugin_name}/methods/{method_name}", self.handle_plugin_method_call), web.get("/plugins/{plugin_name}/assets/{path:.*}", self.handle_plugin_frontend_assets), - web.post("/plugins/{plugin_name}/reload", self.handle_backend_reload_request), - - # The following is legacy plugin code. - web.get("/plugins/load_main/{name}", self.load_plugin_main_view), - web.get("/plugins/plugin_resource/{name}/{path:.+}", self.handle_sub_route), - web.get("/steam_resource/{path:.+}", self.get_steam_resource) + web.post("/plugins/{plugin_name}/reload", self.handle_backend_reload_request) ]) async def enable_reload_wait(self): @@ -122,7 +117,7 @@ class Loader: async def get_plugins(self, request: web.Request): plugins = list(self.plugins.values()) - return web.json_response([{"name": str(i) if not i.legacy else "$LEGACY_"+str(i), "version": i.version} for i in plugins]) + return web.json_response([{"name": str(i), "version": i.version} for i in plugins]) async def handle_plugin_frontend_assets(self, request: web.Request): plugin = self.plugins[request.match_info["plugin_name"]] @@ -151,7 +146,7 @@ class Loader: self.plugins[plugin.name] = plugin.start() self.logger.info(f"Loaded {plugin.name}") if not batch: - self.loop.create_task(self.dispatch_plugin(plugin.name if not plugin.legacy else "$LEGACY_" + plugin.name, plugin.version)) + self.loop.create_task(self.dispatch_plugin(plugin.name, plugin.version)) except Exception as e: self.logger.error(f"Could not load {file}. {e}") print_exc() @@ -192,43 +187,6 @@ class Loader: res["success"] = False return web.json_response(res) - """ - The following methods are used to load legacy plugins, which are considered deprecated. - I made the choice to re-add them so that the first iteration/version of the react loader - can work as a drop-in replacement for the stable branch of the PluginLoader, so that we - can introduce it more smoothly and give people the chance to sample the new features even - without plugin support. They will be removed once legacy plugins are no longer relevant. - """ - async def load_plugin_main_view(self, request: web.Request): - plugin = self.plugins[request.match_info["name"]] - with open(path.join(self.plugin_path, plugin.plugin_directory, plugin.main_view_html), "r", encoding="utf-8") as template: - template_data = template.read() - ret = f""" - <script src="/legacy/library.js"></script> - <script>window.plugin_name = '{plugin.name}' </script> - <base href="http://127.0.0.1:1337/plugins/plugin_resource/{plugin.name}/"> - {template_data} - """ - return web.Response(text=ret, content_type="text/html") - - async def handle_sub_route(self, request: web.Request): - plugin = self.plugins[request.match_info["name"]] - route_path = request.match_info["path"] - self.logger.info(path) - ret = "" - file_path = path.join(self.plugin_path, plugin.plugin_directory, route_path) - with open(file_path, "r", encoding="utf-8") as resource_data: - ret = resource_data.read() - - return web.Response(text=ret) - - async def get_steam_resource(self, request: web.Request): - tab = await get_tab("SP") - try: - return web.Response(text=await tab.get_steam_resource(f"https://steamloopback.host/{request.match_info['path']}"), content_type="text/html") - except Exception as e: - return web.Response(text=str(e), status=400) - async def handle_backend_reload_request(self, request: web.Request): plugin_name : str = request.match_info["plugin_name"] plugin = self.plugins[plugin_name] diff --git a/backend/src/main.py b/backend/src/main.py index 83a4b997..1c7c44d1 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -87,7 +87,6 @@ class PluginManager: for route in list(self.web_app.router.routes()): self.cors.add(route) # type: ignore self.web_app.add_routes([static("/static", path.join(path.dirname(__file__), '..', 'static'))]) - self.web_app.add_routes([static("/legacy", path.join(path.dirname(__file__), 'legacy'))]) def exception_handler(self, loop: AbstractEventLoop, context: Dict[str, str]): if context["message"] == "Unclosed connection": diff --git a/backend/src/plugin.py b/backend/src/plugin.py index 163bb9b6..481ede3f 100644 --- a/backend/src/plugin.py +++ b/backend/src/plugin.py @@ -29,11 +29,6 @@ class PluginWrapper: package_json = load(open(path.join(plugin_path, plugin_directory, "package.json"), "r", encoding="utf-8")) self.version = package_json["version"] - self.legacy = False - self.main_view_html = json["main_view_html"] if "main_view_html" in json else "" - self.tile_view_html = json["tile_view_html"] if "tile_view_html" in json else "" - self.legacy = self.main_view_html or self.tile_view_html - self.name = json["name"] self.author = json["author"] self.flags = json["flags"] diff --git a/frontend/src/components/LegacyPlugin.tsx b/frontend/src/components/LegacyPlugin.tsx deleted file mode 100644 index f0dd2521..00000000 --- a/frontend/src/components/LegacyPlugin.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { VFC } from 'react'; - -interface Props { - url: string; -} - -const LegacyPlugin: VFC<Props> = ({ url }) => { - return <iframe style={{ border: 'none', width: '100%', height: '100%' }} src={url}></iframe>; -}; - -export default LegacyPlugin; diff --git a/frontend/src/plugin-loader.tsx b/frontend/src/plugin-loader.tsx index b27a19bb..e5f69f1f 100644 --- a/frontend/src/plugin-loader.tsx +++ b/frontend/src/plugin-loader.tsx @@ -13,7 +13,6 @@ import { FC, lazy } from 'react'; import { FaExclamationCircle, FaPlug } from 'react-icons/fa'; import { DeckyState, DeckyStateContextProvider, UserInfo, useDeckyState } from './components/DeckyState'; -import LegacyPlugin from './components/LegacyPlugin'; import { File, FileSelectionType } from './components/modals/filepicker'; import { deinitFilepickerPatches, initFilepickerPatches } from './components/modals/filepicker/patches'; import MultiplePluginsInstallModal from './components/modals/MultiplePluginsInstallModal'; @@ -238,7 +237,7 @@ class PluginLoader extends Logger { public unloadPlugin(name: string) { console.log('Plugin List: ', this.plugins); - const plugin = this.plugins.find((plugin) => plugin.name === name || plugin.name === name.replace('$LEGACY_', '')); + const plugin = this.plugins.find((plugin) => plugin.name === name); plugin?.onDismount?.(); this.plugins = this.plugins.filter((p) => p !== plugin); this.deckyState.setPlugins(this.plugins); @@ -256,12 +255,7 @@ class PluginLoader extends Logger { this.log(`Trying to load ${name}`); this.unloadPlugin(name); - - if (name.startsWith('$LEGACY_')) { - await this.importLegacyPlugin(name.replace('$LEGACY_', '')); - } else { - await this.importReactPlugin(name, version); - } + await this.importReactPlugin(name, version); this.deckyState.setPlugins(this.plugins); this.log(`Loaded ${name}`); @@ -342,15 +336,6 @@ class PluginLoader extends Logger { } else throw new Error(`${name} frontend_bundle not OK`); } - private async importLegacyPlugin(name: string) { - const url = `http://127.0.0.1:1337/plugins/load_main/${name}`; - this.plugins.push({ - name: name, - icon: <FaPlug />, - content: <LegacyPlugin url={url} />, - }); - } - async callServerMethod(methodName: string, args = {}) { const response = await fetch(`http://127.0.0.1:1337/methods/${methodName}`, { method: 'POST', |
