mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make startableStoppables have ID for better error logging
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
57a1677c48
commit
203418ac37
@ -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", () => {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -13,7 +13,7 @@ const catalogSyncToRendererInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||
|
||||
return getStartableStoppable(() =>
|
||||
return getStartableStoppable("catalog-sync", () =>
|
||||
startCatalogSyncToRenderer(catalogEntityRegistry),
|
||||
);
|
||||
},
|
||||
|
||||
@ -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, () => () => {});
|
||||
|
||||
@ -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,
|
||||
}),
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user