mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Make openBrowser->openLinkInBrowser injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of deprecated link matcher API from XtermJS Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 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 loggerInjectable from "../../common/logger.injectable";
|
|
import openLinkInBrowserInjectable from "../../common/utils/open-link-in-browser.injectable";
|
|
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
|
|
import type { ForwardedPort } from "./port-forward-item";
|
|
import { portForwardAddress } from "./port-forward-utils";
|
|
|
|
export type OpenPortForward = (portForward: ForwardedPort) => void;
|
|
|
|
const openPortForwardInjectable = getInjectable({
|
|
id: "open-port-forward",
|
|
instantiate: (di): OpenPortForward => {
|
|
const openLinkInBrowser = di.inject(openLinkInBrowserInjectable);
|
|
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
|
const logger = di.inject(loggerInjectable);
|
|
|
|
return (portForward) => {
|
|
const browseTo = portForwardAddress(portForward);
|
|
|
|
openLinkInBrowser(browseTo)
|
|
.catch(error => {
|
|
logger.error(`failed to open in browser: ${error}`, {
|
|
port: portForward.port,
|
|
kind: portForward.kind,
|
|
namespace: portForward.namespace,
|
|
name: portForward.name,
|
|
});
|
|
showErrorNotification(`Failed to open ${browseTo} in browser`);
|
|
});
|
|
};
|
|
},
|
|
});
|
|
|
|
export default openPortForwardInjectable;
|