mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
- This fixes a runtime error that was encountered during testing Signed-off-by: Sebastian Malton <sebastian@malton.name>
38 lines
1.3 KiB
TypeScript
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;
|