lime icon indicating copy to clipboard operation
lime copied to clipboard

Open links using external browser (Electron)

Open hoangdung-qbt opened this issue 4 years ago • 1 comments

Could we add these lines of code to Electron template in order to force the external links to be opened in default browser (not using built-in webview). I did a small test and it worked really well!

ElectronSetup.window.webContents.on('new-window', function(e, url) {
	e.preventDefault();
	require('electron').shell.openExternal(url);
});
ElectronSetup.window.loadURL("file://" + __dirname + "/index.html"); 	

hoangdung-qbt avatar Aug 16 '20 11:08 hoangdung-qbt

Submit a pull request, and someone will take a look.

It would help if you could include a list of pros and cons for the built-in webview. Do people use it often? For people who want to use it, is there another option that lets them continue to use it, and how easy is it to use? (For instance, maybe the answer is to stick to internal links if you don't want to leave the built-in webview. Simple solution, but would it cover all use cases?) The more concerns you address, the easier it'll be to process your pull request.

If you think developers would want both options, consider adding a compiler flag that toggles this block of code.

::if DEFINE_ELECTRON_USE_EXTERNAL_BROWSER::
ElectronSetup.window.webContents.on('new-window', function(e, url) {
	e.preventDefault();
	require('electron').shell.openExternal(url);
});
ElectronSetup.window.loadURL("file://" + __dirname + "/index.html");
::end::

This corresponds to <haxedef name="electronUseExternalBrowser" /> in project.xml. Bit wordy, but at least it's unambiguous.

player-03 avatar Aug 17 '20 04:08 player-03