From 8c6999bd60e2d4257c032db0e119244c7a19c849 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 19 Sep 2022 10:54:15 -0400 Subject: [PATCH] Make UserStore loading seperate from creation to fix initialization timing errors Signed-off-by: Sebastian Malton --- .../initialize-sentry-reporting.injectable.ts | 4 +--- src/common/user-store/user-store.ts | 1 - src/main/stores/init-user-store.injectable.ts | 23 +++++++++++++++++++ src/renderer/bootstrap.tsx | 4 ---- .../stores/init-user-store.injectable.ts | 23 +++++++++++++++++++ 5 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/main/stores/init-user-store.injectable.ts create mode 100644 src/renderer/stores/init-user-store.injectable.ts diff --git a/src/common/error-reporting/initialize-sentry-reporting.injectable.ts b/src/common/error-reporting/initialize-sentry-reporting.injectable.ts index d34005f374..778f959739 100644 --- a/src/common/error-reporting/initialize-sentry-reporting.injectable.ts +++ b/src/common/error-reporting/initialize-sentry-reporting.injectable.ts @@ -20,6 +20,7 @@ const initializeSentryReportingWithInjectable = getInjectable({ instantiate: (di): InitializeSentryReportingWith => { const sentryDataSourceName = di.inject(sentryDataSourceNameInjectable); const isProduction = di.inject(isProductionInjectable); + const userStore = di.inject(userStoreInjectable); if (!sentryDataSourceName) { return () => {}; @@ -27,9 +28,6 @@ const initializeSentryReportingWithInjectable = getInjectable({ return (initSentry) => initSentry({ beforeSend: (event) => { - // TODO: remove loading from userStoreInjectable so that this can be moved out - const userStore = di.inject(userStoreInjectable); - if (userStore.allowErrorReporting) { return event; } diff --git a/src/common/user-store/user-store.ts b/src/common/user-store/user-store.ts index 7457548436..6c995996bf 100644 --- a/src/common/user-store/user-store.ts +++ b/src/common/user-store/user-store.ts @@ -34,7 +34,6 @@ export class UserStore extends BaseStore /* implements UserStore }); makeObservable(this); - this.load(); } @observable lastSeenAppVersion = "0.0.0"; diff --git a/src/main/stores/init-user-store.injectable.ts b/src/main/stores/init-user-store.injectable.ts new file mode 100644 index 0000000000..c7d088a21b --- /dev/null +++ b/src/main/stores/init-user-store.injectable.ts @@ -0,0 +1,23 @@ +/** + * 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 userStoreInjectable from "../../common/user-store/user-store.injectable"; +import { beforeApplicationIsLoadingInjectionToken } from "../start-main-application/runnable-tokens/before-application-is-loading-injection-token"; +import initDefaultUpdateChannelInjectableInjectable from "../vars/default-update-channel/init.injectable"; + +const initUserStoreInjectable = getInjectable({ + id: "init-user-store", + instantiate: (di) => { + const userStore = di.inject(userStoreInjectable); + + return { + run: () => userStore.load(), + runAfter: di.inject(initDefaultUpdateChannelInjectableInjectable), + }; + }, + injectionToken: beforeApplicationIsLoadingInjectionToken, +}); + +export default initUserStoreInjectable; diff --git a/src/renderer/bootstrap.tsx b/src/renderer/bootstrap.tsx index 2ebd849805..53e2913583 100644 --- a/src/renderer/bootstrap.tsx +++ b/src/renderer/bootstrap.tsx @@ -28,7 +28,6 @@ import extensionLoaderInjectable from "../extensions/extension-loader/extension- import extensionDiscoveryInjectable from "../extensions/extension-discovery/extension-discovery.injectable"; import extensionInstallationStateStoreInjectable from "../extensions/extension-installation-state-store/extension-installation-state-store.injectable"; import clusterStoreInjectable from "../common/cluster-store/cluster-store.injectable"; -import userStoreInjectable from "../common/user-store/user-store.injectable"; import initRootFrameInjectable from "./frames/root-frame/init-root-frame/init-root-frame.injectable"; import initClusterFrameInjectable from "./frames/cluster-frame/init-cluster-frame/init-cluster-frame.injectable"; import commandOverlayInjectable from "./components/command-palette/command-overlay.injectable"; @@ -92,9 +91,6 @@ export async function bootstrap(di: DiContainer) { */ di.inject(autoRegistrationInjectable); - // TODO: Remove temporal dependencies to make timing of initialization not important - di.inject(userStoreInjectable); - await attachChromeDebugger(); rootElem.classList.toggle("is-mac", isMac); diff --git a/src/renderer/stores/init-user-store.injectable.ts b/src/renderer/stores/init-user-store.injectable.ts new file mode 100644 index 0000000000..36f2caf015 --- /dev/null +++ b/src/renderer/stores/init-user-store.injectable.ts @@ -0,0 +1,23 @@ +/** + * 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 userStoreInjectable from "../../common/user-store/user-store.injectable"; +import { beforeFrameStartsInjectionToken } from "../before-frame-starts/before-frame-starts-injection-token"; +import initDefaultUpdateChannelInjectableInjectable from "../vars/default-update-channel/init.injectable"; + +const initUserStoreInjectable = getInjectable({ + id: "init-user-store", + instantiate: (di) => { + const userStore = di.inject(userStoreInjectable); + + return { + run: () => userStore.load(), + runAfter: di.inject(initDefaultUpdateChannelInjectableInjectable), + }; + }, + injectionToken: beforeFrameStartsInjectionToken, +}); + +export default initUserStoreInjectable;