Make Inject-component usable in both LensApp and "App"

Note: this will need some rehaul, as current design with "bootstrap" and iframe make single root for injectables somewhat challenging.

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Mikko AspialaandJanne Savolainen authored and Janne Savolainen committed 2021-11-26 07:44:20 +02:00
1 parent c4c4bc5845
commit 3bc01dc50f
2 files changed
+54 -47

No files matched your search

+20 -8
View File
@@ -50,6 +50,9 @@ import { SentryInit } from "../common/sentry";
import { TerminalStore } from "./components/dock/terminal.store";
import { AppPaths } from "../common/app-paths";
import { registerCustomThemes } from "./components/monaco-editor";
import { getDi } from "./components/getDi";
import { DiContextProvider } from "@ogre-tools/injectable-react";
import type { IDependencyInjectionContainer } from "@ogre-tools/injectable";
if (process.isMainFrame) {
SentryInit();
@@ -73,7 +76,7 @@ type AppComponent = React.ComponentType & {
init(rootElem: HTMLElement): Promise<void>;
};
export async function bootstrap(comp: () => Promise<AppComponent>) {
export async function bootstrap(comp: () => Promise<AppComponent>, di: IDependencyInjectionContainer) {
const rootElem = document.getElementById("app");
const logPrefix = `[BOOTSTRAP-${process.isMainFrame ? "ROOT" : "CLUSTER"}-FRAME]:`;
@@ -147,17 +150,26 @@ export async function bootstrap(comp: () => Promise<AppComponent>) {
await App.init(rootElem);
render(<>
{isMac && <div id="draggable-top" />}
{DefaultProps(App)}
</>, rootElem);
render(
<DiContextProvider value={{ di }}>
{isMac && <div id="draggable-top" />}
{DefaultProps(App)}
</DiContextProvider>,
rootElem,
);
}
const di = getDi();
// run
bootstrap(
async () => process.isMainFrame
? (await import("./root-frame")).RootFrame
: (await import("./cluster-frame")).ClusterFrame,
async () =>
process.isMainFrame
? (await import("./root-frame")).RootFrame
: (await import("./cluster-frame")).ClusterFrame,
di,
);