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

View File

@ -88,13 +88,13 @@ export class LensExtension {
} }
try { 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(); await this.onActivate();
this.isEnabled = true; this.isEnabled = true;
this[Disposers].push(...await register(this)); this[Disposers].push(...await register(this));
logger.info(`[EXTENSION]: enabled ${this.name}@${this.version}`); 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) { } catch (error) {
logger.error(`[EXTENSION]: failed to activate ${this.name}@${this.version}: ${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 { installDeveloperTools } from "./developer-tools";
import { LensProtocolRouterMain } from "./protocol-handler"; import { LensProtocolRouterMain } from "./protocol-handler";
import { disposer, getAppVersion, getAppVersionFromProxyServer, storedKubeConfigFolder } from "../common/utils"; 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 { startUpdateChecking } from "./app-updater";
import { IpcRendererNavigationEvents } from "../renderer/navigation/events"; import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
import { pushCatalogToRenderer } from "./catalog-pusher"; import { pushCatalogToRenderer } from "./catalog-pusher";
@ -284,15 +284,15 @@ app.on("ready", async () => {
onCloseCleanup.push(pushCatalogToRenderer(catalogEntityRegistry)); onCloseCleanup.push(pushCatalogToRenderer(catalogEntityRegistry));
await ensureDir(storedKubeConfigFolder()); await ensureDir(storedKubeConfigFolder());
KubeconfigSyncManager.getInstance().startSync(); KubeconfigSyncManager.getInstance().startSync();
logger.info(`STARTUP LENS Init extensions start ${new Date()}`);
await initExtensions();
logger.info(`STARTUP LENS Init extensions end ${new Date()}`);
startUpdateChecking(); startUpdateChecking();
LensProtocolRouterMain.getInstance().rendererLoaded = true; LensProtocolRouterMain.getInstance().rendererLoaded = true;
console.log(`STARTUP LENS EXTENSIONS:LOADED ${new Date()}`); 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(() => { setTimeout(() => {
appEventBus.emit({ name: "service", action: "start" }); appEventBus.emit({ name: "service", action: "start" });
}, 1000); }, 1000);

View File

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

View File

@ -49,7 +49,10 @@ export class RootFrame extends React.Component {
static async init(rootElem: HTMLElement) { static async init(rootElem: HTMLElement) {
catalogEntityRegistry.init(); 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(); LensProtocolRouterRenderer.createInstance().init();
bindProtocolAddRouteHandlers(); bindProtocolAddRouteHandlers();