From c4306ca740d380592a71614f2101edecdc927f12 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 8 Feb 2020 15:08:10 +0000 Subject: [PATCH] show a warning when there are no permissions --- src/js/options_page.js | 26 +++++++++++++++++++++----- src/js/permissions.js | 8 ++++++++ src/options.html | 11 ++++++++--- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/js/options_page.js b/src/js/options_page.js index 63392b7..8db7010 100644 --- a/src/js/options_page.js +++ b/src/js/options_page.js @@ -1,10 +1,11 @@ /* @flow */ import {get_options, set_options} from './options'; -import {ensurePermissions} from './permissions'; +import {ensurePermissions, hasPermissions} from './permissions'; -const ENDPOINT_ID = 'endpoint_id'; -const NOTIFICATION_ID = 'notification_id'; -const DEFAULT_TAGS_ID = 'default_tags_id'; +const ENDPOINT_ID = 'endpoint_id'; +const HAS_PERMISSION_ID = 'has_permission_id'; +const NOTIFICATION_ID = 'notification_id'; +const DEFAULT_TAGS_ID = 'default_tags_id'; // TODO specify capture path here? const SAVE_ID = 'save_id'; @@ -26,11 +27,26 @@ function getSaveButton(): HTMLInputElement { return ((document.getElementById(SAVE_ID): any): HTMLInputElement); } +function getHasPermission(): HTMLElement { + return ((document.getElementById(HAS_PERMISSION_ID): any): HTMLElement); +} + function restoreOptions() { get_options(opts => { - getEndpoint().value = opts.endpoint; + 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'; + }); }); } diff --git a/src/js/permissions.js b/src/js/permissions.js index c616499..fa800cd 100644 --- a/src/js/permissions.js +++ b/src/js/permissions.js @@ -23,6 +23,14 @@ function urlForPermissionsCheck(url: string): string { return u.toString(); } +export function hasPermissions(endpoint: string) { + const perms = { + origins: [ + urlForPermissionsCheck(endpoint), + ], + }; + return chromePermissionsContains(perms); +} export function ensurePermissions(endpoint: string) { const perms = { diff --git a/src/options.html b/src/options.html index 9d31fc5..8b12c4b 100644 --- a/src/options.html +++ b/src/options.html @@ -10,9 +10,14 @@ - -
- +
+ Endpoint + + +
+