1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

load extensions before showing main window

This commit is contained in:
Juho Heikka 2021-12-14 16:29:14 +02:00
parent 72f975a258
commit 99294188a6
5 changed files with 27 additions and 20 deletions

View File

@ -48,7 +48,6 @@ const logModule = "[EXTENSIONS-LOADER]";
export class ExtensionLoader extends Singleton {
protected extensions = observable.map<LensExtensionId, InstalledExtension>();
protected instances = observable.map<LensExtensionId, LensExtension>();
/**
* This is the set of extensions that don't come with either
* - Main.LensExtension when running in the main process
@ -273,9 +272,9 @@ export class ExtensionLoader extends Singleton {
});
}
loadOnClusterManagerRenderer() {
async loadOnClusterManagerRenderer() {
logger.debug(`${logModule}: load on main renderer (cluster manager)`);
this.autoInitExtensions(async (extension: LensRendererExtension) => {
await this.autoInitExtensions(async (extension: LensRendererExtension) => {
const removeItems = [
registries.GlobalPageRegistry.getInstance().add(extension.globalPages, extension),
registries.AppPreferenceRegistry.getInstance().add(extension.appPreferences),
@ -298,6 +297,7 @@ export class ExtensionLoader extends Singleton {
return removeItems;
});
console.log(`STARTUP ExtensionLoader:loadOnClusterManagerRenderer done ${new Date()} ${new Date().getTime()}`);
}
loadOnClusterRenderer() {
@ -331,8 +331,11 @@ export class ExtensionLoader extends Singleton {
});
}
protected autoInitExtensions(register: (ext: LensExtension) => Promise<Disposer[]>) {
return reaction(() => this.toJSON(), async installedExtensions => {
protected async autoInitExtensions(register: (ext: LensExtension) => Promise<Disposer[]>) {
console.log(`STARTUP ${new Date()} ExtensionLoader::autoInitExtensions`);
const enablePromises: Promise<void>[] = [];
reaction(() => this.toJSON(), async installedExtensions => {
for (const [extId, extension] of installedExtensions) {
const alreadyInit = this.instances.has(extId) || this.nonInstancesByName.has(extension.manifest.name);
@ -347,9 +350,10 @@ export class ExtensionLoader extends Singleton {
const instance = new LensExtensionClass(extension);
await instance.enable(register);
console.log("STARTUP await instance.enable(register) returned");
this.instances.set(extId, instance);
enablePromises.push(instance.enable(register).catch((err) => {
logger.error(`${logModule}: failed to enable`, { ext: extension, err });
}));
} catch (err) {
logger.error(`${logModule}: activation extension error`, { ext: extension, err });
}
@ -360,6 +364,8 @@ export class ExtensionLoader extends Singleton {
}, {
fireImmediately: true,
});
return Promise.all(enablePromises);
}
protected requireExtension(extension: InstalledExtension): LensExtensionConstructor | null {

View File

@ -88,13 +88,13 @@ export class LensExtension {
}
try {
logger.info(`STARTUP LENS Extension enable ${new Date()}`);
logger.info(`STARTUP LENS ${this.name} Extension enable ${new Date()} ${new Date().getTime()}`);
await this.onActivate();
this.isEnabled = true;
this[Disposers].push(...await register(this));
logger.info(`[EXTENSION]: enabled ${this.name}@${this.version}`);
logger.info(`STARTUP LENS Extension enabled ${new Date()}`);
logger.info(`STARTUP LENS Extension ${this.name} enabled ${new Date()} ${new Date().getTime()}`);
} catch (error) {
logger.error(`[EXTENSION]: failed to activate ${this.name}@${this.version}: ${error}`);
}

View File

@ -42,7 +42,7 @@ import type { LensExtensionId } from "../extensions/lens-extension";
import { installDeveloperTools } from "./developer-tools";
import { LensProtocolRouterMain } from "./protocol-handler";
import { disposer, getAppVersion, getAppVersionFromProxyServer, storedKubeConfigFolder } from "../common/utils";
import { bindBroadcastHandlers, broadcastMessage, ipcMainOn } from "../common/ipc";
import { bindBroadcastHandlers, ipcMainOn } from "../common/ipc";
import { startUpdateChecking } from "./app-updater";
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
import { pushCatalogToRenderer } from "./catalog-pusher";
@ -284,15 +284,15 @@ app.on("ready", async () => {
onCloseCleanup.push(pushCatalogToRenderer(catalogEntityRegistry));
await ensureDir(storedKubeConfigFolder());
KubeconfigSyncManager.getInstance().startSync();
logger.info(`STARTUP LENS Init extensions start ${new Date()}`);
await initExtensions();
logger.info(`STARTUP LENS Init extensions end ${new Date()}`);
startUpdateChecking();
LensProtocolRouterMain.getInstance().rendererLoaded = true;
console.log(`STARTUP LENS EXTENSIONS:LOADED ${new Date()}`);
broadcastMessage("EXTENSIONS:LOADED");
});
logger.info(`STARTUP LENS Init extensions start ${new Date()}`);
await initExtensions();
logger.info(`STARTUP LENS Init extensions end ${new Date()}`);
setTimeout(() => {
appEventBus.emit({ name: "service", action: "start" });
}, 1000);

View File

@ -177,7 +177,7 @@ export class WindowManager extends Singleton {
if (!this.mainWindow) {
viewHasLoaded = new Promise<void>(resolve => {
ipcMain.once("EXTENSIONS:LOADED", () => {
logger.info(`STARTUP LENS EXTENSIONS:LOADED: ${showSplash} ${new Date()}`);
console.log(`STARTUP GOT EXTENSIONS:LOADED ${new Date()} ${new Date().getTime()}`);
resolve();
} );
});
@ -186,11 +186,9 @@ export class WindowManager extends Singleton {
try {
await viewHasLoaded;
await delay(50); // wait just a bit longer to let the first round of rendering happen
logger.info("[WINDOW-MANAGER]: Main window has reported that it has loaded");
logger.info(`STARTUP LENS view has loaded let's show mainWindow ${new Date()}`);
await delay(100); // wait just a bit longer to let the first round of rendering happen
console.log(`STARTUP this.mainWindow.show ${new Date()} ${new Date().getTime()}`);
this.mainWindow.show();
logger.info(`STARTUP LENS let's close the splashWindow ${new Date()}`);
this.splashWindow?.close();
this.splashWindow = undefined;
setTimeout(() => {

View File

@ -49,7 +49,10 @@ export class RootFrame extends React.Component {
static async init(rootElem: HTMLElement) {
catalogEntityRegistry.init();
ExtensionLoader.getInstance().loadOnClusterManagerRenderer();
console.log(`STARTUP ExtensionLoader::init::loadOnClusterManagerRenderer ${new Date()} ${new Date().getTime()}`);
await ExtensionLoader.getInstance().loadOnClusterManagerRenderer();
console.log(`STARTUP ExtensionLoader::init::loadOnClusterManagerRenderer done ${new Date()} ${new Date().getTime()}`);
ipcRenderer.send("EXTENSIONS:LOADED");
LensProtocolRouterRenderer.createInstance().init();
bindProtocolAddRouteHandlers();