mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Replace last use of customRequestPromise with di
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
3c9791e81e
commit
c3402562a1
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
export const windowActionHandleChannel = "window:window-action";
|
export const windowActionHandleChannel = "window:window-action";
|
||||||
export const windowOpenAppMenuAsContextMenuChannel = "window:open-app-context-menu";
|
export const windowOpenAppMenuAsContextMenuChannel = "window:open-app-context-menu";
|
||||||
export const windowLocationChangedChannel = "window:location-changed";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The supported actions on the current window. The argument for `windowActionHandleChannel`
|
* The supported actions on the current window. The argument for `windowActionHandleChannel`
|
||||||
|
|||||||
@ -5,8 +5,8 @@
|
|||||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue } from "mobx";
|
||||||
export interface SyncBox<Value> {
|
export interface SyncBox<Value> {
|
||||||
id: string;
|
readonly id: string;
|
||||||
value: IComputedValue<Value>;
|
readonly value: IComputedValue<Value>;
|
||||||
set: (value: Value) => void;
|
set: (value: Value) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,7 @@ describe("listing active helm repositories in preferences", () => {
|
|||||||
|
|
||||||
builder.beforeApplicationStart((mainDi) => {
|
builder.beforeApplicationStart((mainDi) => {
|
||||||
mainDi.override(readYamlFileInjectable, () => readYamlFileMock);
|
mainDi.override(readYamlFileInjectable, () => readYamlFileMock);
|
||||||
mainDi.override(execFileInjectable, () => execFileMock);
|
mainDi.override(exrequestPublicHelmRepositoriesInjectable
|
||||||
mainDi.override(helmBinaryPathInjectable, () => "some-helm-binary-path");
|
mainDi.override(helmBinaryPathInjectable, () => "some-helm-binary-path");
|
||||||
mainDi.override(loggerInjectable, () => loggerStub);
|
mainDi.override(loggerInjectable, () => loggerStub);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -30,7 +30,7 @@ describe("preferences - navigation to kubernetes preferences", () => {
|
|||||||
mainDi.override(
|
mainDi.override(
|
||||||
getActiveHelmRepositoriesInjectable,
|
getActiveHelmRepositoriesInjectable,
|
||||||
() => async () => ({ callWasSuccessful: true, response: [] }),
|
() => async () => ({ callWasSuccessful: true, response: [] }),
|
||||||
);
|
);requestPublicHelmRepositoriesInjectable;
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.beforeWindowStart((windowDi) => {
|
builder.beforeWindowStart((windowDi) => {
|
||||||
|
|||||||
27
src/features/top-bar/common/state.injectable.ts
Normal file
27
src/features/top-bar/common/state.injectable.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* 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 createSyncBoxInjectable from "../../../common/utils/sync-box/create-sync-box.injectable";
|
||||||
|
import { syncBoxInjectionToken } from "../../../common/utils/sync-box/sync-box-injection-token";
|
||||||
|
|
||||||
|
export interface TopBarState {
|
||||||
|
prevEnabled: boolean;
|
||||||
|
nextEnabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const topBarStateInjectable = getInjectable({
|
||||||
|
id: "top-bar-state",
|
||||||
|
instantiate: (di) => {
|
||||||
|
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||||
|
|
||||||
|
return createSyncBox<TopBarState>("top-bar-state", {
|
||||||
|
prevEnabled: false,
|
||||||
|
nextEnabled: false,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
injectionToken: syncBoxInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default topBarStateInjectable;
|
||||||
11
src/features/window-location/common/channel.ts
Normal file
11
src/features/window-location/common/channel.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { MessageChannel } from "../../../common/utils/channel/message-channel-listener-injection-token";
|
||||||
|
import type { Location } from "history";
|
||||||
|
|
||||||
|
export const windowLocationChangedChannel: MessageChannel<Location> = {
|
||||||
|
id: "window-location-changed",
|
||||||
|
};
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getMessageChannelListenerInjectable } from "../../../common/utils/channel/message-channel-listener-injection-token";
|
||||||
|
import getVisibleWindowsInjectable from "../../../main/start-main-application/lens-window/get-visible-windows.injectable";
|
||||||
|
import topBarStateInjectable from "../../top-bar/common/state.injectable";
|
||||||
|
import { windowLocationChangedChannel } from "../common/channel";
|
||||||
|
|
||||||
|
const windowLocationHasChangedForTopBarStateHandlerInjectable = getMessageChannelListenerInjectable({
|
||||||
|
id: "for-top-bar-state",
|
||||||
|
channel: windowLocationChangedChannel,
|
||||||
|
handler: (di) => {
|
||||||
|
const getVisibleWindows = di.inject(getVisibleWindowsInjectable);
|
||||||
|
const topBarState = di.inject(topBarStateInjectable);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
const windows = getVisibleWindows();
|
||||||
|
|
||||||
|
topBarState.set({
|
||||||
|
prevEnabled: windows.some(window => window.canGoBack()),
|
||||||
|
nextEnabled: windows.some(window => window.canGoForward()),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default windowLocationHasChangedForTopBarStateHandlerInjectable;
|
||||||
21
src/features/window-location/renderer/emit.injectable.ts
Normal file
21
src/features/window-location/renderer/emit.injectable.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* 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 type { MessageChannelSender } from "../../../common/utils/channel/message-to-channel-injection-token";
|
||||||
|
import { sendMessageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
|
||||||
|
import { windowLocationChangedChannel } from "../common/channel";
|
||||||
|
|
||||||
|
export type EmitWindowLocationChanged = MessageChannelSender<typeof windowLocationChangedChannel>;
|
||||||
|
|
||||||
|
const emitWindowLocationChangedInjectable = getInjectable({
|
||||||
|
id: "emit-window-location-changed",
|
||||||
|
instantiate: (di): EmitWindowLocationChanged => {
|
||||||
|
const sendMessageToChannel = di.inject(sendMessageToChannelInjectionToken);
|
||||||
|
|
||||||
|
return (location) => sendMessageToChannel(windowLocationChangedChannel, location);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default emitWindowLocationChangedInjectable;
|
||||||
@ -10,8 +10,8 @@ import type { ClusterId } from "../../../../common/cluster-types";
|
|||||||
import type { ClusterStore } from "../../../../common/cluster-store/cluster-store";
|
import type { ClusterStore } from "../../../../common/cluster-store/cluster-store";
|
||||||
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc";
|
import { broadcastMainChannel, broadcastMessage, ipcMainHandle, ipcMainOn } from "../../../../common/ipc";
|
||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue } from "mobx";
|
||||||
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../../common/ipc/window";
|
import { windowActionHandleChannel, windowOpenAppMenuAsContextMenuChannel } from "../../../../common/ipc/window";
|
||||||
import { handleWindowAction, onLocationChange } from "../../../ipc/window";
|
import { handleWindowAction } from "../../../ipc/window";
|
||||||
import type { ApplicationMenuItemTypes } from "../../../../features/application-menu/main/menu-items/application-menu-item-injection-token";
|
import type { ApplicationMenuItemTypes } from "../../../../features/application-menu/main/menu-items/application-menu-item-injection-token";
|
||||||
import type { Composite } from "../../../../common/utils/composite/get-composite/get-composite";
|
import type { Composite } from "../../../../common/utils/composite/get-composite/get-composite";
|
||||||
import { getApplicationMenuTemplate } from "../../../../features/application-menu/main/populate-application-menu.injectable";
|
import { getApplicationMenuTemplate } from "../../../../features/application-menu/main/populate-application-menu.injectable";
|
||||||
@ -59,8 +59,6 @@ export const setupIpcMainHandlers = ({
|
|||||||
|
|
||||||
ipcMainHandle(windowActionHandleChannel, (event, action) => handleWindowAction(action));
|
ipcMainHandle(windowActionHandleChannel, (event, action) => handleWindowAction(action));
|
||||||
|
|
||||||
ipcMainOn(windowLocationChangedChannel, () => onLocationChange());
|
|
||||||
|
|
||||||
ipcMainHandle(broadcastMainChannel, (event, channel, ...args) => broadcastMessage(channel, ...args));
|
ipcMainHandle(broadcastMainChannel, (event, channel, ...args) => broadcastMessage(channel, ...args));
|
||||||
|
|
||||||
ipcMainOn(windowOpenAppMenuAsContextMenuChannel, async (event) => {
|
ipcMainOn(windowOpenAppMenuAsContextMenuChannel, async (event) => {
|
||||||
|
|||||||
@ -3,8 +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 { BrowserWindow, webContents } from "electron";
|
import { BrowserWindow } from "electron";
|
||||||
import { broadcastMessage } from "../../common/ipc";
|
|
||||||
import { WindowAction } from "../../common/ipc/window";
|
import { WindowAction } from "../../common/ipc/window";
|
||||||
|
|
||||||
export function handleWindowAction(action: WindowAction) {
|
export function handleWindowAction(action: WindowAction) {
|
||||||
@ -46,26 +45,3 @@ export function handleWindowAction(action: WindowAction) {
|
|||||||
throw new Error(`Attemped window action ${action} is unknown`);
|
throw new Error(`Attemped window action ${action} is unknown`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onLocationChange(): void {
|
|
||||||
const getAllWebContents = webContents.getAllWebContents();
|
|
||||||
|
|
||||||
const canGoBack = getAllWebContents.some((webContent) => {
|
|
||||||
if (webContent.getType() === "window") {
|
|
||||||
return webContent.canGoBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
const canGoForward = getAllWebContents.some((webContent) => {
|
|
||||||
if (webContent.getType() === "window") {
|
|
||||||
return webContent.canGoForward();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
broadcastMessage("history:can-go-back", canGoBack);
|
|
||||||
broadcastMessage("history:can-go-forward", canGoForward);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import { timingSafeEqual, X509Certificate } from "crypto";
|
|||||||
import loggerInjectable from "../../../../common/logger.injectable";
|
import loggerInjectable from "../../../../common/logger.injectable";
|
||||||
import applicationWindowStateInjectable from "./application-window-state.injectable";
|
import applicationWindowStateInjectable from "./application-window-state.injectable";
|
||||||
import { BrowserWindow } from "electron";
|
import { BrowserWindow } from "electron";
|
||||||
import type { ElectronWindow } from "./create-lens-window.injectable";
|
|
||||||
import type { RequireExactlyOne } from "type-fest";
|
import type { RequireExactlyOne } from "type-fest";
|
||||||
import openLinkInBrowserInjectable from "../../../../common/utils/open-link-in-browser.injectable";
|
import openLinkInBrowserInjectable from "../../../../common/utils/open-link-in-browser.injectable";
|
||||||
import getAbsolutePathInjectable from "../../../../common/path/get-absolute-path.injectable";
|
import getAbsolutePathInjectable from "../../../../common/path/get-absolute-path.injectable";
|
||||||
@ -16,6 +15,24 @@ import isLinuxInjectable from "../../../../common/vars/is-linux.injectable";
|
|||||||
import applicationInformationToken from "../../../../common/vars/application-information-token";
|
import applicationInformationToken from "../../../../common/vars/application-information-token";
|
||||||
import pathExistsSyncInjectable from "../../../../common/fs/path-exists-sync.injectable";
|
import pathExistsSyncInjectable from "../../../../common/fs/path-exists-sync.injectable";
|
||||||
import lensProxyCertificateInjectable from "../../../../common/certificate/lens-proxy-certificate.injectable";
|
import lensProxyCertificateInjectable from "../../../../common/certificate/lens-proxy-certificate.injectable";
|
||||||
|
import type { ClusterFrameInfo } from "../../../../common/cluster-frames";
|
||||||
|
|
||||||
|
export interface SendToViewArgs {
|
||||||
|
channel: string;
|
||||||
|
frameInfo?: ClusterFrameInfo;
|
||||||
|
data?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ElectronWindow {
|
||||||
|
show: () => void;
|
||||||
|
close: () => void;
|
||||||
|
send: (args: SendToViewArgs) => void;
|
||||||
|
loadFile: (filePath: string) => Promise<void>;
|
||||||
|
loadUrl: (url: string) => Promise<void>;
|
||||||
|
reload: () => void;
|
||||||
|
canGoBack: () => boolean;
|
||||||
|
canGoForward: () => boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export type ElectronWindowTitleBarStyle = "hiddenInset" | "hidden" | "default" | "customButtonsOnHover";
|
export type ElectronWindowTitleBarStyle = "hiddenInset" | "hidden" | "default" | "customButtonsOnHover";
|
||||||
|
|
||||||
@ -165,7 +182,6 @@ const createElectronWindowInjectable = getInjectable({
|
|||||||
|
|
||||||
await browserWindow.loadFile(filePath);
|
await browserWindow.loadFile(filePath);
|
||||||
},
|
},
|
||||||
|
|
||||||
loadUrl: async (url) => {
|
loadUrl: async (url) => {
|
||||||
logger.info(
|
logger.info(
|
||||||
`[CREATE-ELECTRON-WINDOW]: Loading content for window "${configuration.id}" from url: ${url}...`,
|
`[CREATE-ELECTRON-WINDOW]: Loading content for window "${configuration.id}" from url: ${url}...`,
|
||||||
@ -173,7 +189,8 @@ const createElectronWindowInjectable = getInjectable({
|
|||||||
|
|
||||||
await browserWindow.loadURL(url);
|
await browserWindow.loadURL(url);
|
||||||
},
|
},
|
||||||
|
canGoBack: () => browserWindow.webContents.canGoBack(),
|
||||||
|
canGoForward: () => browserWindow.webContents.canGoForward(),
|
||||||
show: () => browserWindow.show(),
|
show: () => browserWindow.show(),
|
||||||
close: () => browserWindow.close(),
|
close: () => browserWindow.close(),
|
||||||
send: ({ channel, data, frameInfo }) => {
|
send: ({ channel, data, frameInfo }) => {
|
||||||
@ -187,7 +204,6 @@ const createElectronWindowInjectable = getInjectable({
|
|||||||
browserWindow.webContents.send(channel, data);
|
browserWindow.webContents.send(channel, data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
reload: () => {
|
reload: () => {
|
||||||
const wc = browserWindow.webContents;
|
const wc = browserWindow.webContents;
|
||||||
|
|
||||||
|
|||||||
@ -3,24 +3,8 @@
|
|||||||
* 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 type { ContentSource, ElectronWindowTitleBarStyle } from "./create-electron-window.injectable";
|
import type { ContentSource, ElectronWindow, ElectronWindowTitleBarStyle, SendToViewArgs } from "./create-electron-window.injectable";
|
||||||
import createElectronWindowForInjectable from "./create-electron-window.injectable";
|
import createElectronWindowForInjectable from "./create-electron-window.injectable";
|
||||||
import type { ClusterFrameInfo } from "../../../../common/cluster-frames";
|
|
||||||
|
|
||||||
export interface ElectronWindow {
|
|
||||||
show: () => void;
|
|
||||||
close: () => void;
|
|
||||||
send: (args: SendToViewArgs) => void;
|
|
||||||
loadFile: (filePath: string) => Promise<void>;
|
|
||||||
loadUrl: (url: string) => Promise<void>;
|
|
||||||
reload: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SendToViewArgs {
|
|
||||||
channel: string;
|
|
||||||
frameInfo?: ClusterFrameInfo;
|
|
||||||
data?: unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LensWindow {
|
export interface LensWindow {
|
||||||
id: string;
|
id: string;
|
||||||
@ -31,6 +15,8 @@ export interface LensWindow {
|
|||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
isStarting: boolean;
|
isStarting: boolean;
|
||||||
reload: () => void;
|
reload: () => void;
|
||||||
|
canGoBack: () => boolean;
|
||||||
|
canGoForward: () => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LensWindowConfiguration {
|
export interface LensWindowConfiguration {
|
||||||
@ -78,15 +64,14 @@ const createLensWindowInjectable = getInjectable({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
id: configuration.id,
|
id: configuration.id,
|
||||||
|
|
||||||
get isVisible() {
|
get isVisible() {
|
||||||
return windowIsShown;
|
return windowIsShown;
|
||||||
},
|
},
|
||||||
|
|
||||||
get isStarting() {
|
get isStarting() {
|
||||||
return windowIsStarting;
|
return windowIsStarting;
|
||||||
},
|
},
|
||||||
|
canGoBack: () => Boolean(browserWindow?.canGoBack()),
|
||||||
|
canGoForward: () => Boolean(browserWindow?.canGoForward()),
|
||||||
start: async () => {
|
start: async () => {
|
||||||
if (!browserWindow) {
|
if (!browserWindow) {
|
||||||
windowIsStarting = true;
|
windowIsStarting = true;
|
||||||
|
|||||||
@ -1,33 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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 { action } from "mobx";
|
|
||||||
import { beforeFrameStartsSecondInjectionToken } from "../../../before-frame-starts/tokens";
|
|
||||||
import ipcRendererInjectable from "../../../utils/channel/ipc-renderer.injectable";
|
|
||||||
import topBarStateInjectable from "./state.injectable";
|
|
||||||
|
|
||||||
// TODO: replace with a SyncBox
|
|
||||||
const startTopbarStateSyncInjectable = getInjectable({
|
|
||||||
id: "start-topbar-state-sync",
|
|
||||||
instantiate: (di) => ({
|
|
||||||
id: "start-topbar-state-sync",
|
|
||||||
run: () => {
|
|
||||||
const state = di.inject(topBarStateInjectable);
|
|
||||||
const ipcRenderer = di.inject(ipcRendererInjectable);
|
|
||||||
|
|
||||||
ipcRenderer.on("history:can-go-back", action((event, canGoBack: boolean) => {
|
|
||||||
state.prevEnabled = canGoBack;
|
|
||||||
}));
|
|
||||||
|
|
||||||
ipcRenderer.on("history:can-go-forward", action((event, canGoForward: boolean) => {
|
|
||||||
state.nextEnabled = canGoForward;
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
injectionToken: beforeFrameStartsSecondInjectionToken,
|
|
||||||
causesSideEffects: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default startTopbarStateSyncInjectable;
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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 { observable } from "mobx";
|
|
||||||
|
|
||||||
const topBarStateInjectable = getInjectable({
|
|
||||||
id: "top-bar-state",
|
|
||||||
instantiate: () => observable.object({
|
|
||||||
prevEnabled: false,
|
|
||||||
nextEnabled: false,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default topBarStateInjectable;
|
|
||||||
@ -4,14 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import topBarStateInjectable from "../../state.injectable";
|
import topBarStateInjectable from "../../../../../../features/top-bar/common/state.injectable";
|
||||||
|
|
||||||
const topBarPrevEnabledInjectable = getInjectable({
|
const topBarPrevEnabledInjectable = getInjectable({
|
||||||
id: "top-bar-prev-enabled",
|
id: "top-bar-prev-enabled",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const state = di.inject(topBarStateInjectable);
|
const state = di.inject(topBarStateInjectable);
|
||||||
|
|
||||||
return computed(() => state.prevEnabled);
|
return computed(() => state.value.get().prevEnabled);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -4,14 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import topBarStateInjectable from "../../state.injectable";
|
import topBarStateInjectable from "../../../../../../features/top-bar/common/state.injectable";
|
||||||
|
|
||||||
const topBarNextEnabledInjectable = getInjectable({
|
const topBarNextEnabledInjectable = getInjectable({
|
||||||
id: "top-bar-next-enabled",
|
id: "top-bar-next-enabled",
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const state = di.inject(topBarStateInjectable);
|
const state = di.inject(topBarStateInjectable);
|
||||||
|
|
||||||
return computed(() => state.nextEnabled);
|
return computed(() => state.value.get().nextEnabled);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -11,17 +11,17 @@ import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
|||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import type { DiRender } from "../../test-utils/renderFor";
|
import type { DiRender } from "../../test-utils/renderFor";
|
||||||
import { renderFor } from "../../test-utils/renderFor";
|
import { renderFor } from "../../test-utils/renderFor";
|
||||||
import { computed, observable } from "mobx";
|
import { computed } from "mobx";
|
||||||
import rendererExtensionsInjectable from "../../../../extensions/renderer-extensions.injectable";
|
import rendererExtensionsInjectable from "../../../../extensions/renderer-extensions.injectable";
|
||||||
import closeWindowInjectable from "./top-bar-items/window-controls/close-window/close-window.injectable";
|
import closeWindowInjectable from "./top-bar-items/window-controls/close-window/close-window.injectable";
|
||||||
import goBackInjectable from "./top-bar-items/navigation-to-back/go-back/go-back.injectable";
|
import goBackInjectable from "./top-bar-items/navigation-to-back/go-back/go-back.injectable";
|
||||||
import maximizeWindowInjectable from "./top-bar-items/window-controls/maximize-window/maximize-window.injectable";
|
import maximizeWindowInjectable from "./top-bar-items/window-controls/maximize-window/maximize-window.injectable";
|
||||||
import openAppContextMenuInjectable from "./top-bar-items/context-menu/open-app-context-menu/open-app-context-menu.injectable";
|
import openAppContextMenuInjectable from "./top-bar-items/context-menu/open-app-context-menu/open-app-context-menu.injectable";
|
||||||
import toggleMaximizeWindowInjectable from "./toggle-maximize-window/toggle-maximize-window.injectable";
|
import toggleMaximizeWindowInjectable from "./toggle-maximize-window/toggle-maximize-window.injectable";
|
||||||
import topBarStateInjectable from "./state.injectable";
|
|
||||||
import platformInjectable from "../../../../common/vars/platform.injectable";
|
import platformInjectable from "../../../../common/vars/platform.injectable";
|
||||||
import goForwardInjectable from "./top-bar-items/navigation-to-forward/go-forward/go-forward.injectable";
|
import goForwardInjectable from "./top-bar-items/navigation-to-forward/go-forward/go-forward.injectable";
|
||||||
import currentlyInClusterFrameInjectable from "../../../routes/currently-in-cluster-frame.injectable";
|
import currentlyInClusterFrameInjectable from "../../../routes/currently-in-cluster-frame.injectable";
|
||||||
|
import topBarStateInjectable from "../../../../features/top-bar/common/state.injectable";
|
||||||
|
|
||||||
describe("<TopBar/>", () => {
|
describe("<TopBar/>", () => {
|
||||||
let di: DiContainer;
|
let di: DiContainer;
|
||||||
@ -50,10 +50,10 @@ describe("<TopBar/>", () => {
|
|||||||
|
|
||||||
describe("with both previous and next history enabled", () => {
|
describe("with both previous and next history enabled", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
di.override(topBarStateInjectable, () => observable.object({
|
di.inject(topBarStateInjectable).set({
|
||||||
prevEnabled: true,
|
prevEnabled: true,
|
||||||
nextEnabled: true,
|
nextEnabled: true,
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders w/o errors", () => {
|
it("renders w/o errors", () => {
|
||||||
|
|||||||
@ -12,9 +12,7 @@ import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
|||||||
import hostedClusterIdInjectable from "./cluster-frame-context/hosted-cluster-id.injectable";
|
import hostedClusterIdInjectable from "./cluster-frame-context/hosted-cluster-id.injectable";
|
||||||
import { runInAction } from "mobx";
|
import { runInAction } from "mobx";
|
||||||
import requestAnimationFrameInjectable from "./components/animate/request-animation-frame.injectable";
|
import requestAnimationFrameInjectable from "./components/animate/request-animation-frame.injectable";
|
||||||
import startTopbarStateSyncInjectable from "./components/layout/top-bar/start-state-sync.injectable";
|
|
||||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||||
import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable";
|
|
||||||
import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable";
|
import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable";
|
||||||
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
||||||
import applicationInformationInjectable from "../common/vars/application-information-injectable";
|
import applicationInformationInjectable from "../common/vars/application-information-injectable";
|
||||||
@ -60,21 +58,11 @@ export const getDiForUnitTesting = (
|
|||||||
di.override(globalOverride.injectable, globalOverride.overridingInstantiate);
|
di.override(globalOverride.injectable, globalOverride.overridingInstantiate);
|
||||||
}
|
}
|
||||||
|
|
||||||
[
|
|
||||||
startTopbarStateSyncInjectable,
|
|
||||||
].forEach((injectable) => {
|
|
||||||
di.override(injectable, () => ({
|
|
||||||
id: injectable.id,
|
|
||||||
run: () => {},
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
di.override(hostedClusterIdInjectable, () => undefined);
|
di.override(hostedClusterIdInjectable, () => undefined);
|
||||||
|
|
||||||
di.override(legacyOnChannelListenInjectable, () => () => noop);
|
di.override(legacyOnChannelListenInjectable, () => () => noop);
|
||||||
|
|
||||||
di.override(requestAnimationFrameInjectable, () => (callback) => callback());
|
di.override(requestAnimationFrameInjectable, () => (callback) => callback());
|
||||||
di.override(watchHistoryStateInjectable, () => () => () => {});
|
|
||||||
|
|
||||||
di.override(requestFromChannelInjectable, () => () => Promise.resolve(undefined as never));
|
di.override(requestFromChannelInjectable, () => () => Promise.resolve(undefined as never));
|
||||||
|
|
||||||
|
|||||||
@ -5,12 +5,11 @@
|
|||||||
|
|
||||||
import { clusterActivateHandler, clusterDisconnectHandler, clusterSetFrameIdHandler, clusterStates } from "../../common/ipc/cluster";
|
import { clusterActivateHandler, clusterDisconnectHandler, clusterSetFrameIdHandler, clusterStates } from "../../common/ipc/cluster";
|
||||||
import type { ClusterId, ClusterState } from "../../common/cluster-types";
|
import type { ClusterId, ClusterState } from "../../common/cluster-types";
|
||||||
import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppMenuAsContextMenuChannel, type WindowAction } from "../../common/ipc/window";
|
import { windowActionHandleChannel, windowOpenAppMenuAsContextMenuChannel, type WindowAction } from "../../common/ipc/window";
|
||||||
import { extensionDiscoveryStateChannel, extensionLoaderFromMainChannel } from "../../common/ipc/extension-handling";
|
import { extensionDiscoveryStateChannel, extensionLoaderFromMainChannel } from "../../common/ipc/extension-handling";
|
||||||
import type { InstalledExtension } from "../../extensions/extension-discovery/extension-discovery";
|
import type { InstalledExtension } from "../../extensions/extension-discovery/extension-discovery";
|
||||||
import type { LensExtensionId } from "../../extensions/lens-extension";
|
import type { LensExtensionId } from "../../extensions/lens-extension";
|
||||||
import { toJS } from "../utils";
|
import { toJS } from "../utils";
|
||||||
import type { Location } from "history";
|
|
||||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||||
import ipcRendererInjectable from "../utils/channel/ipc-renderer.injectable";
|
import ipcRendererInjectable from "../utils/channel/ipc-renderer.injectable";
|
||||||
|
|
||||||
@ -34,10 +33,6 @@ export function emitOpenAppMenuAsContextMenu(): void {
|
|||||||
emitToMain(windowOpenAppMenuAsContextMenuChannel);
|
emitToMain(windowOpenAppMenuAsContextMenuChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function emitWindowLocationChanged(location: Location): void {
|
|
||||||
emitToMain(windowLocationChangedChannel, location);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function requestWindowAction(type: WindowAction): Promise<void> {
|
export function requestWindowAction(type: WindowAction): Promise<void> {
|
||||||
return requestMain(windowActionHandleChannel, type);
|
return requestMain(windowActionHandleChannel, type);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,23 +4,22 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
import { emitWindowLocationChanged } from "../ipc";
|
|
||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
import observableHistoryInjectable from "../navigation/observable-history.injectable";
|
import observableHistoryInjectable from "../navigation/observable-history.injectable";
|
||||||
|
import emitWindowLocationChangedInjectable from "../../features/window-location/renderer/emit.injectable";
|
||||||
|
|
||||||
const watchHistoryStateInjectable = getInjectable({
|
const watchHistoryStateInjectable = getInjectable({
|
||||||
id: "watch-history-state",
|
id: "watch-history-state",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const observableHistory = di.inject(observableHistoryInjectable);
|
const observableHistory = di.inject(observableHistoryInjectable);
|
||||||
|
const emitWindowLocationChanged = di.inject(emitWindowLocationChangedInjectable);
|
||||||
|
|
||||||
return () => reaction(
|
return () => reaction(
|
||||||
() => observableHistory.location,
|
() => observableHistory.location,
|
||||||
emitWindowLocationChanged,
|
emitWindowLocationChanged,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
causesSideEffects: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default watchHistoryStateInjectable;
|
export default watchHistoryStateInjectable;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user