mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-06-17 08:47:49 +00:00
Drop support for legacy plugins
This commit is contained in:
@@ -32,7 +32,7 @@ def get_csrf_token():
|
|||||||
|
|
||||||
@middleware
|
@middleware
|
||||||
async def csrf_middleware(request: Request, handler: Handler):
|
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 await handler(request)
|
||||||
return Response(text='Forbidden', status=403)
|
return Response(text='Forbidden', status=403)
|
||||||
|
|
||||||
|
|||||||
+3
-45
@@ -91,12 +91,7 @@ class Loader:
|
|||||||
web.get("/plugins/{plugin_name}/frontend_bundle", self.handle_frontend_bundle),
|
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.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.get("/plugins/{plugin_name}/assets/{path:.*}", self.handle_plugin_frontend_assets),
|
||||||
web.post("/plugins/{plugin_name}/reload", self.handle_backend_reload_request),
|
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)
|
|
||||||
])
|
])
|
||||||
|
|
||||||
async def enable_reload_wait(self):
|
async def enable_reload_wait(self):
|
||||||
@@ -122,7 +117,7 @@ class Loader:
|
|||||||
|
|
||||||
async def get_plugins(self, request: web.Request):
|
async def get_plugins(self, request: web.Request):
|
||||||
plugins = list(self.plugins.values())
|
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):
|
async def handle_plugin_frontend_assets(self, request: web.Request):
|
||||||
plugin = self.plugins[request.match_info["plugin_name"]]
|
plugin = self.plugins[request.match_info["plugin_name"]]
|
||||||
@@ -151,7 +146,7 @@ class Loader:
|
|||||||
self.plugins[plugin.name] = plugin.start()
|
self.plugins[plugin.name] = plugin.start()
|
||||||
self.logger.info(f"Loaded {plugin.name}")
|
self.logger.info(f"Loaded {plugin.name}")
|
||||||
if not batch:
|
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:
|
except Exception as e:
|
||||||
self.logger.error(f"Could not load {file}. {e}")
|
self.logger.error(f"Could not load {file}. {e}")
|
||||||
print_exc()
|
print_exc()
|
||||||
@@ -192,43 +187,6 @@ class Loader:
|
|||||||
res["success"] = False
|
res["success"] = False
|
||||||
return web.json_response(res)
|
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):
|
async def handle_backend_reload_request(self, request: web.Request):
|
||||||
plugin_name : str = request.match_info["plugin_name"]
|
plugin_name : str = request.match_info["plugin_name"]
|
||||||
plugin = self.plugins[plugin_name]
|
plugin = self.plugins[plugin_name]
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ class PluginManager:
|
|||||||
for route in list(self.web_app.router.routes()):
|
for route in list(self.web_app.router.routes()):
|
||||||
self.cors.add(route) # type: ignore
|
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("/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]):
|
def exception_handler(self, loop: AbstractEventLoop, context: Dict[str, str]):
|
||||||
if context["message"] == "Unclosed connection":
|
if context["message"] == "Unclosed connection":
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ class PluginWrapper:
|
|||||||
package_json = load(open(path.join(plugin_path, plugin_directory, "package.json"), "r", encoding="utf-8"))
|
package_json = load(open(path.join(plugin_path, plugin_directory, "package.json"), "r", encoding="utf-8"))
|
||||||
self.version = package_json["version"]
|
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.name = json["name"]
|
||||||
self.author = json["author"]
|
self.author = json["author"]
|
||||||
self.flags = json["flags"]
|
self.flags = json["flags"]
|
||||||
|
|||||||
@@ -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;
|
|
||||||
@@ -13,7 +13,6 @@ import { FC, lazy } from 'react';
|
|||||||
import { FaExclamationCircle, FaPlug } from 'react-icons/fa';
|
import { FaExclamationCircle, FaPlug } from 'react-icons/fa';
|
||||||
|
|
||||||
import { DeckyState, DeckyStateContextProvider, UserInfo, useDeckyState } from './components/DeckyState';
|
import { DeckyState, DeckyStateContextProvider, UserInfo, useDeckyState } from './components/DeckyState';
|
||||||
import LegacyPlugin from './components/LegacyPlugin';
|
|
||||||
import { File, FileSelectionType } from './components/modals/filepicker';
|
import { File, FileSelectionType } from './components/modals/filepicker';
|
||||||
import { deinitFilepickerPatches, initFilepickerPatches } from './components/modals/filepicker/patches';
|
import { deinitFilepickerPatches, initFilepickerPatches } from './components/modals/filepicker/patches';
|
||||||
import MultiplePluginsInstallModal from './components/modals/MultiplePluginsInstallModal';
|
import MultiplePluginsInstallModal from './components/modals/MultiplePluginsInstallModal';
|
||||||
@@ -238,7 +237,7 @@ class PluginLoader extends Logger {
|
|||||||
|
|
||||||
public unloadPlugin(name: string) {
|
public unloadPlugin(name: string) {
|
||||||
console.log('Plugin List: ', this.plugins);
|
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?.();
|
plugin?.onDismount?.();
|
||||||
this.plugins = this.plugins.filter((p) => p !== plugin);
|
this.plugins = this.plugins.filter((p) => p !== plugin);
|
||||||
this.deckyState.setPlugins(this.plugins);
|
this.deckyState.setPlugins(this.plugins);
|
||||||
@@ -256,12 +255,7 @@ class PluginLoader extends Logger {
|
|||||||
this.log(`Trying to load ${name}`);
|
this.log(`Trying to load ${name}`);
|
||||||
|
|
||||||
this.unloadPlugin(name);
|
this.unloadPlugin(name);
|
||||||
|
await this.importReactPlugin(name, version);
|
||||||
if (name.startsWith('$LEGACY_')) {
|
|
||||||
await this.importLegacyPlugin(name.replace('$LEGACY_', ''));
|
|
||||||
} else {
|
|
||||||
await this.importReactPlugin(name, version);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.deckyState.setPlugins(this.plugins);
|
this.deckyState.setPlugins(this.plugins);
|
||||||
this.log(`Loaded ${name}`);
|
this.log(`Loaded ${name}`);
|
||||||
@@ -342,15 +336,6 @@ class PluginLoader extends Logger {
|
|||||||
} else throw new Error(`${name} frontend_bundle not OK`);
|
} 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 = {}) {
|
async callServerMethod(methodName: string, args = {}) {
|
||||||
const response = await fetch(`http://127.0.0.1:1337/methods/${methodName}`, {
|
const response = await fetch(`http://127.0.0.1:1337/methods/${methodName}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
Reference in New Issue
Block a user