mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Switch to using startable-stoppable from NPM package
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
7113e0f255
commit
dbb87c231a
@ -329,6 +329,7 @@
|
|||||||
"@k8slens/application-for-electron-main": "^6.5.0-alpha.0",
|
"@k8slens/application-for-electron-main": "^6.5.0-alpha.0",
|
||||||
"@k8slens/legacy-extensions": "^1.0.0-alpha.0",
|
"@k8slens/legacy-extensions": "^1.0.0-alpha.0",
|
||||||
"@k8slens/run-many": "^1.0.0-alpha.1",
|
"@k8slens/run-many": "^1.0.0-alpha.1",
|
||||||
|
"@k8slens/startable-stoppable": "^1.0.0-alpha.1",
|
||||||
"@k8slens/test-utils": "^1.0.0-alpha.1",
|
"@k8slens/test-utils": "^1.0.0-alpha.1",
|
||||||
"@k8slens/utilities": "^1.0.0-alpha.1",
|
"@k8slens/utilities": "^1.0.0-alpha.1",
|
||||||
"@types/byline": "^4.2.33",
|
"@types/byline": "^4.2.33",
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { getStartableStoppable } from "../get-startable-stoppable";
|
import { getStartableStoppable } from "@k8slens/startable-stoppable";
|
||||||
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
|
import { messageChannelListenerInjectionToken } from "./message-channel-listener-injection-token";
|
||||||
import { enlistMessageChannelListenerInjectionToken } from "./enlist-message-channel-listener-injection-token";
|
import { enlistMessageChannelListenerInjectionToken } from "./enlist-message-channel-listener-injection-token";
|
||||||
import { disposer } from "@k8slens/utilities";
|
import { disposer } from "@k8slens/utilities";
|
||||||
|
|||||||
@ -1,62 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import type { StartableStoppable } from "./get-startable-stoppable";
|
|
||||||
import { getStartableStoppable } from "./get-startable-stoppable";
|
|
||||||
|
|
||||||
describe("getStartableStoppable", () => {
|
|
||||||
let stopMock: jest.MockedFunction<() => void>;
|
|
||||||
let startMock: jest.MockedFunction<() => () => void>;
|
|
||||||
let actual: StartableStoppable;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
stopMock = jest.fn();
|
|
||||||
startMock = jest.fn().mockImplementation(() => stopMock);
|
|
||||||
actual = getStartableStoppable("some-id", startMock);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not start yet", () => {
|
|
||||||
expect(startMock).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not stop yet", () => {
|
|
||||||
expect(stopMock).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("when stopping before ever starting, throws", () => {
|
|
||||||
expect(() => actual.stop()).toThrow("Tried to stop \"some-id\", but it is already stopped.");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("is not started", () => {
|
|
||||||
expect(actual.started).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("when started", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
actual.start();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls start function", () => {
|
|
||||||
expect(startMock).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("is started", () => {
|
|
||||||
expect(actual.started).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("when stopped", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
actual.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls stop function", () => {
|
|
||||||
expect(stopMock).toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("is stopped", () => {
|
|
||||||
expect(actual.started).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export type Stopper = () => void;
|
|
||||||
export type Starter = () => Stopper;
|
|
||||||
|
|
||||||
export interface StartableStoppable {
|
|
||||||
readonly started: boolean;
|
|
||||||
start: () => void;
|
|
||||||
stop: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
type StartableStoppableState = "stopped" | "started" | "starting";
|
|
||||||
|
|
||||||
export function getStartableStoppable(id: string, startAndGetStopper: Starter): StartableStoppable {
|
|
||||||
let stop: Stopper;
|
|
||||||
let state: StartableStoppableState = "stopped";
|
|
||||||
|
|
||||||
return {
|
|
||||||
get started() {
|
|
||||||
return state === "started";
|
|
||||||
},
|
|
||||||
|
|
||||||
start: () => {
|
|
||||||
if (state !== "stopped") {
|
|
||||||
throw new Error(`Tried to start "${id}", but it is already ${state}.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = "starting";
|
|
||||||
stop = startAndGetStopper();
|
|
||||||
state = "started";
|
|
||||||
},
|
|
||||||
|
|
||||||
stop: () => {
|
|
||||||
if (state !== "started") {
|
|
||||||
throw new Error(`Tried to stop "${id}", but it is already ${state}.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
stop();
|
|
||||||
state = "stopped";
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { autorun } from "mobx";
|
import { autorun } from "mobx";
|
||||||
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "@k8slens/startable-stoppable";
|
||||||
import populateApplicationMenuInjectable from "./populate-application-menu.injectable";
|
import populateApplicationMenuInjectable from "./populate-application-menu.injectable";
|
||||||
import applicationMenuItemCompositeInjectable from "./application-menu-item-composite.injectable";
|
import applicationMenuItemCompositeInjectable from "./application-menu-item-composite.injectable";
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { getStartableStoppable } from "../../../../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "@k8slens/startable-stoppable";
|
||||||
import processCheckingForUpdatesInjectable from "../../../main/process-checking-for-updates.injectable";
|
import processCheckingForUpdatesInjectable from "../../../main/process-checking-for-updates.injectable";
|
||||||
import withOrphanPromiseInjectable from "../../../../../common/utils/with-orphan-promise/with-orphan-promise.injectable";
|
import withOrphanPromiseInjectable from "../../../../../common/utils/with-orphan-promise/with-orphan-promise.injectable";
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { autorun } from "mobx";
|
import { autorun } from "mobx";
|
||||||
import { getStartableStoppable } from "../../../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "@k8slens/startable-stoppable";
|
||||||
import setUpdateOnQuitInjectable from "../../../../main/electron-app/features/set-update-on-quit.injectable";
|
import setUpdateOnQuitInjectable from "../../../../main/electron-app/features/set-update-on-quit.injectable";
|
||||||
import selectedUpdateChannelInjectable from "../../common/selected-update-channel/selected-update-channel.injectable";
|
import selectedUpdateChannelInjectable from "../../common/selected-update-channel/selected-update-channel.injectable";
|
||||||
import type { ReleaseChannel, UpdateChannel } from "../../common/update-channels";
|
import type { ReleaseChannel, UpdateChannel } from "../../common/update-channels";
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { reaction } from "mobx";
|
|||||||
import ipcMainInjectionToken from "../../common/ipc/ipc-main-injection-token";
|
import ipcMainInjectionToken from "../../common/ipc/ipc-main-injection-token";
|
||||||
import { catalogInitChannel } from "../../common/ipc/catalog";
|
import { catalogInitChannel } from "../../common/ipc/catalog";
|
||||||
import { disposer } from "@k8slens/utilities";
|
import { disposer } from "@k8slens/utilities";
|
||||||
import { getStartableStoppable } from "../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "@k8slens/startable-stoppable";
|
||||||
import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable";
|
import catalogEntityRegistryInjectable from "../catalog/entity-registry.injectable";
|
||||||
import catalogSyncBroadcasterInjectable from "./broadcaster.injectable";
|
import catalogSyncBroadcasterInjectable from "./broadcaster.injectable";
|
||||||
import { toJS } from "../../common/utils";
|
import { toJS } from "../../common/utils";
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "@k8slens/startable-stoppable";
|
||||||
import operatingSystemThemeStateInjectable from "../../theme/operating-system-theme-state.injectable";
|
import operatingSystemThemeStateInjectable from "../../theme/operating-system-theme-state.injectable";
|
||||||
import nativeThemeInjectable from "./native-theme.injectable";
|
import nativeThemeInjectable from "./native-theme.injectable";
|
||||||
import getElectronThemeInjectable from "./get-electron-theme.injectable";
|
import getElectronThemeInjectable from "./get-electron-theme.injectable";
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "@k8slens/startable-stoppable";
|
||||||
import electronTrayInjectable from "../electron-tray/electron-tray.injectable";
|
import electronTrayInjectable from "../electron-tray/electron-tray.injectable";
|
||||||
import trayIconInjectable from "./tray-icon.injectable";
|
import trayIconInjectable from "./tray-icon.injectable";
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { getStartableStoppable } from "../../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "@k8slens/startable-stoppable";
|
||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
import type { MinimalTrayMenuItem } from "../electron-tray/electron-tray.injectable";
|
import type { MinimalTrayMenuItem } from "../electron-tray/electron-tray.injectable";
|
||||||
import electronTrayInjectable from "../electron-tray/electron-tray.injectable";
|
import electronTrayInjectable from "../electron-tray/electron-tray.injectable";
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { disposer } from "@k8slens/utilities";
|
import { disposer } from "@k8slens/utilities";
|
||||||
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
import type { RequestChannel } from "../../../../common/utils/channel/request-channel-listener-injection-token";
|
||||||
import { getStartableStoppable } from "../../../../common/utils/get-startable-stoppable";
|
import { getStartableStoppable } from "@k8slens/startable-stoppable";
|
||||||
import enlistRequestChannelListenerInjectable from "./enlist-request-channel-listener.injectable";
|
import enlistRequestChannelListenerInjectable from "./enlist-request-channel-listener.injectable";
|
||||||
import { requestChannelListenerInjectionToken } from "./listener-tokens";
|
import { requestChannelListenerInjectionToken } from "./listener-tokens";
|
||||||
|
|
||||||
|
|||||||
@ -204,6 +204,7 @@
|
|||||||
"@k8slens/legacy-extension-example": "^1.0.0-alpha.1",
|
"@k8slens/legacy-extension-example": "^1.0.0-alpha.1",
|
||||||
"@k8slens/legacy-extensions": "^1.0.0-alpha.1",
|
"@k8slens/legacy-extensions": "^1.0.0-alpha.1",
|
||||||
"@k8slens/run-many": "^1.0.0-alpha.1",
|
"@k8slens/run-many": "^1.0.0-alpha.1",
|
||||||
|
"@k8slens/startable-stoppable": "^1.0.0-alpha.1",
|
||||||
"@k8slens/test-utils": "^1.0.0-alpha.1",
|
"@k8slens/test-utils": "^1.0.0-alpha.1",
|
||||||
"@k8slens/utilities": "^1.0.0-alpha.1",
|
"@k8slens/utilities": "^1.0.0-alpha.1",
|
||||||
"@ogre-tools/fp": "^15.1.2",
|
"@ogre-tools/fp": "^15.1.2",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user