mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
simplify ExtensionLoader
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
2d51af6be3
commit
cdc0af520d
@ -23,31 +23,6 @@ export class ExtensionLoader {
|
|||||||
@observable isLoaded = false;
|
@observable isLoaded = false;
|
||||||
whenLoaded = when(() => this.isLoaded);
|
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<LensExtensionId, InstalledExtension> {
|
@computed get userExtensions(): Map<LensExtensionId, InstalledExtension> {
|
||||||
const extensions = this.extensions.toJS();
|
const extensions = this.extensions.toJS();
|
||||||
extensions.forEach((ext, extId) => {
|
extensions.forEach((ext, extId) => {
|
||||||
@ -59,11 +34,45 @@ export class ExtensionLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async init(extensions: Map<LensExtensionId, InstalledExtension>) {
|
async init(extensions?: Map<LensExtensionId, InstalledExtension>) {
|
||||||
this.extensions.replace(extensions);
|
if (extensions) {
|
||||||
|
this.extensions.replace(extensions);
|
||||||
|
}
|
||||||
|
if (ipcRenderer) {
|
||||||
|
this.initRenderer()
|
||||||
|
} else {
|
||||||
|
this.initMain()
|
||||||
|
}
|
||||||
|
extensionsStore.manageState(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async initMain() {
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
this.loadOnMain();
|
this.loadOnMain();
|
||||||
this.broadcastExtensions();
|
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() {
|
loadOnMain() {
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import { clusterStore } from "../common/cluster-store";
|
|||||||
import { i18nStore } from "./i18n";
|
import { i18nStore } from "./i18n";
|
||||||
import { themeStore } from "./theme.store";
|
import { themeStore } from "./theme.store";
|
||||||
import { extensionsStore } from "../extensions/extensions-store";
|
import { extensionsStore } from "../extensions/extensions-store";
|
||||||
|
import { extensionLoader } from "../extensions/extension-loader";
|
||||||
|
|
||||||
type AppComponent = React.ComponentType & {
|
type AppComponent = React.ComponentType & {
|
||||||
init?(): Promise<void>;
|
init?(): Promise<void>;
|
||||||
@ -30,6 +31,8 @@ export async function bootstrap(App: AppComponent) {
|
|||||||
const rootElem = document.getElementById("app")
|
const rootElem = document.getElementById("app")
|
||||||
rootElem.classList.toggle("is-mac", isMac);
|
rootElem.classList.toggle("is-mac", isMac);
|
||||||
|
|
||||||
|
extensionLoader.init()
|
||||||
|
|
||||||
// preload common stores
|
// preload common stores
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
userStore.load(),
|
userStore.load(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user