Open External Links in Default Browser #35
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since Electron apps are showing webpages that you make they can also show other webpages that you link to in your app. If they're not actually a part of your app, you may prefer them to open up in the user's default browser.
That's what we're gonna do. In various places I link out to other GitHub or Git resources. Those will now open outside of the Git-it app and in the user's browser.
To do this we use the
shell
module and the method it has,openExternal
, which takes in a url. You can read more about it on the documentation page forshell
in Electron.So in the template for each page,
layout.hbs
(and in theindex.html
) we require the script that we'll use to handle these external links:Note: I do this a couple of different ways in the app right now and will clean it up later 😁
Then in that script we wait until the page is loaded and loop through each of its links. We see if the link includes a
http
, meaning it's an external link, not a relative link (e.g.../.../file.html
) to another Git-it file.With each external link we find we add a click event that uses
shell
to open the link in the browser.Here's the rest of that code.
Fixes #7