Skip to content

Commit

Permalink
feat: Open external links in default browser
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Dec 22, 2019
1 parent fe5b6b0 commit d54469f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# electron-im
Electron based multi IM client
# ElectronIM

Free/Libre open source Electron based multi instance messaging (IM) client.

Combine all your IM applications (or whatever you want) in a single browser (Electron) window

## Features

- Multiplatform
- Spellchecker
- Supports any web based IM solution
12 changes: 11 additions & 1 deletion src/tab-manager/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {BrowserView} = require('electron');
const {BrowserView, shell} = require('electron');
const settings = require('../settings');
let activeTab = null;
const tabs = {};
Expand All @@ -7,11 +7,21 @@ const webPreferences = {
preload: `${__dirname}/preload.js`
};

const handleRedirect = currentUrl => (e, url) => {
if (url !== currentUrl) {
e.preventDefault();
shell.openExternal(url);
}
};

const addTabs = ipcSender => tabsMetadata => {
tabsMetadata.forEach(({id, url}) => {
const tab = new BrowserView({webPreferences});
tab.setAutoResize({width: true, height: true});
tab.webContents.loadURL(url);
const handleRedirectForCurrentUrl = handleRedirect(tab.webContents.getURL());
tab.webContents.on('will-navigate', handleRedirectForCurrentUrl);
tab.webContents.on('new-window', handleRedirectForCurrentUrl);
tabs[id.toString()] = tab;
});
ipcSender.send('addTabs', tabsMetadata);
Expand Down

0 comments on commit d54469f

Please sign in to comment.