| const assets = require( '../../lib/assets' ); |
| const Config = require( '../../lib/config' ); |
| const log = require( '../../lib/logger' )( 'desktop:external-links' ); |
|
|
| let targetURL = ''; |
|
|
| module.exports = function ( { view } ) { |
| |
| |
| view.webContents.on( 'new-window', function ( event, url ) { |
| |
| if ( url.includes( 'https://accounts.google.com/o/oauth2/auth' ) ) { |
| return; |
| } |
| |
| const urlToLoad = url.includes( 'about:blank' ) || url === '' ? targetURL : url; |
| log.info( `Navigating to URL: '${ urlToLoad }'` ); |
|
|
| event.preventDefault(); |
| view.webContents.loadURL( urlToLoad ); |
| return; |
| } ); |
|
|
| |
| |
| view.webContents.on( 'will-navigate', function ( event, url ) { |
| if ( url === Config.baseURL() + 'log-in/link' ) { |
| const urlToLoad = 'file://' + assets.getPath( 'magic-links-unsupported.html' ); |
| log.info( `Navigating to URL: '${ urlToLoad }'` ); |
| view.webContents.loadURL( urlToLoad ); |
| } |
|
|
| return; |
| } ); |
|
|
| |
| |
| |
| |
| view.webContents.on( 'update-target-url', function ( event, url ) { |
| targetURL = url; |
| } ); |
|
|
| view.webContents.on( 'will-redirect', function ( _, url ) { |
| if ( url.includes( 'https://wordpress.com/log-in/apple/callback' ) ) { |
| log.info( 'Redirecting to URL: ', url ); |
| view.webContents.loadURL( url ); |
| } |
| } ); |
| }; |
|
|