From a449181802f05c0d1bd1a318741ce347e993d6f7 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Wed, 21 Feb 2024 17:39:13 -0500 Subject: hook up the backend api --- frontend/rollup.config.js | 2 ++ frontend/src/plugin-loader.tsx | 40 +++++++--------------------------------- frontend/src/start.tsx | 1 - 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/frontend/rollup.config.js b/frontend/rollup.config.js index ac9ff58c..e86fbf07 100644 --- a/frontend/rollup.config.js +++ b/frontend/rollup.config.js @@ -43,6 +43,8 @@ export default defineConfig({ chunkFileNames: (chunkInfo) => { return 'chunk-[hash].js'; }, + sourcemap: true, + sourcemapPathTransform: (relativeSourcePath) => relativeSourcePath.replace(/^\.\.\//, `decky://decky/loader/`), }, onwarn: function (message, handleWarning) { if (hiddenWarnings.some((warning) => message.code === warning)) return; 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 = 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; -- cgit v1.2.3