File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff 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" ,
You can’t perform that action at this time.
0 commit comments