From 94dfe682c638e09dae9d5040aa78da65c92d3de6 Mon Sep 17 00:00:00 2001 From: Ilia Miheev Date: Sat, 6 Jun 2026 00:58:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B5=20=D1=81=D1=81=D1=8B?= =?UTF-8?q?=D0=BB=D0=BE=D0=BA=20=D0=B2=20=D0=B1=D1=80=D0=B0=D1=83=D0=B7?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=20=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 070a946..d274e22 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,4 @@ -import { app, BrowserWindow } from 'electron'; +import { app, BrowserWindow, shell } from 'electron'; import path from 'node:path'; import started from 'electron-squirrel-startup'; @@ -7,6 +7,38 @@ if (started) { app.quit(); } +function isAppNavigation(url) { + if (MAIN_WINDOW_VITE_DEV_SERVER_URL && url.startsWith(MAIN_WINDOW_VITE_DEV_SERVER_URL)) { + return true; + } + + return url.startsWith('file://'); +} + +function openExternalLink(url) { + shell.openExternal(url).catch((error) => { + console.error('Failed to open external link:', url, error); + }); +} + +function configureExternalLinks(mainWindow) { + mainWindow.webContents.setWindowOpenHandler(({ url }) => { + openExternalLink(url); + return { action: 'deny' }; + }); + + mainWindow.webContents.on('will-navigate', (event, url) => { + if (isAppNavigation(url)) { + return; + } + + if (url.startsWith('http://') || url.startsWith('https://')) { + event.preventDefault(); + openExternalLink(url); + } + }); +} + const createWindow = () => { const { screen } = require('electron'); const primaryDisplay = screen.getPrimaryDisplay(); @@ -22,6 +54,7 @@ const createWindow = () => { }); mainWindow.setMenuBarVisibility(false); mainWindow.maximize(); + configureExternalLinks(mainWindow); // and load the index.html of the app. if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {