From becc43863c99f8d77b3056ab875480916f039189 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Mon, 9 Dec 2019 23:56:57 +0000 Subject: [PATCH] Start using promise apis --- src/js/common.js | 24 ++++++++++++++++++++++++ src/js/options.js | 9 +++++++++ 2 files changed, 33 insertions(+) diff --git a/src/js/common.js b/src/js/common.js index 0d15525..3d375de 100644 --- a/src/js/common.js +++ b/src/js/common.js @@ -12,3 +12,27 @@ export function showNotification(text: string, priority: number=0) { 'iconUrl': 'unicorn.png', }); } + +// $FlowFixMe +export function awrap(fn, ...args: Array): Promise { + 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); +} diff --git a/src/js/options.js b/src/js/options.js index ff2f805..7b53c32 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -25,3 +25,12 @@ export function set_options(opts: Options, cb: () => void) { console.log('Saving %s', JSON.stringify(opts)); chrome.storage.local.set(opts, cb); } + + + +export function getOptions(): Promise { + return new Promise((resolve) => { + // TODO FIXME reject? + get_options(resolve); + }); +}