open external links (github) in browser

This commit is contained in:
Kesku 2025-06-23 13:41:16 +01:00
parent 0610aac84c
commit f32378be45
1 changed files with 17 additions and 0 deletions

View File

@ -125,4 +125,21 @@ app.on('web-contents-created', (event, contents) => {
contents.on('new-window', (event, navigationUrl) => {
event.preventDefault();
});
contents.setWindowOpenHandler(({ url }) => {
const { shell } = require('electron');
if (url.startsWith('http://') || url.startsWith('https://')) {
shell.openExternal(url);
return { action: 'deny' };
}
return { action: 'allow' };
});
contents.on('will-navigate', (event, url) => {
if (url.startsWith('http://') || url.startsWith('https://')) {
event.preventDefault();
const { shell } = require('electron');
shell.openExternal(url);
}
});
});