diff --git a/src/extensions/extension-loader.ts b/src/extensions/extension-loader.ts index f4f6edc6bc..c5339f31c9 100644 --- a/src/extensions/extension-loader.ts +++ b/src/extensions/extension-loader.ts @@ -23,31 +23,6 @@ export class ExtensionLoader { @observable isLoaded = false; whenLoaded = when(() => this.isLoaded); - constructor() { - if (ipcRenderer) { - const extensionListHandler = ( extensions: [LensExtensionId, InstalledExtension][]) => { - this.isLoaded = true; - extensions.forEach(([extId, ext]) => { - if (!this.extensions.has(extId)) { - this.extensions.set(extId, ext) - } - }) - } - requestMain(this.requestExtensionsChannel).then(extensionListHandler) - subscribeToBroadcast(this.requestExtensionsChannel, (event, extensions: [LensExtensionId, InstalledExtension][]) => { - extensionListHandler(extensions) - }); - } else { - reaction(() => this.extensions.toJS(), () => { - this.broadcastExtensions() - }) - handleRequest(this.requestExtensionsChannel, () => { - return Array.from(this.toJSON()) - }) - } - extensionsStore.manageState(this); - } - @computed get userExtensions(): Map { const extensions = this.extensions.toJS(); extensions.forEach((ext, extId) => { @@ -59,11 +34,45 @@ export class ExtensionLoader { } @action - async init(extensions: Map) { - this.extensions.replace(extensions); + async init(extensions?: Map) { + if (extensions) { + this.extensions.replace(extensions); + } + if (ipcRenderer) { + this.initRenderer() + } else { + this.initMain() + } + extensionsStore.manageState(this); + } + + protected async initMain() { this.isLoaded = true; this.loadOnMain(); this.broadcastExtensions(); + + reaction(() => this.extensions.toJS(), () => { + this.broadcastExtensions() + }) + + handleRequest(this.requestExtensionsChannel, () => { + return Array.from(this.toJSON()) + }) + } + + protected async initRenderer() { + const extensionListHandler = ( extensions: [LensExtensionId, InstalledExtension][]) => { + this.isLoaded = true; + extensions.forEach(([extId, ext]) => { + if (!this.extensions.has(extId)) { + this.extensions.set(extId, ext) + } + }) + } + requestMain(this.requestExtensionsChannel).then(extensionListHandler) + subscribeToBroadcast(this.requestExtensionsChannel, (event, extensions: [LensExtensionId, InstalledExtension][]) => { + extensionListHandler(extensions) + }); } loadOnMain() { diff --git a/src/renderer/bootstrap.tsx b/src/renderer/bootstrap.tsx index 52a92b7c11..cfadb5c379 100644 --- a/src/renderer/bootstrap.tsx +++ b/src/renderer/bootstrap.tsx @@ -14,6 +14,7 @@ import { clusterStore } from "../common/cluster-store"; import { i18nStore } from "./i18n"; import { themeStore } from "./theme.store"; import { extensionsStore } from "../extensions/extensions-store"; +import { extensionLoader } from "../extensions/extension-loader"; type AppComponent = React.ComponentType & { init?(): Promise; @@ -30,6 +31,8 @@ export async function bootstrap(App: AppComponent) { const rootElem = document.getElementById("app") rootElem.classList.toggle("is-mac", isMac); + extensionLoader.init() + // preload common stores await Promise.all([ userStore.load(),