mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Open external links in Desktop app with default app for url on OS
- Open external links using the default link handler registered on OS for the link type, e.g http:// -> firefox, mailto: thunderbird etc - Confirm before opening non-http URL using an external app
This commit is contained in:
parent
170bce2c02
commit
4839f2901a
1 changed files with 23 additions and 0 deletions
|
@ -380,6 +380,29 @@ const createWindow = (tab = 'chat.html') => {
|
|||
win.setBackgroundColor('#f5f4f3');
|
||||
win.setHasShadow(true);
|
||||
|
||||
// Open external links in link handler registered on OS (e.g. browser)
|
||||
win.webContents.setWindowOpenHandler(async ({ url }) => {
|
||||
const shouldOpen = { response: 0 };
|
||||
|
||||
if (!url.startsWith('http://')) {
|
||||
// Confirm before opening non-HTTP links
|
||||
const confirmNotice = `Do you want to open this link? It will be handled by an external application.\n\n${url}`;
|
||||
shouldOpen = await dialog.showMessageBox({
|
||||
type: 'question',
|
||||
buttons: ['Yes', 'No'],
|
||||
defaultId: 1,
|
||||
title: 'Confirm',
|
||||
message: confirmNotice,
|
||||
});
|
||||
}
|
||||
|
||||
// If user confirms, let OS link handler open the link in appropriate app
|
||||
if (shouldOpen.response === 0) shell.openExternal(url);
|
||||
|
||||
// Do not open external links within the app
|
||||
return { action: 'deny' };
|
||||
});
|
||||
|
||||
job.start();
|
||||
|
||||
win.loadFile(tab)
|
||||
|
|
Loading…
Reference in a new issue