-
Notifications
You must be signed in to change notification settings - Fork 0
/
permissions.js
46 lines (43 loc) · 1.48 KB
/
permissions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import browser from "webextension-polyfill";
import hyper from "hyperhtml";
export const initPermissions = async state => {
try {
const response = await browser.permissions.getAll();
state.permissions = response.permissions;
} catch (err) {
console.error("initPermissions", err);
}
};
export const changePermission = (state, permission, grant) => {
const options = { permissions: [permission] };
return async () => {
state.permissionResponse = "changing permissions ...";
try {
if (grant) {
browser.permissions
.request(options)
.then(() => {
// never called
console.log("browser.permissions.request then");
})
.catch(err => {
// only called if "was not declared in optional_permissions"
state.permissionResponse = `Error: ${err.message}`;
})
.finally(() => {
// only called if "was not declared in optional_permissions"
console.log("browser.permissions.request finally");
});
} else {
await browser.permissions.remove(options);
}
state.permissionResponse = "Call successful.";
} catch (err) {
// Catch the case where the permission is completely wrong.
state.permissionResponse = `Error: ${err.message}`;
}
state.permissions = (await browser.permissions.getAll()).permissions;
};
};
export const renderPermission = permission =>
hyper.wire()`<li>${permission}</li>`;