mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce and use "openBrowser" (#4876)
Co-authored-by: Steven Johnstone <sjohntone@mirantis.com>
This commit is contained in:
1 parent
8088d3b5c2
commit
625b00c247
7 files changed
+46
-21
No files matched your search
@@ -30,7 +30,7 @@ export * from "./getRandId";
|
||||
export * from "./hash-set";
|
||||
export * from "./n-fircate";
|
||||
export * from "./objects";
|
||||
export * from "./openExternal";
|
||||
export * from "./openBrowser";
|
||||
export * from "./paths";
|
||||
export * from "./promise-exec";
|
||||
export * from "./reject-promise";
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { shell } from "electron";
|
||||
|
||||
const allowedProtocols = new Set(["http:", "https:"]);
|
||||
|
||||
/**
|
||||
* Opens a link using the program configured as the default browser
|
||||
* on the target platform. Will reject URLs with a scheme other than
|
||||
* http or https to prevent programs other than the default browser
|
||||
* running.
|
||||
*
|
||||
* @param url The URL to open
|
||||
*/
|
||||
export function openBrowser(url: string): Promise<void> {
|
||||
if (allowedProtocols.has(new URL(url).protocol)) {
|
||||
return shell.openExternal(url);
|
||||
}
|
||||
|
||||
return Promise.reject(new TypeError("not an http(s) URL"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use openBrowser
|
||||
*/
|
||||
export const openExternal = openBrowser;
|
||||
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
// Opens a link in external browser
|
||||
import { shell } from "electron";
|
||||
|
||||
export function openExternal(url: string) {
|
||||
return shell.openExternal(url);
|
||||
}
|
||||
Reference in new issue
Block a user