Fixed prompts factory regression on Android.

This commit is contained in:
hackademix 2024-10-20 12:54:36 +02:00
parent acf1ab6a1b
commit 27ad1c4192
No known key found for this signature in database
GPG Key ID: 231A83AFDA9C2434
3 changed files with 27 additions and 30 deletions

View File

@ -39,7 +39,15 @@ var Prompts = (() => {
this.close(); this.close();
let url = browser.runtime.getURL("ui/prompt.html"); let url = browser.runtime.getURL("ui/prompt.html");
if (!("windows" in browser)) {
// Android, most likely
this.currentTab = await browser.tabs.create({url});
return;
}
let {width, height, left, top, parent } = data.features; let {width, height, left, top, parent } = data.features;
let options = { let options = {
url, url,
type: "popup", type: "popup",
@ -53,32 +61,23 @@ var Prompts = (() => {
options.allowScriptsToClose = true; options.allowScriptsToClose = true;
} }
if (!("windows" in browser)) { const centerOnParent = bounds => {
// Android, most likely for (const [p, s] of [["left", "width"], ["top", "height"]]) {
this.currentTab = await browser.tabs.create({url}); if (bounds[s] && bounds[p] === undefined) {
return; bounds[p] = Math.round(parent[p] + (parent[s] - bounds[s]) / 2);
} }
}
const centerOnParent = (dim) => { return bounds;
const { width, height } = dim;
dim.left =
left === undefined
? Math.round(parent.left + (parent.width - width) / 2)
: left;
dim.top =
top === undefined
? Math.round(parent.top + (parent.height - height) / 2)
: top;
return dim;
}; };
if (width && height) { if (width && height) {
let size = { width, height }; const bounds = { width, height, left, top };
url += `?size=${JSON.stringify(size)}`; url += `?winbounds=${JSON.stringify(bounds)}`;
if (parent) { if (parent) {
({ left, top } = Object.assign(options, centerOnParent(size))); ({ left, top } = Object.assign(options, centerOnParent(bounds)));
} }
} }
debug("Prompt pre-opening options", options, left, top, width, height); // DEV_ONLY debug("Prompt pre-opening options", options, left, top, width, height); // DEV_ONLY
let popup = (this.currentWindow = await browser.windows.create(options)); let popup = (this.currentWindow = await browser.windows.create(options));
@ -93,7 +92,7 @@ var Prompts = (() => {
if (top === undefined) ({ top } = popup); if (top === undefined) ({ top } = popup);
} }
debug("Prompt post-opening options", popup, options, left, top, width, height); debug("Prompt post-opening options", popup, options, left, top, width, height); // DEV_ONLY
// work around for resistFingerprinting new window rounding (https://bugzilla.mozilla.org/show_bug.cgi?id=1330882) // work around for resistFingerprinting new window rounding (https://bugzilla.mozilla.org/show_bug.cgi?id=1330882)
if ( if (

View File

@ -139,10 +139,8 @@
await browser.windows.update(win.id, { await browser.windows.update(win.id, {
height: win.height + delta, height: win.height + delta,
top: win.top - Math.round(delta / 2), top: win.top - Math.round(delta / 2),
focused: false
}); });
} }
await browser.windows.update(win.id, {focused: true});
} }
if (document.readyState === "complete") { if (document.readyState === "complete") {
fitHeight(); fitHeight();

View File

@ -24,19 +24,19 @@ if ("windows" in browser) document.addEventListener("DOMContentLoaded", async e
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1402110 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1402110
let win = await browser.windows.getCurrent({populate: true}); let win = await browser.windows.getCurrent({populate: true});
if (win.tabs[0].url === document.URL) { if (win.tabs[0].url === document.URL) {
let size = decodeURIComponent(location.search).match(/\bsize=(\{\s*"width":[^}]+\})/); let bounds = decodeURIComponent(location.href).match(/\bwinbounds=(\{[^}]*"width":[^}]+\})/);
try { try {
size = size && JSON.parse(size[1]); bounds = bounds && JSON.parse(bounds[1]);
} catch (e) { } catch (e) {
size = null; bounds = null;
} }
let {width, height} = size || win; let {width} = bounds || win;
debug("Resize hack", win, size, width, height); // DEV_ONLY debug("Resize hack", win, bounds); // DEV_ONLY
await browser.windows.update(win.id, { await browser.windows.update(win.id, {
width: width + 1, height width: width + 1
}); });
await browser.windows.update(win.id, { await browser.windows.update(win.id, {
width, height width
}); });
} }
}); });