Open site history links in new tab from settings
Site history items in settings are now clickable links that request navigation in a new tab, preserving the settings view. Renderer logic updated to handle 'navigate' events with a 'newTab' option from both webview IPC and postMessage.
This commit is contained in:
+26
-6
@@ -214,7 +214,16 @@ function createTab(inputUrl) {
|
||||
|
||||
// After creating dynamic webview:
|
||||
webview.addEventListener('ipc-message', e => {
|
||||
if (e.channel === 'theme-update') {
|
||||
if (e.channel === 'navigate' && e.args[0]) {
|
||||
const targetUrl = e.args[0];
|
||||
const opts = e.args[1] || {};
|
||||
if (opts.newTab) {
|
||||
createTab(targetUrl);
|
||||
} else {
|
||||
urlBox.value = targetUrl;
|
||||
navigate();
|
||||
}
|
||||
} else if (e.channel === 'theme-update') {
|
||||
const home = document.getElementById('home-webview');
|
||||
if (home) home.send('theme-update', ...e.args);
|
||||
}
|
||||
@@ -658,8 +667,15 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
webviewsEl.addEventListener('ipc-message', (e) => {
|
||||
// Navigation messages from home or other pages
|
||||
if (e.channel === 'navigate' && e.args[0]) {
|
||||
urlBox.value = e.args[0];
|
||||
navigate();
|
||||
const targetUrl = e.args[0];
|
||||
const opts = e.args[1] || {};
|
||||
if (opts.newTab) {
|
||||
// Open in a new tab, leaving settings/home intact
|
||||
createTab(targetUrl);
|
||||
} else {
|
||||
urlBox.value = targetUrl;
|
||||
navigate();
|
||||
}
|
||||
}
|
||||
// Theme update from settings webview
|
||||
if (e.channel === 'theme-update' && e.args[0]) {
|
||||
@@ -669,11 +685,15 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
}
|
||||
});
|
||||
// Fallback: listen for postMessage navigations from home webview
|
||||
// Fallback: listen for postMessage navigations from embedded pages (home/settings)
|
||||
window.addEventListener('message', (event) => {
|
||||
if (event.data && event.data.type === 'navigate' && event.data.url) {
|
||||
urlBox.value = event.data.url;
|
||||
navigate();
|
||||
if (event.data.newTab) {
|
||||
createTab(event.data.url);
|
||||
} else {
|
||||
urlBox.value = event.data.url;
|
||||
navigate();
|
||||
}
|
||||
}
|
||||
});
|
||||
// only now bind the reload button (guaranteed to exist)
|
||||
|
||||
+26
-1
@@ -563,8 +563,33 @@
|
||||
console.log('[SETTINGS DEBUG] Displaying', siteHistory.length, 'site history items');
|
||||
siteHistory.forEach(item => {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = item;
|
||||
li.style.wordBreak = 'break-all';
|
||||
// Create a clickable link that asks host to navigate in a new tab
|
||||
const a = document.createElement('a');
|
||||
a.href = item;
|
||||
a.textContent = item;
|
||||
a.target = '_blank';
|
||||
a.rel = 'noopener noreferrer';
|
||||
a.style.color = 'var(--accent)';
|
||||
a.style.textDecoration = 'none';
|
||||
a.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
// Ask the host to open this URL in a new tab to keep Settings open
|
||||
window.electronAPI.sendToHost('navigate', item, { newTab: true });
|
||||
} else if (window.parent) {
|
||||
// Fallback: postMessage to parent if available
|
||||
window.parent.postMessage({ type: 'navigate', url: item }, '*');
|
||||
} else {
|
||||
// Last resort: open in this webview
|
||||
window.location.href = item;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[SETTINGS DEBUG] Failed to trigger navigation for', item, err);
|
||||
}
|
||||
});
|
||||
li.appendChild(a);
|
||||
siteList.appendChild(li);
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user