Introduce and use "openBrowser" (#4876)

Co-authored-by: Steven Johnstone <sjohntone@mirantis.com>
This commit is contained in:
Steven JohnstoneandSteven Johnstone authored and GitHub committed 2022-02-17 08:37:34 -05:00
1 parent 8088d3b5c2
commit 625b00c247
7 files changed
+46 -21

No files matched your search

+1 -1
View File
@@ -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";
+29
View File
@@ -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;
-11
View File
@@ -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);
}