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 = {
|
vAPI.localStorage = {
|
||||||
start: function() {
|
start: function() {
|
||||||
|
if ( this.cache instanceof Promise ) { return this.cache; }
|
||||||
if ( this.cache instanceof Object ) { return Promise.resolve(); }
|
if ( this.cache instanceof Object ) { return Promise.resolve(); }
|
||||||
if ( this.promise !== undefined ) { return this.promise; }
|
const onChanged = (changes, area) => {
|
||||||
this.promise = new Promise(resolve => {
|
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 => {
|
browser.storage.local.get('localStorage', bin => {
|
||||||
|
this.cache = undefined;
|
||||||
if (
|
if (
|
||||||
bin instanceof Object === false ||
|
bin instanceof Object === false ||
|
||||||
bin.localStorage instanceof Object === false
|
bin.localStorage instanceof Object === false
|
||||||
@ -255,22 +267,15 @@ vAPI.localStorage = {
|
|||||||
if ( this.cache instanceof Object === false ) {
|
if ( this.cache instanceof Object === false ) {
|
||||||
this.cache = {};
|
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();
|
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() {
|
clear: function() {
|
||||||
this.cache = {};
|
this.cache = {};
|
||||||
@ -295,11 +300,11 @@ vAPI.localStorage = {
|
|||||||
},
|
},
|
||||||
setItem: function(key, value = undefined) {
|
setItem: function(key, value = undefined) {
|
||||||
return this.start().then(( ) => {
|
return this.start().then(( ) => {
|
||||||
|
if ( value === this.cache[key] ) { return; }
|
||||||
this.cache[key] = value;
|
this.cache[key] = value;
|
||||||
return browser.storage.local.set({ localStorage: this.cache });
|
return browser.storage.local.set({ localStorage: this.cache });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
promise: undefined,
|
|
||||||
cache: undefined,
|
cache: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
(( ) => {
|
{
|
||||||
|
// >>>>> start of local scope
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@ -82,13 +83,7 @@ const discardUnsavedData = function(synchronous = false) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadDashboardPanel = function(pane = '') {
|
const loadDashboardPanel = function(pane, first) {
|
||||||
if ( pane === '' ) {
|
|
||||||
vAPI.localStorage.getItemAsync('dashboardLastVisitedPane').then(value => {
|
|
||||||
loadDashboardPanel(value !== null ? value : 'settings.html');
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const tabButton = uDom(`[href="#${pane}"]`);
|
const tabButton = uDom(`[href="#${pane}"]`);
|
||||||
if ( !tabButton || tabButton.hasClass('selected') ) { return; }
|
if ( !tabButton || tabButton.hasClass('selected') ) { return; }
|
||||||
const loadPane = ( ) => {
|
const loadPane = ( ) => {
|
||||||
@ -98,6 +93,9 @@ const loadDashboardPanel = function(pane = '') {
|
|||||||
uDom.nodeFromId('iframe').setAttribute('src', pane);
|
uDom.nodeFromId('iframe').setAttribute('src', pane);
|
||||||
vAPI.localStorage.setItem('dashboardLastVisitedPane', pane);
|
vAPI.localStorage.setItem('dashboardLastVisitedPane', pane);
|
||||||
};
|
};
|
||||||
|
if ( first ) {
|
||||||
|
return loadPane();
|
||||||
|
}
|
||||||
const r = discardUnsavedData();
|
const r = discardUnsavedData();
|
||||||
if ( r === false ) { return; }
|
if ( r === false ) { return; }
|
||||||
if ( r === true ) {
|
if ( r === true ) {
|
||||||
@ -122,18 +120,22 @@ vAPI.messaging.send('dashboard', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
resizeFrame();
|
resizeFrame();
|
||||||
loadDashboardPanel();
|
|
||||||
|
|
||||||
window.addEventListener('resize', resizeFrame);
|
vAPI.localStorage.getItemAsync('dashboardLastVisitedPane').then(value => {
|
||||||
uDom('.tabButton').on('click', onTabClickHandler);
|
loadDashboardPanel(value !== null ? value : 'settings.html', true);
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
|
window.addEventListener('resize', resizeFrame);
|
||||||
window.addEventListener('beforeunload', ( ) => {
|
uDom('.tabButton').on('click', onTabClickHandler);
|
||||||
if ( discardUnsavedData(true) ) { return; }
|
|
||||||
event.preventDefault();
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
|
||||||
event.returnValue = '';
|
window.addEventListener('beforeunload', ( ) => {
|
||||||
|
if ( discardUnsavedData(true) ) { return; }
|
||||||
|
event.preventDefault();
|
||||||
|
event.returnValue = '';
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
})();
|
// <<<<< end of local scope
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user