mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Convert runMany and runManySync to use injectManyWithMeta + move to seperate package (#7244)
* Convert runMany and runManySync to use injectManyWithMeta Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup type errors due to new Runnable requirements Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add documentation for verifyRunnablesAreDAG Signed-off-by: Sebastian Malton <sebastian@malton.name> * Simplify convertToWithIdWith Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move all utility functions to separate package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move testing utilities to separate package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move run-many and run-many-sync to separate package Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace all internal uses of utilities with new packages Signed-off-by: Sebastian Malton <sebastian@malton.name> * Use new @k8slens/run-many package in core Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add dep to open-lens Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup uses of @k8slens/test-utils Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup getGlobalOverride Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move tests to new package too Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup uses of AsyncResult and autoBind Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup remaining import issues Signed-off-by: Sebastian Malton <sebastian@malton.name> * Finial fixups to fix build Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Revert moving "testUsingFakeTime" to separate package - This fixes tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix integration tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix unit test failing due to spelling fix Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
ad9bafe2a5
commit
2789bcebcb
754 files changed
+2715
-2752
No files matched your search
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { kebabCase } from "lodash";
|
||||
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import electronAppInjectable from "./electron-app.injectable";
|
||||
|
||||
export default getGlobalOverride(electronAppInjectable, () => {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import electronDialogInjectable from "./electron-dialog.injectable";
|
||||
|
||||
export default getGlobalOverride(electronDialogInjectable, () => ({
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import EventEmitter from "events";
|
||||
import { getGlobalOverride } from "../../../common/test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import nativeThemeInjectable from "./native-theme.injectable";
|
||||
|
||||
export default getGlobalOverride(nativeThemeInjectable, () => Object.assign(new EventEmitter(), {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverrideForFunction } from "../../../common/test-utils/get-global-override-for-function";
|
||||
import { getGlobalOverrideForFunction } from "@k8slens/test-utils";
|
||||
import showOpenDialogInjectable from "./show-open-dialog.injectable";
|
||||
|
||||
export default getGlobalOverrideForFunction(showOpenDialogInjectable);
|
||||
@@ -3,20 +3,21 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
|
||||
import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/phases";
|
||||
import lensProtocolRouterMainInjectable from "../../protocol-handler/lens-protocol-router-main/lens-protocol-router-main.injectable";
|
||||
|
||||
const cleanUpDeepLinkingInjectable = getInjectable({
|
||||
id: "clean-up-deep-linking",
|
||||
|
||||
instantiate: (di) => {
|
||||
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const lensProtocolRouterMain = di.inject(lensProtocolRouterMainInjectable);
|
||||
|
||||
return {
|
||||
id: "clean-up-deep-linking",
|
||||
run: () => void lensProtocolRouterMain.cleanup(),
|
||||
};
|
||||
},
|
||||
lensProtocolRouterMain.cleanup();
|
||||
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeQuitOfBackEndInjectionToken,
|
||||
});
|
||||
|
||||
+12
-16
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeQuitOfFrontEndInjectionToken } from "../../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
|
||||
import { beforeQuitOfFrontEndInjectionToken } from "../../../start-main-application/runnable-tokens/phases";
|
||||
import electronAppInjectable from "../../electron-app.injectable";
|
||||
import { isEmpty } from "lodash/fp";
|
||||
import getVisibleWindowsInjectable from "../../../start-main-application/lens-window/get-visible-windows.injectable";
|
||||
@@ -11,23 +11,19 @@ import getVisibleWindowsInjectable from "../../../start-main-application/lens-wi
|
||||
const hideDockForLastClosedWindowInjectable = getInjectable({
|
||||
id: "hide-dock-when-there-are-no-windows",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const getVisibleWindows = di.inject(getVisibleWindowsInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const getVisibleWindows = di.inject(getVisibleWindowsInjectable);
|
||||
const visibleWindows = getVisibleWindows();
|
||||
|
||||
return {
|
||||
id: "hide-dock-when-there-are-no-windows",
|
||||
run: () => {
|
||||
const visibleWindows = getVisibleWindows();
|
||||
if (isEmpty(visibleWindows)) {
|
||||
app.dock?.hide();
|
||||
}
|
||||
|
||||
if (isEmpty(visibleWindows)) {
|
||||
app.dock?.hide();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeQuitOfFrontEndInjectionToken,
|
||||
});
|
||||
|
||||
+7
-10
@@ -4,21 +4,18 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import electronAppInjectable from "../../electron-app.injectable";
|
||||
import { afterWindowIsOpenedInjectionToken } from "../../../start-main-application/runnable-tokens/after-window-is-opened-injection-token";
|
||||
import { afterWindowIsOpenedInjectionToken } from "../../../start-main-application/runnable-tokens/phases";
|
||||
|
||||
const showDockForFirstOpenedWindowInjectable = getInjectable({
|
||||
id: "show-dock-for-first-opened-window",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
|
||||
return {
|
||||
id: "show-dock-for-first-opened-window",
|
||||
run: () => {
|
||||
app.dock?.show();
|
||||
},
|
||||
};
|
||||
},
|
||||
app.dock?.show();
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: afterWindowIsOpenedInjectionToken,
|
||||
});
|
||||
|
||||
+10
-13
@@ -10,21 +10,18 @@ import exitAppInjectable from "../features/exit-app.injectable";
|
||||
const enforceSingleApplicationInstanceInjectable = getInjectable({
|
||||
id: "enforce-single-application-instance",
|
||||
|
||||
instantiate: (di) => {
|
||||
const requestSingleInstanceLock = di.inject(requestSingleInstanceLockInjectable);
|
||||
const exitApp = di.inject(exitAppInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const requestSingleInstanceLock = di.inject(requestSingleInstanceLockInjectable);
|
||||
const exitApp = di.inject(exitAppInjectable);
|
||||
|
||||
return {
|
||||
id: "enforce-single-application-instance",
|
||||
run: () => {
|
||||
if (!requestSingleInstanceLock()) {
|
||||
exitApp();
|
||||
}
|
||||
if (!requestSingleInstanceLock()) {
|
||||
exitApp();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
@@ -10,19 +10,16 @@ import electronAppInjectable from "../electron-app.injectable";
|
||||
const setupApplicationNameInjectable = getInjectable({
|
||||
id: "setup-application-name",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const appName = di.inject(appNameInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const appName = di.inject(appNameInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-application-name",
|
||||
run: () => {
|
||||
app.setName(appName);
|
||||
app.setName(appName);
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
@@ -7,68 +7,63 @@ import electronAppInjectable from "../electron-app.injectable";
|
||||
import openDeepLinkInjectable from "../../protocol-handler/lens-protocol-router-main/open-deep-link-for-url/open-deep-link.injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import commandLineArgumentsInjectable from "../../utils/command-line-arguments.injectable";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { find, startsWith, toLower, map } from "lodash/fp";
|
||||
import { startsWith, toLower } from "lodash/fp";
|
||||
import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
|
||||
import showApplicationWindowInjectable from "../../start-main-application/lens-window/show-application-window.injectable";
|
||||
|
||||
const setupDeepLinkingInjectable = getInjectable({
|
||||
id: "setup-deep-linking",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const openDeepLinkForUrl = di.inject(openDeepLinkInjectable);
|
||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: async () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const openDeepLinkForUrl = di.inject(openDeepLinkInjectable);
|
||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||
const firstInstanceCommandLineArguments = di.inject(commandLineArgumentsInjectable);
|
||||
|
||||
const firstInstanceCommandLineArguments = di.inject(
|
||||
commandLineArgumentsInjectable,
|
||||
);
|
||||
logger.info(`📟 Setting protocol client for lens://`);
|
||||
|
||||
return {
|
||||
id: "setup-deep-linking",
|
||||
run: async () => {
|
||||
logger.info(`📟 Setting protocol client for lens://`);
|
||||
if (app.setAsDefaultProtocolClient("lens")) {
|
||||
logger.info("📟 Protocol client register succeeded ✅");
|
||||
} else {
|
||||
logger.info("📟 Protocol client register failed ❗");
|
||||
}
|
||||
|
||||
if (app.setAsDefaultProtocolClient("lens")) {
|
||||
logger.info("📟 Protocol client register succeeded ✅");
|
||||
} else {
|
||||
logger.info("📟 Protocol client register failed ❗");
|
||||
}
|
||||
const url = getDeepLinkUrl(firstInstanceCommandLineArguments);
|
||||
|
||||
const url = getDeepLinkUrl(firstInstanceCommandLineArguments);
|
||||
if (url) {
|
||||
await openDeepLinkForUrl(url);
|
||||
}
|
||||
|
||||
if (url) {
|
||||
await openDeepLinkForUrl(url);
|
||||
}
|
||||
app.on("open-url", async (event, url) => {
|
||||
event.preventDefault();
|
||||
|
||||
app.on("open-url", async (event, url) => {
|
||||
event.preventDefault();
|
||||
await openDeepLinkForUrl(url);
|
||||
});
|
||||
|
||||
await openDeepLinkForUrl(url);
|
||||
});
|
||||
app.on(
|
||||
"second-instance",
|
||||
async (_, secondInstanceCommandLineArguments) => {
|
||||
const url = getDeepLinkUrl(secondInstanceCommandLineArguments);
|
||||
|
||||
app.on(
|
||||
"second-instance",
|
||||
await showApplicationWindow();
|
||||
|
||||
async (_, secondInstanceCommandLineArguments) => {
|
||||
const url = getDeepLinkUrl(secondInstanceCommandLineArguments);
|
||||
|
||||
await showApplicationWindow();
|
||||
|
||||
if (url) {
|
||||
await openDeepLinkForUrl(url);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
};
|
||||
},
|
||||
if (url) {
|
||||
await openDeepLinkForUrl(url);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
export default setupDeepLinkingInjectable;
|
||||
|
||||
const getDeepLinkUrl = (commandLineArguments: string[]) =>
|
||||
pipeline(commandLineArguments, map(toLower), find(startsWith("lens://")));
|
||||
const getDeepLinkUrl = (commandLineArguments: string[]) => (
|
||||
commandLineArguments
|
||||
.map(toLower)
|
||||
.find(startsWith("lens://"))
|
||||
);
|
||||
+25
-24
@@ -10,32 +10,33 @@ import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
|
||||
const setupDeveloperToolsInDevelopmentEnvironmentInjectable = getInjectable({
|
||||
id: "setup-developer-tools-in-development-environment",
|
||||
|
||||
instantiate: (di) => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const nodeEnv = di.inject(nodeEnvInjectionToken);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const nodeEnv = di.inject(nodeEnvInjectionToken);
|
||||
|
||||
return {
|
||||
id: "setup-developer-tools-in-development-environment",
|
||||
run: () => {
|
||||
if (nodeEnv !== "development") {
|
||||
return;
|
||||
if (nodeEnv !== "development") {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("🤓 Installing developer tools");
|
||||
|
||||
void (async () => {
|
||||
try {
|
||||
const {
|
||||
default: devToolsInstaller,
|
||||
REACT_DEVELOPER_TOOLS,
|
||||
} = await import("electron-devtools-installer");
|
||||
|
||||
const name = await devToolsInstaller([REACT_DEVELOPER_TOOLS]);
|
||||
|
||||
logger.info(`[DEVTOOLS-INSTALLER]: installed ${name}`);
|
||||
} catch (error) {
|
||||
logger.error(`[DEVTOOLS-INSTALLER]: failed`, { error });
|
||||
}
|
||||
|
||||
logger.info("🤓 Installing developer tools");
|
||||
|
||||
import("electron-devtools-installer")
|
||||
.then(({ default: devToolsInstaller, REACT_DEVELOPER_TOOLS }) =>
|
||||
devToolsInstaller([REACT_DEVELOPER_TOOLS]),
|
||||
)
|
||||
.then((name) =>
|
||||
logger.info(`[DEVTOOLS-INSTALLER]: installed ${name}`),
|
||||
)
|
||||
.catch((error) =>
|
||||
logger.error(`[DEVTOOLS-INSTALLER]: failed`, { error }),
|
||||
);
|
||||
},
|
||||
};
|
||||
},
|
||||
})();
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
@@ -10,19 +10,14 @@ import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
|
||||
const setupDeviceShutdownInjectable = getInjectable({
|
||||
id: "setup-device-shutdown",
|
||||
|
||||
instantiate: (di) => {
|
||||
const powerMonitor = di.inject(powerMonitorInjectable);
|
||||
const exitApp = di.inject(exitAppInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const powerMonitor = di.inject(powerMonitorInjectable);
|
||||
const exitApp = di.inject(exitAppInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-device-shutdown",
|
||||
run: () => {
|
||||
powerMonitor.on("shutdown", async () => {
|
||||
exitApp();
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
powerMonitor.on("shutdown", exitApp);
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
+19
-22
@@ -16,30 +16,27 @@ import clusterConnectionInjectable from "../../../cluster/cluster-connection.inj
|
||||
const setupIpcMainHandlersInjectable = getInjectable({
|
||||
id: "setup-ipc-main-handlers",
|
||||
|
||||
instantiate: (di) => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const applicationMenuItemComposite = di.inject(applicationMenuItemCompositeInjectable);
|
||||
const pushCatalogToRenderer = di.inject(pushCatalogToRendererInjectable);
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
const emitAppEvent = di.inject(emitAppEventInjectable);
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const applicationMenuItemComposite = di.inject(applicationMenuItemCompositeInjectable);
|
||||
const pushCatalogToRenderer = di.inject(pushCatalogToRendererInjectable);
|
||||
const clusterStore = di.inject(clusterStoreInjectable);
|
||||
const emitAppEvent = di.inject(emitAppEventInjectable);
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-ipc-main-handlers",
|
||||
run: () => {
|
||||
logger.debug("[APP-MAIN] initializing ipc main handlers");
|
||||
logger.debug("[APP-MAIN] initializing ipc main handlers");
|
||||
|
||||
setupIpcMainHandlers({
|
||||
applicationMenuItemComposite,
|
||||
pushCatalogToRenderer,
|
||||
clusterStore,
|
||||
emitAppEvent,
|
||||
getClusterById,
|
||||
getClusterConnection: (cluster) => di.inject(clusterConnectionInjectable, cluster),
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
setupIpcMainHandlers({
|
||||
applicationMenuItemComposite,
|
||||
pushCatalogToRenderer,
|
||||
clusterStore,
|
||||
emitAppEvent,
|
||||
getClusterById,
|
||||
getClusterConnection: (cluster) => di.inject(clusterConnectionInjectable, cluster),
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
causesSideEffects: true,
|
||||
|
||||
+13
-16
@@ -11,24 +11,21 @@ import showApplicationWindowInjectable from "../../start-main-application/lens-w
|
||||
const setupMainWindowVisibilityAfterActivationInjectable = getInjectable({
|
||||
id: "setup-main-window-visibility-after-activation",
|
||||
|
||||
instantiate: (di) => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-main-window-visibility-after-activation",
|
||||
run: () => {
|
||||
app.on("activate", async (_, windowIsVisible) => {
|
||||
logger.info("APP:ACTIVATE", { hasVisibleWindows: windowIsVisible });
|
||||
app.on("activate", (_, windowIsVisible) => {
|
||||
logger.info("APP:ACTIVATE", { hasVisibleWindows: windowIsVisible });
|
||||
|
||||
if (!windowIsVisible) {
|
||||
await showApplicationWindow();
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
if (!windowIsVisible) {
|
||||
void showApplicationWindow();
|
||||
}
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: onLoadOfApplicationInjectionToken,
|
||||
});
|
||||
|
||||
+12
-15
@@ -4,28 +4,25 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-electron-main";
|
||||
import { afterWindowIsOpenedInjectionToken } from "../../start-main-application/runnable-tokens/phases";
|
||||
import electronAppInjectable from "../electron-app.injectable";
|
||||
import { runManyFor } from "../../../common/runnable/run-many-for";
|
||||
import { afterWindowIsOpenedInjectionToken } from "../../start-main-application/runnable-tokens/after-window-is-opened-injection-token";
|
||||
import { runManyFor } from "@k8slens/run-many";
|
||||
|
||||
const setupRunnablesAfterWindowIsOpenedInjectable = getInjectable({
|
||||
id: "setup-runnables-after-window-is-opened",
|
||||
|
||||
instantiate: (di) => {
|
||||
const afterWindowIsOpened = runManyFor(di)(afterWindowIsOpenedInjectionToken);
|
||||
const app = di.inject(electronAppInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const afterWindowIsOpened = runManyFor(di)(afterWindowIsOpenedInjectionToken);
|
||||
const app = di.inject(electronAppInjectable);
|
||||
|
||||
return {
|
||||
id: "setup-runnables-after-window-is-opened",
|
||||
run: () => {
|
||||
app.on("browser-window-created", () => {
|
||||
afterWindowIsOpened();
|
||||
});
|
||||
app.on("browser-window-created", () => {
|
||||
afterWindowIsOpened();
|
||||
});
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
+27
-32
@@ -4,50 +4,45 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { beforeElectronIsReadyInjectionToken } from "@k8slens/application-for-electron-main";
|
||||
import { beforeQuitOfFrontEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-front-end-injection-token";
|
||||
import { beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
|
||||
import { beforeQuitOfFrontEndInjectionToken, beforeQuitOfBackEndInjectionToken } from "../../start-main-application/runnable-tokens/phases";
|
||||
import electronAppInjectable from "../electron-app.injectable";
|
||||
import isIntegrationTestingInjectable from "../../../common/vars/is-integration-testing.injectable";
|
||||
import autoUpdaterInjectable from "../features/auto-updater.injectable";
|
||||
import { runManySyncFor } from "../../../common/runnable/run-many-sync-for";
|
||||
import { runManySyncFor } from "@k8slens/run-many";
|
||||
|
||||
const setupRunnablesBeforeClosingOfApplicationInjectable = getInjectable({
|
||||
id: "setup-closing-of-application",
|
||||
|
||||
instantiate: (di) => {
|
||||
const runManySync = runManySyncFor(di);
|
||||
const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken);
|
||||
const runRunnablesBeforeQuitOfBackEnd = runManySync(beforeQuitOfBackEndInjectionToken);
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
|
||||
const autoUpdater = di.inject(autoUpdaterInjectable);
|
||||
instantiate: (di) => ({
|
||||
run: () => {
|
||||
const runManySync = runManySyncFor(di);
|
||||
const runRunnablesBeforeQuitOfFrontEnd = runManySync(beforeQuitOfFrontEndInjectionToken);
|
||||
const runRunnablesBeforeQuitOfBackEnd = runManySync(beforeQuitOfBackEndInjectionToken);
|
||||
const app = di.inject(electronAppInjectable);
|
||||
const isIntegrationTesting = di.inject(isIntegrationTestingInjectable);
|
||||
const autoUpdater = di.inject(autoUpdaterInjectable);
|
||||
let isAutoUpdating = false;
|
||||
|
||||
return {
|
||||
id: "setup-closing-of-application",
|
||||
run: () => {
|
||||
let isAutoUpdating = false;
|
||||
autoUpdater.on("before-quit-for-update", () => {
|
||||
isAutoUpdating = true;
|
||||
});
|
||||
|
||||
autoUpdater.on("before-quit-for-update", () => {
|
||||
isAutoUpdating = true;
|
||||
});
|
||||
app.on("will-quit", (event) => {
|
||||
runRunnablesBeforeQuitOfFrontEnd();
|
||||
|
||||
app.on("will-quit", (event) => {
|
||||
runRunnablesBeforeQuitOfFrontEnd();
|
||||
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
|
||||
|
||||
const shouldQuitBackEnd = isIntegrationTesting || isAutoUpdating;
|
||||
if (shouldQuitBackEnd) {
|
||||
runRunnablesBeforeQuitOfBackEnd();
|
||||
} else {
|
||||
// IMPORTANT: This cannot be destructured as it would break binding of "this" for the Electron event
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
if (shouldQuitBackEnd) {
|
||||
runRunnablesBeforeQuitOfBackEnd();
|
||||
} else {
|
||||
// IMPORTANT: This cannot be destructured as it would break binding of "this" for the Electron event
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
return undefined;
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeElectronIsReadyInjectionToken,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user