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

Move last main frame into into runnable

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-02-21 12:25:41 -05:00
parent 1dd172eafe
commit 4561a59906
4 changed files with 37 additions and 19 deletions

View File

@ -10,7 +10,6 @@ import { render } from "react-dom";
import { DefaultProps } from "./mui-base-theme";
import { DiContextProvider } from "@ogre-tools/injectable-react";
import type { DiContainer } from "@ogre-tools/injectable";
import initRootFrameInjectable from "./frames/root-frame/init-root-frame.injectable";
import { Router } from "react-router";
import historyInjectable from "./navigation/history.injectable";
import startFrameInjectable from "./start-frame/start-frame.injectable";
@ -23,20 +22,6 @@ export async function bootstrap(di: DiContainer) {
await startFrame();
try {
// TODO: Introduce proper architectural boundaries between root and cluster iframes
if (process.isMainFrame) {
const initRootFrame = di.inject(initRootFrameInjectable);
await initRootFrame();
}
} catch (error) {
console.error(`[BOOTSTRAP]: view initialization error: ${error}`, {
origin: location.href,
isTopFrameView: process.isMainFrame,
});
}
const App = process.isMainFrame
? RootFrame
: ClusterFrame;

View File

@ -0,0 +1,10 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
import { noop } from "../../utils";
import handleOnMainFrameCloseInjectable from "./on-main-frame-close.injectable";
export default getGlobalOverride(handleOnMainFrameCloseInjectable, () => noop);

View File

@ -6,19 +6,20 @@ import { getInjectable } from "@ogre-tools/injectable";
import loggerInjectable from "../../../common/logger.injectable";
import unmountRootComponentInjectable from "../../window/unmount-root-component.injectable";
const initRootFrameInjectable = getInjectable({
id: "init-root-frame",
const handleOnMainFrameCloseInjectable = getInjectable({
id: "handle-on-main-frame-close",
instantiate: (di) => {
const logger = di.inject(loggerInjectable);
const unmountRootComponent = di.inject(unmountRootComponentInjectable);
return async () => {
return () => {
window.addEventListener("beforeunload", () => {
logger.info("[ROOT-FRAME]: Unload app");
unmountRootComponent();
});
};
},
causesSideEffects: true,
});
export default initRootFrameInjectable;
export default handleOnMainFrameCloseInjectable;

View File

@ -0,0 +1,22 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { beforeMainFrameStartsSecondInjectionToken } from "../../before-frame-starts/tokens";
import handleOnMainFrameCloseInjectable from "./on-main-frame-close.injectable";
const setupUnloadEventHandlerInjectable = getInjectable({
id: "setup-unload-event-handler",
instantiate: (di) => ({
id: "setup-unload-event-handler",
run: () => {
const handleOnMainFrameClose = di.inject(handleOnMainFrameCloseInjectable);
handleOnMainFrameClose();
},
}),
injectionToken: beforeMainFrameStartsSecondInjectionToken,
});
export default setupUnloadEventHandlerInjectable;