diff --git a/src/common/utils/get-startable-stoppable.test.ts b/src/common/utils/get-startable-stoppable.test.ts index 0e5410f664..43c95921a5 100644 --- a/src/common/utils/get-startable-stoppable.test.ts +++ b/src/common/utils/get-startable-stoppable.test.ts @@ -13,7 +13,7 @@ describe("getStartableStoppable", () => { stopMock = jest.fn(); startMock = jest.fn(() => stopMock); - actual = getStartableStoppable(startMock); + actual = getStartableStoppable("some-id", startMock); }); it("does not start yet", () => { @@ -27,7 +27,7 @@ describe("getStartableStoppable", () => { it("when stopping before ever starting, throws", () => { expect(() => { actual.stop(); - }).toThrow("Tried to stop something that has not started yet."); + }).toThrow("Tried to stop \"some-id\", but it has not started yet."); }); describe("when started", () => { @@ -42,7 +42,7 @@ describe("getStartableStoppable", () => { it("when started again, throws", () => { expect(() => { actual.start(); - }).toThrow("Tried to start something that has already started."); + }).toThrow("Tried to start \"some-id\", but it has already started."); }); it("does not stop yet", () => { @@ -61,7 +61,7 @@ describe("getStartableStoppable", () => { it("when stopped again, throws", () => { expect(() => { actual.stop(); - }).toThrow("Tried to stop something that has already stopped."); + }).toThrow("Tried to stop \"some-id\", but it has already stopped."); }); describe("when started again", () => { diff --git a/src/common/utils/get-startable-stoppable.ts b/src/common/utils/get-startable-stoppable.ts index 11dc8efa34..7b2f0e1fd7 100644 --- a/src/common/utils/get-startable-stoppable.ts +++ b/src/common/utils/get-startable-stoppable.ts @@ -3,6 +3,7 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ export const getStartableStoppable = ( + id: string, startAndGetStopCallback: () => () => void, ) => { let dispose: () => void; @@ -12,7 +13,7 @@ export const getStartableStoppable = ( return { start: () => { if (started) { - throw new Error("Tried to start something that has already started."); + throw new Error(`Tried to start "${id}", but it has already started.`); } stopped = false; @@ -24,11 +25,11 @@ export const getStartableStoppable = ( stop: () => { if (stopped) { - throw new Error("Tried to stop something that has already stopped."); + throw new Error(`Tried to stop "${id}", but it has already stopped.`); } if (!started) { - throw new Error("Tried to stop something that has not started yet."); + throw new Error(`Tried to stop "${id}", but it has not started yet.`); } started = false; diff --git a/src/main/catalog-sync-to-renderer/catalog-sync-to-renderer.injectable.ts b/src/main/catalog-sync-to-renderer/catalog-sync-to-renderer.injectable.ts index 961ddee1f9..37daf0b265 100644 --- a/src/main/catalog-sync-to-renderer/catalog-sync-to-renderer.injectable.ts +++ b/src/main/catalog-sync-to-renderer/catalog-sync-to-renderer.injectable.ts @@ -13,7 +13,7 @@ const catalogSyncToRendererInjectable = getInjectable({ instantiate: (di) => { const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable); - return getStartableStoppable(() => + return getStartableStoppable("catalog-sync", () => startCatalogSyncToRenderer(catalogEntityRegistry), ); }, diff --git a/src/main/getDiForUnitTesting.ts b/src/main/getDiForUnitTesting.ts index 7c1bde8fb6..63addb3bbf 100644 --- a/src/main/getDiForUnitTesting.ts +++ b/src/main/getDiForUnitTesting.ts @@ -56,11 +56,8 @@ import applicationMenuInjectable from "./menu/application-menu.injectable"; import windowManagerInjectable from "./window-manager.injectable"; import isDevelopmentInjectable from "../common/vars/is-development.injectable"; import setupSystemCaInjectable from "./start-main-application/before-application-is-ready/implementations/setup-system-ca.injectable"; -import whenApplicationWillQuitInjectable from "./electron-app/when-application-will-quit.injectable"; import setupDeepLinkingInjectable from "./electron-app/after-application-is-ready/setup-deep-linking.injectable"; -import whenSecondInstanceInjectable from "./electron-app/when-second-instance.injectable"; import exitAppInjectable from "./electron-app/features/exit-app.injectable"; -import setApplicationNameInjectable from "./electron-app/features/set-application-name.injectable"; import getCommandLineSwitchInjectable from "./electron-app/features/get-command-line-switch.injectable"; import requestSingleInstanceLockInjectable from "./electron-app/features/request-single-instance-lock.injectable"; import disableHardwareAccelerationInjectable from "./electron-app/features/disable-hardware-acceleration.injectable"; @@ -92,7 +89,7 @@ export const getDiForUnitTesting = ( if (doGeneralOverrides) { overrideOperatingSystem(di); overrideRunnablesHavingSideEffects(di); - overrideElectron(di); + overrideElectronFeatures(di); di.override(isDevelopmentInjectable, () => false); di.override(environmentVariablesInjectable, () => ({})); @@ -187,7 +184,7 @@ const overrideOperatingSystem = (di: DiContainer) => { di.override(joinPathsInjectable, () => joinPathsFake); }; -const overrideElectron = (di: DiContainer) => { +const overrideElectronFeatures = (di: DiContainer) => { di.override(setupMainWindowVisibilityAfterActivationInjectable, () => ({ run: () => {}, })); @@ -197,10 +194,7 @@ const overrideElectron = (di: DiContainer) => { })); di.override(setupDeepLinkingInjectable, () => ({ run: () => {} })); - di.override(whenApplicationWillQuitInjectable, () => () => {}); - di.override(whenSecondInstanceInjectable, () => () => {}); di.override(exitAppInjectable, () => () => {}); - di.override(setApplicationNameInjectable, () => () => {}); di.override(getCommandLineSwitchInjectable, () => () => "irrelevant"); di.override(requestSingleInstanceLockInjectable, () => () => true); di.override(disableHardwareAccelerationInjectable, () => () => {}); diff --git a/src/main/menu/application-menu.injectable.ts b/src/main/menu/application-menu.injectable.ts index 4daf56bb6e..633ccedbc4 100644 --- a/src/main/menu/application-menu.injectable.ts +++ b/src/main/menu/application-menu.injectable.ts @@ -14,7 +14,7 @@ const applicationMenuInjectable = getInjectable({ instantiate: (di) => { const applicationMenuItems = di.inject(applicationMenuItemsInjectable); - return getStartableStoppable(() => + return getStartableStoppable("build-of-application-menu", () => autorun(() => buildMenu(applicationMenuItems.get()), { delay: 100, }), diff --git a/src/main/tray/tray.injectable.ts b/src/main/tray/tray.injectable.ts index 185044cbf5..89ffebe2c4 100644 --- a/src/main/tray/tray.injectable.ts +++ b/src/main/tray/tray.injectable.ts @@ -21,7 +21,7 @@ const trayInjectable = getInjectable({ const stopServicesAndExitApp = di.inject(stopServicesAndExitAppInjectable); const isAutoUpdateEnabled = di.inject(isAutoUpdateEnabledInjectable); - return getStartableStoppable(() => + return getStartableStoppable("build-of-tray", () => initTray( windowManager, trayMenuItems,