Add advanced reload and history clearing features
Introduces hard reload and fresh reload buttons to the UI, allowing users to reload pages while ignoring cache or with a cache-busting parameter. Refactors session and browser data clearing logic to handle multiple sessions and resets history JSON files. Adds per-section clear buttons for site and search history in settings, improving user control over stored data.
This commit is contained in:
@@ -51,6 +51,8 @@
|
||||
<span id="zoom-percent">100%</span>
|
||||
<button id="zoom-in-btn">+</button>
|
||||
</div>
|
||||
<button id="hard-reload-btn">Hard Reload (Ignore Cache)</button>
|
||||
<button id="fresh-reload-btn">Reload Fresh (Add Cache-Buster)</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -674,6 +674,30 @@ function reload() {
|
||||
}
|
||||
}
|
||||
|
||||
function hardReload() {
|
||||
const webview = document.getElementById(`tab-${activeTabId}`);
|
||||
if (webview && typeof webview.reloadIgnoringCache === 'function') {
|
||||
webview.reloadIgnoringCache();
|
||||
scheduleUpdateNavButtons();
|
||||
} else if (webview) {
|
||||
// Fallback
|
||||
webview.reload();
|
||||
}
|
||||
}
|
||||
|
||||
function freshReload() {
|
||||
const webview = document.getElementById(`tab-${activeTabId}`);
|
||||
if (!webview) return;
|
||||
try {
|
||||
const u = new URL(webview.getURL());
|
||||
u.searchParams.set('_bust', Date.now().toString());
|
||||
webview.src = u.toString();
|
||||
} catch {
|
||||
// If URL parsing fails (e.g., internal pages), fall back to hard reload
|
||||
hardReload();
|
||||
}
|
||||
}
|
||||
|
||||
// Function to open the Settings page
|
||||
function openSettings() {
|
||||
createTab('browser://settings');
|
||||
@@ -776,6 +800,10 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
// only now bind the reload button (guaranteed to exist)
|
||||
const reloadBtn = document.getElementById('reload-btn');
|
||||
reloadBtn.addEventListener('click', reload);
|
||||
const hardReloadBtn = document.getElementById('hard-reload-btn');
|
||||
if (hardReloadBtn) hardReloadBtn.addEventListener('click', hardReload);
|
||||
const freshReloadBtn = document.getElementById('fresh-reload-btn');
|
||||
if (freshReloadBtn) freshReloadBtn.addEventListener('click', freshReload);
|
||||
|
||||
// bind zoom buttons (single binding)
|
||||
const zoomInBtn = document.getElementById('zoom-in-btn');
|
||||
|
||||
+42
-14
@@ -1,13 +1,7 @@
|
||||
// Try to get ipcRenderer, but don't fail if it's not available
|
||||
let ipcRenderer = null;
|
||||
try {
|
||||
if (typeof require !== 'undefined') {
|
||||
const electron = require('electron');
|
||||
ipcRenderer = electron.ipcRenderer;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('[SETTINGS] Electron IPC not available, some features may be limited');
|
||||
}
|
||||
// Prefer contextBridge-exposed API
|
||||
const ipc = (window.electronAPI && typeof window.electronAPI.invoke === 'function')
|
||||
? window.electronAPI
|
||||
: null;
|
||||
|
||||
let clearBtn = document.getElementById('clear-data-btn');
|
||||
const statusDiv = document.getElementById('status');
|
||||
@@ -39,14 +33,18 @@ function attachClearHandler(btn) {
|
||||
btn.onclick = async () => {
|
||||
if (statusDiv && statusText) {
|
||||
statusDiv.classList.remove('hidden');
|
||||
statusText.textContent = 'Clearing all browser data...';
|
||||
statusText.textContent = 'Clearing cookies, storage, cache, and history...';
|
||||
}
|
||||
|
||||
try {
|
||||
if (ipcRenderer) {
|
||||
const ok = await ipcRenderer.invoke('clear-browser-data');
|
||||
if (ipc) {
|
||||
const ok = await ipc.invoke('clear-browser-data');
|
||||
// Also clear localStorage site history in this context
|
||||
try { localStorage.removeItem('siteHistory'); } catch {}
|
||||
// Try to refresh lists if present
|
||||
try { if (typeof loadHistories === 'function') await loadHistories(); } catch {}
|
||||
showStatus(ok
|
||||
? 'All browser data and bookmarks cleared!'
|
||||
? 'All browser data cleared.'
|
||||
: 'Failed to clear browser data.');
|
||||
} else {
|
||||
showStatus('Clear data feature not available in this context.');
|
||||
@@ -70,6 +68,36 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
clearBtn = document.getElementById('clear-data-btn');
|
||||
attachClearHandler(clearBtn);
|
||||
}
|
||||
|
||||
// Wire per-section clear buttons to main when possible
|
||||
const clearSiteBtn = document.getElementById('clear-site-history-btn');
|
||||
if (clearSiteBtn) {
|
||||
clearSiteBtn.addEventListener('click', async () => {
|
||||
try {
|
||||
// Clear localStorage copy
|
||||
try { localStorage.removeItem('siteHistory'); } catch {}
|
||||
// Ask main to clear file-based history for consistency
|
||||
if (ipc) { await ipc.invoke('clear-site-history'); }
|
||||
showStatus('Site history cleared');
|
||||
try { if (typeof loadHistories === 'function') await loadHistories(); } catch {}
|
||||
} catch (e) {
|
||||
console.error('Clear site history error:', e);
|
||||
showStatus('Failed clearing site history');
|
||||
}
|
||||
});
|
||||
}
|
||||
const clearSearchBtn = document.getElementById('clear-search-history-btn');
|
||||
if (clearSearchBtn) {
|
||||
clearSearchBtn.addEventListener('click', async () => {
|
||||
try {
|
||||
if (ipc) { await ipc.invoke('clear-search-history'); }
|
||||
showStatus('Search history cleared');
|
||||
} catch (e) {
|
||||
console.error('Clear search history error:', e);
|
||||
showStatus('Failed clearing search history');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Tabs: simple controller
|
||||
|
||||
Reference in New Issue
Block a user