summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarios8543 <marios8543@gmail.com>2023-10-17 16:07:43 +0300
committermarios8543 <marios8543@gmail.com>2023-10-31 23:17:49 +0200
commit39f64ca6667a0e8703a7a52d6e2bf0da57ee2cb6 (patch)
treec66694a983f4869cecb728c44928e01a1da97b07
parent2391af09eb8d97e485804d8f5c8798a0f1f776a8 (diff)
downloaddecky-loader-39f64ca6667a0e8703a7a52d6e2bf0da57ee2cb6.tar.gz
decky-loader-39f64ca6667a0e8703a7a52d6e2bf0da57ee2cb6.zip
Drop support for legacy plugins
-rw-r--r--backend/src/helpers.py2
-rw-r--r--backend/src/loader.py48
-rw-r--r--backend/src/main.py1
-rw-r--r--backend/src/plugin.py5
-rw-r--r--frontend/src/components/LegacyPlugin.tsx11
-rw-r--r--frontend/src/plugin-loader.tsx19
6 files changed, 6 insertions, 80 deletions
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 ca6eef58..b4623791 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 b57bc5f7..ab33c3eb 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',