diff --git a/src/renderer/bootstrap.tsx b/src/renderer/bootstrap.tsx index 5d96b3b7de..5b5fd05459 100644 --- a/src/renderer/bootstrap.tsx +++ b/src/renderer/bootstrap.tsx @@ -31,22 +31,17 @@ import * as LensExtensionsRendererApi from "../extensions/renderer-api"; import { render, unmountComponentAtNode } from "react-dom"; import { delay } from "../common/utils"; import { isMac, isDevelopment } from "../common/vars"; -import { HotbarStore } from "../common/hotbar-store"; import { ClusterStore } from "../common/cluster-store"; import { UserStore } from "../common/user-store"; import { ExtensionDiscovery } from "../extensions/extension-discovery"; import { ExtensionLoader } from "../extensions/extension-loader"; -import { ExtensionsStore } from "../extensions/extensions-store"; -import { FilesystemProvisionerStore } from "../main/extension-filesystem"; import { App } from "./components/app"; import { LensApp } from "./lens-app"; -import { ThemeStore } from "./theme.store"; import { HelmRepoManager } from "../main/helm/helm-repo-manager"; import { ExtensionInstallationStateStore } from "./components/+extensions/extension-install.store"; import { DefaultProps } from "./mui-base-theme"; import configurePackages from "../common/configure-packages"; import * as initializers from "./initializers"; -import { WeblinkStore } from "../common/weblink-store"; configurePackages(); @@ -83,30 +78,13 @@ export async function bootstrap(App: AppComponent) { ExtensionLoader.createInstance().init(); ExtensionDiscovery.createInstance().init(); - const userStore = UserStore.createInstance(); - const clusterStore = ClusterStore.createInstance(); - const extensionsStore = ExtensionsStore.createInstance(); - const filesystemStore = FilesystemProvisionerStore.createInstance(); - const themeStore = ThemeStore.createInstance(); - const hotbarStore = HotbarStore.createInstance(); - const weblinkStore = WeblinkStore.createInstance(); + await initializers.initStores(); ExtensionInstallationStateStore.bindIpcListeners(); HelmRepoManager.createInstance(); // initialize the manager - // preload common stores - await Promise.all([ - userStore.load(), - hotbarStore.load(), - clusterStore.load(), - extensionsStore.load(), - filesystemStore.load(), - themeStore.init(), - weblinkStore.load() - ]); - // Register additional store listeners - clusterStore.registerIpcListener(); + ClusterStore.getInstance().registerIpcListener(); // init app's dependencies if any if (App.init) { diff --git a/src/renderer/initializers/index.ts b/src/renderer/initializers/index.ts index c9370d5a82..cbfc6b55e2 100644 --- a/src/renderer/initializers/index.ts +++ b/src/renderer/initializers/index.ts @@ -27,3 +27,4 @@ export * from "./registries"; export * from "./welcome-menu-registry"; export * from "./workloads-overview-detail-registry"; export * from "./catalog"; +export * from "./stores"; diff --git a/src/renderer/initializers/stores.ts b/src/renderer/initializers/stores.ts new file mode 100644 index 0000000000..37bef7530a --- /dev/null +++ b/src/renderer/initializers/stores.ts @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import { HotbarStore } from "../../common/hotbar-store"; +import { ClusterStore } from "../../common/cluster-store"; +import { UserStore } from "../../common/user-store"; +import { ExtensionsStore } from "../../extensions/extensions-store"; +import { FilesystemProvisionerStore } from "../../main/extension-filesystem"; + +import { ThemeStore } from "../theme.store"; +import { WeblinkStore } from "../../common/weblink-store"; + +export async function initStores() { + const userStore = UserStore.createInstance(); + const clusterStore = ClusterStore.createInstance(); + const extensionsStore = ExtensionsStore.createInstance(); + const filesystemStore = FilesystemProvisionerStore.createInstance(); + const themeStore = ThemeStore.createInstance(); + const hotbarStore = HotbarStore.createInstance(); + const weblinkStore = WeblinkStore.createInstance(); + + // preload common stores + await Promise.all([ + userStore.load(), + hotbarStore.load(), + clusterStore.load(), + extensionsStore.load(), + filesystemStore.load(), + themeStore.init(), + weblinkStore.load() + ]); +}