Skip to content

Commit be1d59e

Browse files
Merge pull request #86 from p2plabsxyz/open-link-new-tab
feat: add 'Open Link in New Tab' option to context menu
2 parents ef390d7 + d67c424 commit be1d59e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/context-menu.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,40 @@ export function attachContextMenus(browserWindow, windowManager) {
165165
click: () => clipboard.writeText(params.linkURL),
166166
})
167167
);
168+
menu.append(
169+
new MenuItem({
170+
label: "Open Link in New Tab",
171+
click: () => {
172+
// First, attempt to add the URL as a new tab in the current window
173+
const escapedUrl = params.linkURL.replace(/'/g, "\\'");
174+
175+
browserWindow.webContents
176+
.executeJavaScript(`
177+
const tabBar = document.querySelector('#tabbar');
178+
if (tabBar && typeof tabBar.addTab === 'function') {
179+
tabBar.addTab('${escapedUrl}');
180+
// Indicate success so main process knows no fallback is required
181+
true;
182+
} else {
183+
// Tab bar not available – signal fallback
184+
false;
185+
}
186+
`)
187+
.then((added) => {
188+
if (!added && windowManagerInstance) {
189+
// Fallback: open in new window if tab creation failed
190+
windowManagerInstance.open({ url: params.linkURL });
191+
}
192+
})
193+
.catch((err) => {
194+
console.error('Failed to add tab from context menu:', err);
195+
if (windowManagerInstance) {
196+
windowManagerInstance.open({ url: params.linkURL });
197+
}
198+
});
199+
},
200+
})
201+
);
168202
menu.append(
169203
new MenuItem({
170204
label: "Open Link in New Window",

0 commit comments

Comments
 (0)