Commit 7afaae72 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Options Page] Provide feedback when permission was already granted

It's a little awkward having a link "additional permissions"
that does nothing when the permission was already granted.

Instead, check for the permission and show a "You have already
granted this permission." messsage, for which we conveniently
already have a string from the request page.
parent 9d5930e9
......@@ -90,7 +90,7 @@
<label>
<input type="checkbox" data-extension="historyrunner" data-settings-key="enabled"> <span data-i18n="options_plugin_historyrunner_title">I18N</span>
</label>
<p data-i18n="options_plugin_historyrunner_description, request-permission-history, #" data-i18n-html="true">I18N</p>
<p id="historyrunner-description" data-i18n="options_plugin_historyrunner_description, request-permission-history, #" data-i18n-html="true">I18N</p>
</li>
<li data-requires-extension="purpose">
<label>
......
......@@ -151,6 +151,16 @@ function updateDependencies(control, extension, settingsKey) {
}
}
function hasPermission(permission) {
return new Promise((resolve, reject) => {
chrome.permissions.contains({
permissions: [permission]
}, (result) => {
resolve(result);
});
});
}
function askPermission(permission) {
return new Promise((resolve, reject) => {
chrome.permissions.request({
......@@ -262,7 +272,15 @@ versionInfo.host);
});
document.getElementById("request-permission-history").addEventListener("click", (e) => {
askPermission("history");
hasPermission("history").then((granted) => {
if (granted) {
document.getElementById("historyrunner-description").innerText = chrome.i18n.getMessage("permission_request_already");
return;
}
return askPermission("history");
});
e.preventDefault();
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment