Start using promise apis

This commit is contained in:
Dima Gerasimov 2019-12-09 23:56:57 +00:00
parent 8b6069db43
commit becc43863c
2 changed files with 33 additions and 0 deletions

View file

@ -12,3 +12,27 @@ export function showNotification(text: string, priority: number=0) {
'iconUrl': 'unicorn.png', 'iconUrl': 'unicorn.png',
}); });
} }
// $FlowFixMe
export function awrap(fn, ...args: Array<any>): Promise<any> {
return new Promise((resolve, reject) => {
const cbb = (...xxx) => {
const err = chrome.runtime.lastError;
if (err) {
reject(err);
}
resolve(...xxx);
};
// ugh. can't pass proper typed args down to chrome interfaces?
// $FlowFixMe
fn(...args, cbb);
});
}
export function chromePermissionsRequest(params: any) {
return awrap(chrome.permissions.request, params);
}
export function chromePermissionsContains(params: any) {
return awrap(chrome.permissions.contains, params);
}

View file

@ -25,3 +25,12 @@ export function set_options(opts: Options, cb: () => void) {
console.log('Saving %s', JSON.stringify(opts)); console.log('Saving %s', JSON.stringify(opts));
chrome.storage.local.set(opts, cb); chrome.storage.local.set(opts, cb);
} }
export function getOptions(): Promise<Options> {
return new Promise((resolve) => {
// TODO FIXME reject?
get_options(resolve);
});
}