Forgot Chromium's `alarms` API is not promisified...

This commit is contained in:
Raymond Hill 2024-02-29 20:29:36 -05:00
parent d1fe023281
commit c2c80be897
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 14 additions and 5 deletions

View File

@ -54,6 +54,15 @@ const promisify = function(thisArg, fnName) {
};
const webext = {
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/alarms
alarms: {
clear: promisifyNoFail(chrome.alarms, 'clear'),
clearAll: promisifyNoFail(chrome.alarms, 'clearAll'),
create: promisifyNoFail(chrome.alarms, 'create'),
get: promisifyNoFail(chrome.alarms, 'get'),
getAll: promisifyNoFail(chrome.alarms, 'getAll'),
onAlarm: chrome.alarms.onAlarm,
},
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserAction
browserAction: {
setBadgeBackgroundColor: promisifyNoFail(chrome.browserAction, 'setBadgeBackgroundColor'),

View File

@ -1781,20 +1781,20 @@ vAPI.cloud = (( ) => {
vAPI.alarms = {
create(...args) {
browser.alarms.create(...args);
webext.alarms.create(...args);
},
createIfNotPresent(name, ...args) {
browser.alarms.get(name).then(details => {
webext.alarms.get(name).then(details => {
if ( details !== undefined ) { return; }
browser.alarms.create(name, ...args);
webext.alarms.create(name, ...args);
});
},
async clear(...args) {
return browser.alarms.clear(...args);
return webext.alarms.clear(...args);
},
onAlarm: {
addListener(...args) {
browser.alarms.onAlarm.addListener(...args);
webext.alarms.onAlarm.addListener(...args);
},
},
};