Skip to content

Commit

Permalink
Merge pull request #147 from ente-io/open-external-link-in-browser
Browse files Browse the repository at this point in the history
open non desktop specific URLs in external browser
  • Loading branch information
abhinavkgrd authored Feb 10, 2023
2 parents bb8e575 + 68700db commit fe65252
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
handleDockIconHideOnAutoLaunch,
handleUpdates,
logSystemInfo,
handleExternalLinks,
} from './utils/main';
import { initSentry } from './services/sentry';
import { setupLogging } from './utils/logging';
Expand Down Expand Up @@ -79,6 +80,7 @@ if (!gotTheLock) {
setupIpcComs(tray, mainWindow, watcher);
handleUpdates(mainWindow);
handleDownloads(mainWindow);
handleExternalLinks(mainWindow);
addAllowOriginHeader(mainWindow);
});

Expand Down
11 changes: 11 additions & 0 deletions src/utils/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,14 @@ export function logSystemInfo() {
const osRelease = os.release();
ElectronLog.info({ osName, osRelease, systemVersion });
}

export function handleExternalLinks(mainWindow: BrowserWindow) {
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
if (!url.startsWith(PROD_HOST_URL)) {
require('electron').shell.openExternal(url);
return { action: 'deny' };
} else {
return { action: 'allow' };
}
});
}

0 comments on commit fe65252

Please sign in to comment.