Skip to content

Commit 11191c3

Browse files
jonathanlabclaude
andauthored
fix: open external links in default browser (#26)
Co-authored-by: Claude <[email protected]>
1 parent 2859297 commit 11191c3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
BrowserWindow,
88
Menu,
99
type MenuItemConstructorOptions,
10+
shell,
1011
} from "electron";
1112
import { registerAgentIpc, type TaskController } from "./services/agent.js";
1213
import { registerOsIpc } from "./services/os.js";
@@ -36,6 +37,21 @@ function ensureClaudeConfigDir(): void {
3637
process.env.CLAUDE_CONFIG_DIR = claudeDir;
3738
}
3839

40+
function setupExternalLinkHandlers(window: BrowserWindow): void {
41+
window.webContents.setWindowOpenHandler(({ url }) => {
42+
shell.openExternal(url);
43+
return { action: "deny" };
44+
});
45+
46+
window.webContents.on("will-navigate", (event, url) => {
47+
const appUrl = isDev ? "http://localhost:5173" : "file://";
48+
if (!url.startsWith(appUrl)) {
49+
event.preventDefault();
50+
shell.openExternal(url);
51+
}
52+
});
53+
}
54+
3955
function createWindow(): void {
4056
mainWindow = new BrowserWindow({
4157
width: 900,
@@ -57,6 +73,8 @@ function createWindow(): void {
5773
mainWindow?.show();
5874
});
5975

76+
setupExternalLinkHandlers(mainWindow);
77+
6078
// Set up menu for keyboard shortcuts
6179
const template: MenuItemConstructorOptions[] = [
6280
{

0 commit comments

Comments
 (0)