From ff6699d58534a982b91375177106115e717233ac Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 8 Feb 2020 15:13:03 +0000 Subject: [PATCH] Display permission status for the endpoint --- src/js/options_page.js | 30 +++++++++++++++++++----------- src/js/permissions.js | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/js/options_page.js b/src/js/options_page.js index 8db7010..85ee071 100644 --- a/src/js/options_page.js +++ b/src/js/options_page.js @@ -31,22 +31,28 @@ function getHasPermission(): HTMLElement { return ((document.getElementById(HAS_PERMISSION_ID): any): HTMLElement); } +// ugh. needs a better name.. +function refreshPermissionValidation(endpoint: string) { + hasPermissions(endpoint).then(has => { + const pstyle = getHasPermission().style; + if (has) { + console.debug('Got permisssions, nothing to worry about.'); + pstyle.display = 'none'; + return; + } + console.debug('Whoops, no permissions to access %s', endpoint); + // TODO maybe just show button? but then it would need to be reactive.. + pstyle.display = 'block'; + }); +} + function restoreOptions() { get_options(opts => { const ep = opts.endpoint; getEndpoint().value = ep; getDefaultTags().value = opts.default_tags; getEnableNotification().checked = opts.notification; - - hasPermissions(ep).then(has => { - if (has) { - console.debug('Got permisssions already, nothing to worry about.'); - return; - } - console.debug('Whoops, no permissions to access %s', ep); - // TODO maybe just show button? but then it would need to be reactive.. - getHasPermission().style.display = 'block'; - }); + refreshPermissionValidation(ep); }); } @@ -54,7 +60,9 @@ function saveOptions() { // TODO could also check for permissions and display message? const endpoint = getEndpoint().value; - ensurePermissions(endpoint); + ensurePermissions(endpoint).finally(() => { + refreshPermissionValidation(endpoint); + }); const opts = { endpoint: endpoint, diff --git a/src/js/permissions.js b/src/js/permissions.js index fa800cd..10f4a99 100644 --- a/src/js/permissions.js +++ b/src/js/permissions.js @@ -39,7 +39,7 @@ export function ensurePermissions(endpoint: string) { ], }; // shouldn't prompt if we already have the permission - chromePermissionsRequest(perms); + return chromePermissionsRequest(perms); } // just keeping the old one for the reference...