1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/routes/navigate-to-url.injectable.ts
Sebastian Malton fd86ea0d97 Convert all of kube-details-params/ and navigate/ to injectable
- This fixes a runtime error that was encountered during testing

Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-05-04 08:47:20 -04:00

38 lines
1.3 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 observableHistoryInjectable from "../navigation/observable-history.injectable";
import { runInAction } from "mobx";
import type { NavigateToUrl } from "../../common/front-end-routing/navigate-to-url-injection-token";
import { navigateToUrlInjectionToken } from "../../common/front-end-routing/navigate-to-url-injection-token";
import { broadcastMessage } from "../../common/ipc";
import { IpcRendererNavigationEvents } from "../navigation/events";
const navigateToUrlInjectable = getInjectable({
id: "navigate-to-url",
instantiate: (di): NavigateToUrl => {
const observableHistory = di.inject(observableHistoryInjectable);
return (url, options = {}): void => {
if (options.forceRootFrame) {
return void broadcastMessage(IpcRendererNavigationEvents.NAVIGATE_IN_APP, url);
}
runInAction(() => {
if (options.withoutAffectingBackButton) {
observableHistory.replace(url);
} else {
observableHistory.push(url);
}
});
};
},
injectionToken: navigateToUrlInjectionToken,
});
export default navigateToUrlInjectable;