mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Fix spurious warning when force-reloading the dashboard
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/905 Additionally, minor changes to avoid spurious errors in browser console.
This commit is contained in:
parent
7634604aa8
commit
c17a9c8a93
@ -230,10 +230,22 @@ vAPI.closePopup = function() {
|
||||
|
||||
vAPI.localStorage = {
|
||||
start: function() {
|
||||
if ( this.cache instanceof Promise ) { return this.cache; }
|
||||
if ( this.cache instanceof Object ) { return Promise.resolve(); }
|
||||
if ( this.promise !== undefined ) { return this.promise; }
|
||||
this.promise = new Promise(resolve => {
|
||||
const onChanged = (changes, area) => {
|
||||
if (
|
||||
area !== 'local' ||
|
||||
changes instanceof Object === false ||
|
||||
changes.localStorage instanceof Object === false
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const newValue = changes.localStorage.newValue;
|
||||
this.cache = newValue instanceof Object ? newValue : {};
|
||||
};
|
||||
this.cache = new Promise(resolve => {
|
||||
browser.storage.local.get('localStorage', bin => {
|
||||
this.cache = undefined;
|
||||
if (
|
||||
bin instanceof Object === false ||
|
||||
bin.localStorage instanceof Object === false
|
||||
@ -255,22 +267,15 @@ vAPI.localStorage = {
|
||||
if ( this.cache instanceof Object === false ) {
|
||||
this.cache = {};
|
||||
}
|
||||
this.promise = undefined;
|
||||
browser.storage.onChanged.addListener((changes, area) => {
|
||||
if (
|
||||
area !== 'local' ||
|
||||
changes instanceof Object === false ||
|
||||
changes.localStorage instanceof Object === false
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const newValue = changes.localStorage.newValue;
|
||||
this.cache = newValue instanceof Object ? newValue : {};
|
||||
});
|
||||
resolve();
|
||||
browser.storage.onChanged.addListener(onChanged);
|
||||
self.addEventListener('beforeunload', ( ) => {
|
||||
this.cache = undefined;
|
||||
browser.storage.onChanged.removeListener(onChanged);
|
||||
});
|
||||
});
|
||||
return this.promise;
|
||||
});
|
||||
return this.cache;
|
||||
},
|
||||
clear: function() {
|
||||
this.cache = {};
|
||||
@ -295,11 +300,11 @@ vAPI.localStorage = {
|
||||
},
|
||||
setItem: function(key, value = undefined) {
|
||||
return this.start().then(( ) => {
|
||||
if ( value === this.cache[key] ) { return; }
|
||||
this.cache[key] = value;
|
||||
return browser.storage.local.set({ localStorage: this.cache });
|
||||
});
|
||||
},
|
||||
promise: undefined,
|
||||
cache: undefined,
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,8 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
(( ) => {
|
||||
{
|
||||
// >>>>> start of local scope
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
@ -82,13 +83,7 @@ const discardUnsavedData = function(synchronous = false) {
|
||||
});
|
||||
};
|
||||
|
||||
const loadDashboardPanel = function(pane = '') {
|
||||
if ( pane === '' ) {
|
||||
vAPI.localStorage.getItemAsync('dashboardLastVisitedPane').then(value => {
|
||||
loadDashboardPanel(value !== null ? value : 'settings.html');
|
||||
});
|
||||
return;
|
||||
}
|
||||
const loadDashboardPanel = function(pane, first) {
|
||||
const tabButton = uDom(`[href="#${pane}"]`);
|
||||
if ( !tabButton || tabButton.hasClass('selected') ) { return; }
|
||||
const loadPane = ( ) => {
|
||||
@ -98,6 +93,9 @@ const loadDashboardPanel = function(pane = '') {
|
||||
uDom.nodeFromId('iframe').setAttribute('src', pane);
|
||||
vAPI.localStorage.setItem('dashboardLastVisitedPane', pane);
|
||||
};
|
||||
if ( first ) {
|
||||
return loadPane();
|
||||
}
|
||||
const r = discardUnsavedData();
|
||||
if ( r === false ) { return; }
|
||||
if ( r === true ) {
|
||||
@ -122,7 +120,9 @@ vAPI.messaging.send('dashboard', {
|
||||
});
|
||||
|
||||
resizeFrame();
|
||||
loadDashboardPanel();
|
||||
|
||||
vAPI.localStorage.getItemAsync('dashboardLastVisitedPane').then(value => {
|
||||
loadDashboardPanel(value !== null ? value : 'settings.html', true);
|
||||
|
||||
window.addEventListener('resize', resizeFrame);
|
||||
uDom('.tabButton').on('click', onTabClickHandler);
|
||||
@ -133,7 +133,9 @@ window.addEventListener('beforeunload', ( ) => {
|
||||
event.preventDefault();
|
||||
event.returnValue = '';
|
||||
});
|
||||
});
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
})();
|
||||
// <<<<< end of local scope
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user