1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/start-main-application/lens-window/navigate.injectable.ts
Janne Savolainen 5ac9b2aa87
Extract responsibilities of WindowManager as injectables
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2022-05-11 08:27:17 +03:00

40 lines
1.2 KiB
TypeScript

/**
* 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 { iter } from "../../../common/utils";
import applicationWindowInjectable from "./application-window/application-window.injectable";
import clusterFramesInjectable from "../../../common/cluster-frames.injectable";
import { IpcRendererNavigationEvents } from "../../../renderer/navigation/events";
const navigateInjectable = getInjectable({
id: "navigate",
instantiate: (di) => {
const applicationWindow = di.inject(applicationWindowInjectable);
const clusterFrames = di.inject(clusterFramesInjectable);
return async (url: string, frameId?: number) => {
await applicationWindow.show();
const frameInfo = iter.find(
clusterFrames.values(),
(frameInfo) => frameInfo.frameId === frameId,
);
const channel = frameInfo
? IpcRendererNavigationEvents.NAVIGATE_IN_CLUSTER
: IpcRendererNavigationEvents.NAVIGATE_IN_APP;
await applicationWindow.send({
channel,
frameInfo,
data: [url],
});
};
},
});
export default navigateInjectable;