Display permission status for the endpoint

This commit is contained in:
Dima Gerasimov 2020-02-08 15:13:03 +00:00 committed by Dmitrii Gerasimov
parent c4306ca740
commit ff6699d585
2 changed files with 20 additions and 12 deletions

View file

@ -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,

View file

@ -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...