mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
add waiting for renderer and extensions to load before broadcasting handlers
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
7ea0a7fa4b
commit
8e9a0cc4b7
@ -47,7 +47,7 @@ export async function broadcastMessage(channel: string, ...args: any[]) {
|
||||
view.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("[IPC]: failed to send IPC message", { error });
|
||||
logger.error("[IPC]: failed to send IPC message", { error: String(error) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,6 +66,16 @@ export class ExtensionLoader {
|
||||
return extensions;
|
||||
}
|
||||
|
||||
getExtensionByName(name: string): LensExtension | null {
|
||||
for (const [, val] of this.instances) {
|
||||
if (val.name === name) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Transform userExtensions to a state object for storing into ExtensionsStore
|
||||
@computed get storeState() {
|
||||
return Object.fromEntries(
|
||||
|
||||
@ -73,7 +73,7 @@ app.on("second-instance", (event, argv) => {
|
||||
.catch(error => logger.error(`${LensProtocolRouterMain.LoggingPrefix}: an error occured`, { error, rawUrl: arg }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
windowManager?.ensureMainWindow();
|
||||
});
|
||||
|
||||
@ -127,6 +127,16 @@ app.on("ready", async () => {
|
||||
extensionLoader.init();
|
||||
extensionDiscovery.init();
|
||||
windowManager = WindowManager.getInstance<WindowManager>(proxyPort);
|
||||
windowManager.whenLoaded.then(() => {
|
||||
LensProtocolRouterMain
|
||||
.getInstance<LensProtocolRouterMain>()
|
||||
.rendererLoaded = true;
|
||||
});
|
||||
extensionLoader.whenLoaded.then(() => {
|
||||
LensProtocolRouterMain
|
||||
.getInstance<LensProtocolRouterMain>()
|
||||
.extensionsLoaded = true;
|
||||
});
|
||||
|
||||
// call after windowManager to see splash earlier
|
||||
try {
|
||||
|
||||
@ -3,6 +3,7 @@ import * as proto from "../../common/protocol-handler";
|
||||
import Url from "url-parse";
|
||||
import { LensExtension } from "../../extensions/lens-extension";
|
||||
import { broadcastMessage } from "../../common/ipc";
|
||||
import { observable, when } from "mobx";
|
||||
|
||||
export interface FallbackHandler {
|
||||
(name: string): Promise<boolean>;
|
||||
@ -11,6 +12,9 @@ export interface FallbackHandler {
|
||||
export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
||||
private missingExtensionHandlers: FallbackHandler[] = [];
|
||||
|
||||
@observable rendererLoaded = false;
|
||||
@observable extensionsLoaded = false;
|
||||
|
||||
/**
|
||||
* Find the most specific registered handler, if it exists, and invoke it.
|
||||
*
|
||||
@ -31,6 +35,8 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
||||
case "app":
|
||||
return this._routeToInternal(url);
|
||||
case "extension":
|
||||
await when(() => this.extensionsLoaded);
|
||||
|
||||
return this._routeToExtension(url);
|
||||
default:
|
||||
throw new proto.RoutingError(proto.RoutingErrorType.INVALID_HOST, url);
|
||||
@ -69,12 +75,14 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
||||
return "";
|
||||
}
|
||||
|
||||
protected _routeToInternal(url: Url): void {
|
||||
protected async _routeToInternal(url: Url): Promise<void> {
|
||||
const rawUrl = url.toString(); // for sending to renderer
|
||||
|
||||
super._routeToInternal(url);
|
||||
|
||||
broadcastMessage(proto.ProtocolHandlerInternal, rawUrl);
|
||||
await when(() => this.rendererLoaded);
|
||||
|
||||
return broadcastMessage(proto.ProtocolHandlerInternal, rawUrl);
|
||||
}
|
||||
|
||||
protected async _routeToExtension(url: Url): Promise<void> {
|
||||
@ -88,8 +96,9 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
||||
* argument.
|
||||
*/
|
||||
await super._routeToExtension(new Url(url.toString(), true));
|
||||
await when(() => this.rendererLoaded);
|
||||
|
||||
broadcastMessage(proto.ProtocolHandlerExtension, rawUrl);
|
||||
return broadcastMessage(proto.ProtocolHandlerExtension, rawUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { ClusterId } from "../common/cluster-store";
|
||||
import { observable } from "mobx";
|
||||
import { observable, when } from "mobx";
|
||||
import { app, BrowserWindow, dialog, shell, webContents } from "electron";
|
||||
import windowStateKeeper from "electron-window-state";
|
||||
import { appEventBus } from "../common/event-bus";
|
||||
@ -15,6 +15,9 @@ export class WindowManager extends Singleton {
|
||||
protected windowState: windowStateKeeper.State;
|
||||
protected disposers: Record<string, Function> = {};
|
||||
|
||||
@observable mainViewInitiallyLoaded = false;
|
||||
whenLoaded = when(() => this.mainViewInitiallyLoaded);
|
||||
|
||||
@observable activeClusterId: ClusterId;
|
||||
|
||||
constructor(protected proxyPort: number) {
|
||||
@ -91,6 +94,7 @@ export class WindowManager extends Singleton {
|
||||
setTimeout(() => {
|
||||
appEventBus.emit({ name: "app", action: "start" });
|
||||
}, 1000);
|
||||
this.mainViewInitiallyLoaded = true;
|
||||
} catch (err) {
|
||||
dialog.showErrorBox("ERROR!", err.toString());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user