Skip to content

Commit

Permalink
feat(Services): Improve handling of external links
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Jan 5, 2018
1 parent f9cb20f commit e2d6edf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/stores/ServicesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ export default class ServicesStore extends Store {
redirect: false,
});
}
} else if (channel === 'new-window') {
const url = args[0];

this.actions.app.openExternalUrl({ url });
}
}

Expand Down
16 changes: 14 additions & 2 deletions src/webview/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import path from 'path';
import { isDevMode } from '../environment';
import RecipeWebview from './lib/RecipeWebview';

import Spellchecker from './spellchecker.js';
import './notifications.js';
import Spellchecker from './spellchecker';
import './notifications';

ipcRenderer.on('initializeRecipe', (e, data) => {
const modulePath = path.join(data.recipe.path, 'webview.js');
Expand Down Expand Up @@ -39,3 +39,15 @@ ipcRenderer.on('settings-update', (e, data) => {
document.addEventListener('DOMContentLoaded', () => {
ipcRenderer.sendToHost('hello');
}, false);

// Patching window.open
const originalWindowOpen = window.open;

window.open = (url, frameName, features) => {
// We need to differentiate if the link should be opened in a popup or in the systems default browser
if (!frameName && !features) {
return ipcRenderer.sendToHost('new-window', url);
}

return originalWindowOpen(url, frameName, features);
};

0 comments on commit e2d6edf

Please sign in to comment.