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);
|
view.sendToFrame([frameInfo.processId, frameInfo.frameId], channel, ...args);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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;
|
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
|
// Transform userExtensions to a state object for storing into ExtensionsStore
|
||||||
@computed get storeState() {
|
@computed get storeState() {
|
||||||
return Object.fromEntries(
|
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 }));
|
.catch(error => logger.error(`${LensProtocolRouterMain.LoggingPrefix}: an error occured`, { error, rawUrl: arg }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
windowManager?.ensureMainWindow();
|
windowManager?.ensureMainWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -127,6 +127,16 @@ app.on("ready", async () => {
|
|||||||
extensionLoader.init();
|
extensionLoader.init();
|
||||||
extensionDiscovery.init();
|
extensionDiscovery.init();
|
||||||
windowManager = WindowManager.getInstance<WindowManager>(proxyPort);
|
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
|
// call after windowManager to see splash earlier
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import * as proto from "../../common/protocol-handler";
|
|||||||
import Url from "url-parse";
|
import Url from "url-parse";
|
||||||
import { LensExtension } from "../../extensions/lens-extension";
|
import { LensExtension } from "../../extensions/lens-extension";
|
||||||
import { broadcastMessage } from "../../common/ipc";
|
import { broadcastMessage } from "../../common/ipc";
|
||||||
|
import { observable, when } from "mobx";
|
||||||
|
|
||||||
export interface FallbackHandler {
|
export interface FallbackHandler {
|
||||||
(name: string): Promise<boolean>;
|
(name: string): Promise<boolean>;
|
||||||
@ -11,6 +12,9 @@ export interface FallbackHandler {
|
|||||||
export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
||||||
private missingExtensionHandlers: FallbackHandler[] = [];
|
private missingExtensionHandlers: FallbackHandler[] = [];
|
||||||
|
|
||||||
|
@observable rendererLoaded = false;
|
||||||
|
@observable extensionsLoaded = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the most specific registered handler, if it exists, and invoke it.
|
* Find the most specific registered handler, if it exists, and invoke it.
|
||||||
*
|
*
|
||||||
@ -31,6 +35,8 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
|||||||
case "app":
|
case "app":
|
||||||
return this._routeToInternal(url);
|
return this._routeToInternal(url);
|
||||||
case "extension":
|
case "extension":
|
||||||
|
await when(() => this.extensionsLoaded);
|
||||||
|
|
||||||
return this._routeToExtension(url);
|
return this._routeToExtension(url);
|
||||||
default:
|
default:
|
||||||
throw new proto.RoutingError(proto.RoutingErrorType.INVALID_HOST, url);
|
throw new proto.RoutingError(proto.RoutingErrorType.INVALID_HOST, url);
|
||||||
@ -69,12 +75,14 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _routeToInternal(url: Url): void {
|
protected async _routeToInternal(url: Url): Promise<void> {
|
||||||
const rawUrl = url.toString(); // for sending to renderer
|
const rawUrl = url.toString(); // for sending to renderer
|
||||||
|
|
||||||
super._routeToInternal(url);
|
super._routeToInternal(url);
|
||||||
|
|
||||||
broadcastMessage(proto.ProtocolHandlerInternal, rawUrl);
|
await when(() => this.rendererLoaded);
|
||||||
|
|
||||||
|
return broadcastMessage(proto.ProtocolHandlerInternal, rawUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _routeToExtension(url: Url): Promise<void> {
|
protected async _routeToExtension(url: Url): Promise<void> {
|
||||||
@ -88,8 +96,9 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter {
|
|||||||
* argument.
|
* argument.
|
||||||
*/
|
*/
|
||||||
await super._routeToExtension(new Url(url.toString(), true));
|
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 type { ClusterId } from "../common/cluster-store";
|
||||||
import { observable } from "mobx";
|
import { observable, when } from "mobx";
|
||||||
import { app, BrowserWindow, dialog, shell, webContents } from "electron";
|
import { app, BrowserWindow, dialog, shell, webContents } from "electron";
|
||||||
import windowStateKeeper from "electron-window-state";
|
import windowStateKeeper from "electron-window-state";
|
||||||
import { appEventBus } from "../common/event-bus";
|
import { appEventBus } from "../common/event-bus";
|
||||||
@ -15,6 +15,9 @@ export class WindowManager extends Singleton {
|
|||||||
protected windowState: windowStateKeeper.State;
|
protected windowState: windowStateKeeper.State;
|
||||||
protected disposers: Record<string, Function> = {};
|
protected disposers: Record<string, Function> = {};
|
||||||
|
|
||||||
|
@observable mainViewInitiallyLoaded = false;
|
||||||
|
whenLoaded = when(() => this.mainViewInitiallyLoaded);
|
||||||
|
|
||||||
@observable activeClusterId: ClusterId;
|
@observable activeClusterId: ClusterId;
|
||||||
|
|
||||||
constructor(protected proxyPort: number) {
|
constructor(protected proxyPort: number) {
|
||||||
@ -91,6 +94,7 @@ export class WindowManager extends Singleton {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
appEventBus.emit({ name: "app", action: "start" });
|
appEventBus.emit({ name: "app", action: "start" });
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
this.mainViewInitiallyLoaded = true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
dialog.showErrorBox("ERROR!", err.toString());
|
dialog.showErrorBox("ERROR!", err.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user