show a warning when there are no permissions

This commit is contained in:
Dima Gerasimov 2020-02-08 15:08:10 +00:00 committed by Dmitrii Gerasimov
parent 3b093a68b2
commit c4306ca740
3 changed files with 37 additions and 8 deletions

View file

@ -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';
});
});
}

View file

@ -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 = {

View file

@ -10,9 +10,14 @@
</style>
</head>
<body>
<label for="endpoint_id">Endpoint</label>
<div><input type="URL" id="endpoint_id"/></div>
<label for="notification_id">Notification after capturing</label>
<fieldset>
<legend>Endpoint</legend>
<input type='URL' id='endpoint_id'/>
<div id='has_permission_id' style="display: none; color: red">
No permission to access the endpoint. Will request when you press "Save".
</div>
</fieldset>
<label for="notification_id">Notification after capture</label>
<div><input type="checkbox" id="notification_id"/></div>
<label for="default_tags_id">Default tags</label>
<div><input type="text" id="default_tags_id" /></div>