Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add policy change listener #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,13 @@ vAPI.adminStorage = (( ) => {
return bin[key];
}
return bin;
},
onChanged: function(callback) {
webext.storage.onChanged.addListener((changes, areaName) => {
if ( areaName === 'managed' ) {
callback(changes);
}
});
}
};
})();
Expand Down
5 changes: 5 additions & 0 deletions platform/chromium/webext.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ if ( chrome.storage.sync instanceof Object ) {
};
}

// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/onChanged
if ( chrome.storage.onChanged instanceof Object ) {
webext.storage.onChanged = chrome.storage.onChanged;
}

// https://bugs.chromium.org/p/chromium/issues/detail?id=608854
if ( chrome.tabs.removeCSS instanceof Function ) {
webext.tabs.removeCSS = promisifyNoFail(chrome.tabs, 'removeCSS');
Expand Down
3 changes: 3 additions & 0 deletions src/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ const createDefaultProps = function() {
/******************************************************************************/

try {
// https://github.com/uBlockOrigin/uBlock-issues/issues/1608
vAPI.adminStorage.onChanged(( ) => vAPI.app.restart());

// https://github.com/gorhill/uBlock/issues/531
await µb.restoreAdminSettings();
log.info(`Admin settings ready ${Date.now()-vAPI.T0} ms after launch`);
Expand Down