summaryrefslogtreecommitdiff
path: root/frontend/src
diff options
context:
space:
mode:
authorAAGaming <aagaming@riseup.net>2024-02-21 17:39:13 -0500
committerAAGaming <aagaming@riseup.net>2024-02-21 17:39:13 -0500
commita449181802f05c0d1bd1a318741ce347e993d6f7 (patch)
treecbc10cf34623e0895bf434f1501a26362a9e8591 /frontend/src
parent4696583680e18599280ebcce1d8db759294e27e4 (diff)
downloaddecky-loader-a449181802f05c0d1bd1a318741ce347e993d6f7.tar.gz
decky-loader-a449181802f05c0d1bd1a318741ce347e993d6f7.zip
hook up the backend api
Diffstat (limited to 'frontend/src')
-rw-r--r--frontend/src/plugin-loader.tsx40
-rw-r--r--frontend/src/start.tsx1
2 files changed, 7 insertions, 34 deletions
diff --git a/frontend/src/plugin-loader.tsx b/frontend/src/plugin-loader.tsx
index fd5762ea..d9b1211e 100644
--- a/frontend/src/plugin-loader.tsx
+++ b/frontend/src/plugin-loader.tsx
@@ -66,11 +66,9 @@ class PluginLoader extends Logger {
private reloadLock: boolean = false;
// stores a list of plugin names which requested to be reloaded
private pluginReloadQueue: { name: string; version?: string }[] = [];
- private apiKeys: Map<string, string> = new Map();
constructor() {
super(PluginLoader.name);
- console.log(import.meta.url);
DeckyBackend.addEventListener('loader/notify_updates', this.notifyUpdates.bind(this));
DeckyBackend.addEventListener('loader/import_plugin', this.importPlugin.bind(this));
@@ -123,6 +121,8 @@ class PluginLoader extends Logger {
initFilepickerPatches();
+ this.initPluginBackendAPI();
+
Promise.all([this.getUserInfo(), this.updateVersion()])
.then(() => this.loadPlugins())
.then(() => this.checkPluginUpdates())
@@ -334,14 +334,8 @@ class PluginLoader extends Logger {
try {
switch (loadType) {
case PluginLoadType.ESMODULE_V1:
- const uuid = this.initPluginBackendAPIConnection(name);
- let plugin_export: () => Plugin;
- try {
- plugin_export = await import(`http://127.0.0.1:1337/plugins/${name}/dist/index.js#apiKey=${uuid}`);
- } finally {
- this.destroyPluginBackendAPIConnection(uuid);
- }
- let plugin = plugin_export();
+ const plugin_exports = await import(`http://127.0.0.1:1337/plugins/${name}/dist/index.js`);
+ let plugin = plugin_exports.default();
this.plugins.push({
...plugin,
@@ -508,25 +502,12 @@ class PluginLoader extends Logger {
}
}
- destroyPluginBackendAPIConnection(uuid: string) {
- if (this.apiKeys.delete(uuid)) {
- this.debug(`backend api connection init data destroyed for ${uuid}`);
- }
- }
-
initPluginBackendAPI() {
// Things will break *very* badly if plugin code touches this outside of @decky/backend, so lets make that clear.
window.__DECKY_SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_deckyPluginBackendAPIInit = {
- connect: (version: number, key: string) => {
- if (!this.apiKeys.has(key)) {
- throw new Error(`Backend API key ${key} is invalid.`);
- }
-
- const pluginName = this.apiKeys.get(key)!;
-
+ connect: (version: number, pluginName: string) => {
if (version <= 0) {
- this.destroyPluginBackendAPIConnection(key);
- throw new Error(`UUID ${key} requested invalid backend api version ${version}.`);
+ throw new Error(`Plugin ${pluginName} requested invalid backend api version ${version}.`);
}
const backendAPI = {
@@ -538,19 +519,12 @@ class PluginLoader extends Logger {
},
};
- this.destroyPluginBackendAPIConnection(key);
+ this.debug(`${pluginName} connected to backend API.`);
return backendAPI;
},
};
}
- initPluginBackendAPIConnection(pluginName: string) {
- const key = crypto.randomUUID();
- this.apiKeys.set(key, pluginName);
-
- return key;
- }
-
createLegacyPluginAPI(pluginName: string) {
const pluginAPI = {
routerHook: this.routerHook,
diff --git a/frontend/src/start.tsx b/frontend/src/start.tsx
index a2837a1b..e9a2a8ec 100644
--- a/frontend/src/start.tsx
+++ b/frontend/src/start.tsx
@@ -44,7 +44,6 @@ declare global {
window?.DeckyPluginLoader?.deinit();
window.DeckyPluginLoader = new PluginLoader();
DeckyPluginLoader.init();
- console.log(import.meta.url);
})();
export default i18n;