1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

Prevent popup panel to close when forcing a tab reload

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/672

Additionally, this commit add the ability to press F5 to
force a reload while the popup panel is opened.
This commit is contained in:
Raymond Hill 2019-07-21 11:50:15 -04:00
parent 48347897ad
commit 066440534d
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 40 additions and 21 deletions

View File

@ -338,10 +338,10 @@ vAPI.Tabs = class {
get(tabId, callback) { get(tabId, callback) {
if ( tabId === null ) { if ( tabId === null ) {
chrome.tabs.query( browser.tabs.query(
{ active: true, currentWindow: true }, { active: true, currentWindow: true },
tabs => { tabs => {
void chrome.runtime.lastError; void browser.runtime.lastError;
callback( callback(
Array.isArray(tabs) && tabs.length !== 0 Array.isArray(tabs) && tabs.length !== 0
? tabs[0] ? tabs[0]
@ -358,8 +358,8 @@ vAPI.Tabs = class {
return; return;
} }
chrome.tabs.get(tabId, function(tab) { browser.tabs.get(tabId, function(tab) {
void chrome.runtime.lastError; void browser.runtime.lastError;
callback(tab); callback(tab);
}); });
} }
@ -541,21 +541,21 @@ vAPI.Tabs = class {
targetURL = vAPI.getURL(targetURL); targetURL = vAPI.getURL(targetURL);
} }
chrome.tabs.update(tabId, { url: targetURL }, vAPI.resetLastError); browser.tabs.update(tabId, { url: targetURL }, vAPI.resetLastError);
} }
remove(tabId) { remove(tabId) {
tabId = toChromiumTabId(tabId); tabId = toChromiumTabId(tabId);
if ( tabId === 0 ) { return; } if ( tabId === 0 ) { return; }
chrome.tabs.remove(tabId, vAPI.resetLastError); browser.tabs.remove(tabId, vAPI.resetLastError);
} }
reload(tabId, bypassCache = false) { reload(tabId, bypassCache = false) {
tabId = toChromiumTabId(tabId); tabId = toChromiumTabId(tabId);
if ( tabId === 0 ) { return; } if ( tabId === 0 ) { return; }
chrome.tabs.reload( browser.tabs.reload(
tabId, tabId,
{ bypassCache: bypassCache === true }, { bypassCache: bypassCache === true },
vAPI.resetLastError vAPI.resetLastError
@ -566,26 +566,33 @@ vAPI.Tabs = class {
tabId = toChromiumTabId(tabId); tabId = toChromiumTabId(tabId);
if ( tabId === 0 ) { return; } if ( tabId === 0 ) { return; }
chrome.tabs.update(tabId, { active: true }, function(tab) { browser.tabs.update(tabId, { active: true }, function(tab) {
void chrome.runtime.lastError; void browser.runtime.lastError;
if ( !tab ) { return; } if ( !tab ) { return; }
if ( chrome.windows instanceof Object === false ) { return; } if ( browser.windows instanceof Object === false ) { return; }
chrome.windows.update(tab.windowId, { focused: true }); browser.windows.update(tab.windowId, { focused: true });
}); });
} }
injectScript(tabId, details, callback) { injectScript(tabId, details, callback) {
const onScriptExecuted = function() { const onScriptExecuted = function() {
// https://code.google.com/p/chromium/issues/detail?id=410868#c8 // https://code.google.com/p/chromium/issues/detail?id=410868#c8
void chrome.runtime.lastError; void browser.runtime.lastError;
if ( typeof callback === 'function' ) { if ( typeof callback === 'function' ) {
callback.apply(null, arguments); callback.apply(null, arguments);
} }
}; };
if ( tabId ) { if ( tabId ) {
chrome.tabs.executeScript(toChromiumTabId(tabId), details, onScriptExecuted); browser.tabs.executeScript(
toChromiumTabId(tabId),
details,
onScriptExecuted
);
} else { } else {
chrome.tabs.executeScript(details, onScriptExecuted); browser.tabs.executeScript(
details,
onScriptExecuted
);
} }
} }

View File

@ -25,7 +25,7 @@
/******************************************************************************/ /******************************************************************************/
(function() { (( ) => {
/******************************************************************************/ /******************************************************************************/
@ -894,22 +894,35 @@ const reloadTab = function(ev) {
{ {
what: 'reloadTab', what: 'reloadTab',
tabId: popupData.tabId, tabId: popupData.tabId,
select: true, select: vAPI.webextFlavor.soup.has('mobile'),
bypassCache: ev.ctrlKey || ev.metaKey || ev.shiftKey bypassCache: ev.ctrlKey || ev.metaKey || ev.shiftKey
} }
); );
// Polling will take care of refreshing the popup content // Polling will take care of refreshing the popup content
// https://github.com/chrisaljoudi/uBlock/issues/748 // https://github.com/chrisaljoudi/uBlock/issues/748
// User forces a reload, assume the popup has to be updated regardless if // User forces a reload, assume the popup has to be updated regardless
// there were changes or not. // if there were changes or not.
popupData.contentLastModified = -1; popupData.contentLastModified = -1;
// No need to wait to remove this. // No need to wait to remove this.
uDom('body').toggleClass('dirty', false); uDom('body').toggleClass('dirty', false);
}; };
uDom('#refresh').on('click', reloadTab);
// https://github.com/uBlockOrigin/uBlock-issues/issues/672
document.addEventListener(
'keydown',
ev => {
if ( ev.code !== 'F5' ) { return; }
reloadTab(ev);
ev.preventDefault();
ev.stopPropagation();
},
{ capture: true }
);
/******************************************************************************/ /******************************************************************************/
const toggleMinimize = function(ev) { const toggleMinimize = function(ev) {
@ -1121,7 +1134,7 @@ const onHideTooltip = function() {
// Popup DOM is assumed to be loaded at this point -- because this script // Popup DOM is assumed to be loaded at this point -- because this script
// is loaded after everything else.. // is loaded after everything else..
(function() { (( ) => {
// If there's no tab id specified in the query string, // If there's no tab id specified in the query string,
// it will default to current tab. // it will default to current tab.
let tabId = null; let tabId = null;
@ -1138,7 +1151,6 @@ uDom('#switch').on('click', toggleNetFilteringSwitch);
uDom('#gotoZap').on('click', gotoZap); uDom('#gotoZap').on('click', gotoZap);
uDom('#gotoPick').on('click', gotoPick); uDom('#gotoPick').on('click', gotoPick);
uDom('h2').on('click', toggleFirewallPane); uDom('h2').on('click', toggleFirewallPane);
uDom('#refresh').on('click', reloadTab);
uDom('.hnSwitch').on('click', toggleHostnameSwitch); uDom('.hnSwitch').on('click', toggleHostnameSwitch);
uDom('#saveRules').on('click', saveFirewallRules); uDom('#saveRules').on('click', saveFirewallRules);
uDom('#revertRules').on('click', revertFirewallRules); uDom('#revertRules').on('click', revertFirewallRules);