From 8daac68aad8db36a7ff745a159fb693566712387 Mon Sep 17 00:00:00 2001 From: sawka Date: Wed, 8 Nov 2023 00:12:41 -0800 Subject: [PATCH] dont load plugin resources at startup (delays important loads). load on demand if we open the apps screen. --- src/app/sidebar/sidebar.tsx | 11 +++++++++-- src/model/model.ts | 1 + src/plugins/plugins.ts | 13 ++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/app/sidebar/sidebar.tsx b/src/app/sidebar/sidebar.tsx index d3d000690..20ed6a046 100644 --- a/src/app/sidebar/sidebar.tsx +++ b/src/app/sidebar/sidebar.tsx @@ -8,6 +8,7 @@ import { boundMethod } from "autobind-decorator"; import cn from "classnames"; import dayjs from "dayjs"; import type { RemoteType } from "../../types/types"; +import { If, For } from "tsx-control-statements/components"; import { ReactComponent as LeftChevronIcon } from "../assets/icons/chevron_left.svg"; import { ReactComponent as HelpIcon } from "../assets/icons/help.svg"; @@ -235,11 +236,17 @@ class MainSideBar extends React.Component<{}, {}> { Settings -
openLink("https://docs.getprompt.dev")}> +
openLink("https://docs.getprompt.dev")} + > Documentation
-
openLink("https://discord.gg/XfvZ334gwU")}> +
openLink("https://discord.gg/XfvZ334gwU")} + > Discord
diff --git a/src/model/model.ts b/src/model/model.ts index 1328d2870..d16ffba66 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -2455,6 +2455,7 @@ class PluginsModel { selectedPlugin: OV = mobx.observable.box(null, { name: "selectedPlugin" }); showPluginsView(): void { + PluginModel.loadAllPluginResources(); mobx.action(() => { this.reset(); GlobalModel.activeMainView.set("plugins"); diff --git a/src/plugins/plugins.ts b/src/plugins/plugins.ts index 9f6840fc3..5e67a1e3f 100644 --- a/src/plugins/plugins.ts +++ b/src/plugins/plugins.ts @@ -82,6 +82,7 @@ const PluginConfigs: RendererPluginType[] = [ ]; class PluginModelClass { + resourcesLoaded: boolean = false; rendererPlugins: RendererPluginType[] = []; constructor(pluginConfigs: RendererPluginType[]) { @@ -97,11 +98,21 @@ class PluginModelClass { throw new Error(sprintf("plugin with name %s already registered", plugin.name)); } this.rendererPlugins.push(plugin); - this.loadPluginResources(plugin); + // this.loadPluginResources(plugin); return plugin; }); } + loadAllPluginResources() { + if (this.resourcesLoaded) { + return; + } + this.resourcesLoaded = true; + for (let plugin of this.rendererPlugins) { + this.loadPluginResources(plugin); + } + } + // attach all screenshots. webpack doesnt allow dynamic paths, hence, we have to put static paths for each plugin attachScreenshots(plugin) { let screenshotsContext;