Fix broken NoScript dialogs when browser.privatebrowsing.autostart = true (issue#259, thanks foenix for reporting).
This commit is contained in:
parent
c94a80b1c3
commit
cb6f18a5ed
|
@ -23,6 +23,16 @@ var Prompts = (() => {
|
|||
var promptData;
|
||||
var backlog = [];
|
||||
|
||||
Messages.addHandler({
|
||||
getPromptData() { return Prompts.promptData },
|
||||
promptDone(data) {
|
||||
let promptData = promptDataMap.get(data.id);
|
||||
if (promptData) {
|
||||
Object.assign(promptData, data).done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
class WindowManager {
|
||||
async open(data) {
|
||||
promptData = data;
|
||||
|
@ -82,6 +92,8 @@ var Prompts = (() => {
|
|||
}
|
||||
|
||||
var winMan = new WindowManager();
|
||||
var id = 0;
|
||||
var promptDataMap = new Map();
|
||||
var Prompts = {
|
||||
DEFAULTS: {
|
||||
title: "",
|
||||
|
@ -97,7 +109,9 @@ var Prompts = (() => {
|
|||
async prompt(features) {
|
||||
features = Object.assign({}, this.DEFAULTS, features || {});
|
||||
return new Promise((resolve, reject) => {
|
||||
++id;
|
||||
let data = {
|
||||
id,
|
||||
features,
|
||||
result: {
|
||||
button: -1,
|
||||
|
@ -105,6 +119,7 @@ var Prompts = (() => {
|
|||
option: null,
|
||||
},
|
||||
done() {
|
||||
promptDataMap.delete(this.id);
|
||||
this.done = () => {};
|
||||
winMan.close();
|
||||
resolve(this.result);
|
||||
|
@ -116,6 +131,7 @@ var Prompts = (() => {
|
|||
}
|
||||
}
|
||||
};
|
||||
promptDataMap.set(id, data);
|
||||
if (promptData) {
|
||||
backlog.push(data);
|
||||
switch(promptData.features.multiple) {
|
||||
|
|
|
@ -16,6 +16,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||
<script src="/nscl/common/include.js"></script>
|
||||
<script src="/nscl/common/log.js"></script>
|
||||
<script src="/nscl/common/locale.js"></script>
|
||||
<script src="/nscl/common/Messages.js"></script>
|
||||
<script src="/ui/resize_hack.js"></script>
|
||||
<script src="/common/themes.js"></script>
|
||||
</head>
|
||||
|
|
|
@ -20,16 +20,16 @@
|
|||
|
||||
(async () => {
|
||||
document.documentElement.classList.toggle("mobile", !!UA.mobile);
|
||||
window.bg = await browser.runtime.getBackgroundPage();
|
||||
["Prompts"]
|
||||
.forEach(p => window[p] = bg[p]);
|
||||
let data = Prompts.promptData;
|
||||
let data = await Messages.send("getPromptData");
|
||||
debug(data);
|
||||
if (!data) {
|
||||
error("Missing promptData");
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
let done = () => {
|
||||
Messages.send("promptDone", data);
|
||||
}
|
||||
let {title, message, options, checks, buttons} = data.features;
|
||||
|
||||
function labelFor(el, text) {
|
||||
|
@ -99,7 +99,7 @@
|
|||
renderInputs("#checks", checks, "checkbox", "flag");
|
||||
renderInputs("#buttons", buttons, "button", "button");
|
||||
addEventListener("unload", e => {
|
||||
data.done();
|
||||
done();
|
||||
});
|
||||
|
||||
let buttonClicked = e => {
|
||||
|
@ -109,7 +109,7 @@
|
|||
result.option = option && parseInt(option.value);
|
||||
result.checks = [...document.querySelectorAll('#checks [type="checkbox"]:checked')]
|
||||
.map(c => parseInt(c.value));
|
||||
data.done();
|
||||
done();
|
||||
};
|
||||
for (let b of document.querySelectorAll("#buttons button")) {
|
||||
b.addEventListener("click", buttonClicked);
|
||||
|
|
Loading…
Reference in New Issue