Display permission status for the endpoint
This commit is contained in:
parent
c4306ca740
commit
ff6699d585
|
@ -31,22 +31,28 @@ function getHasPermission(): HTMLElement {
|
||||||
return ((document.getElementById(HAS_PERMISSION_ID): any): 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() {
|
function restoreOptions() {
|
||||||
get_options(opts => {
|
get_options(opts => {
|
||||||
const ep = opts.endpoint;
|
const ep = opts.endpoint;
|
||||||
getEndpoint().value = ep;
|
getEndpoint().value = ep;
|
||||||
getDefaultTags().value = opts.default_tags;
|
getDefaultTags().value = opts.default_tags;
|
||||||
getEnableNotification().checked = opts.notification;
|
getEnableNotification().checked = opts.notification;
|
||||||
|
refreshPermissionValidation(ep);
|
||||||
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';
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +60,9 @@ function saveOptions() {
|
||||||
// TODO could also check for permissions and display message?
|
// TODO could also check for permissions and display message?
|
||||||
|
|
||||||
const endpoint = getEndpoint().value;
|
const endpoint = getEndpoint().value;
|
||||||
ensurePermissions(endpoint);
|
ensurePermissions(endpoint).finally(() => {
|
||||||
|
refreshPermissionValidation(endpoint);
|
||||||
|
});
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
|
|
|
@ -39,7 +39,7 @@ export function ensurePermissions(endpoint: string) {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
// shouldn't prompt if we already have the permission
|
// shouldn't prompt if we already have the permission
|
||||||
chromePermissionsRequest(perms);
|
return chromePermissionsRequest(perms);
|
||||||
}
|
}
|
||||||
|
|
||||||
// just keeping the old one for the reference...
|
// just keeping the old one for the reference...
|
||||||
|
|
Loading…
Reference in a new issue