mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 16:14:21 +00: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.setBackgroundColor('#f5f4f3');
|
||||||
win.setHasShadow(true);
|
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();
|
job.start();
|
||||||
|
|
||||||
win.loadFile(tab)
|
win.loadFile(tab)
|
||||||
|
|
Loading…
Add table
Reference in a new issue