Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Share logic for opening external links
- Loading branch information
Showing
4 changed files
with
32 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| const { shell } = require('electron'); | ||
| const url = require('url'); | ||
|
|
||
|
|
||
| const protocolRegex = /^https?:/i; | ||
|
|
||
| /** | ||
| * Opens the given link in an external browser. | ||
| * | ||
| * @param {string} link - The link (URL) that should be opened in the external browser. | ||
| * @returns {void} | ||
| */ | ||
| export function openExternalLink(link) { | ||
| let u; | ||
|
|
||
| try { | ||
| u = url.parse(link); | ||
| } catch (e) { | ||
| return; | ||
| } | ||
|
|
||
| if (protocolRegex.test(u.protocol)) { | ||
| shell.openExternal(link); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters