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 = { 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 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserAction
browserAction: { browserAction: {
setBadgeBackgroundColor: promisifyNoFail(chrome.browserAction, 'setBadgeBackgroundColor'), setBadgeBackgroundColor: promisifyNoFail(chrome.browserAction, 'setBadgeBackgroundColor'),

View File

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