From a50a8298b3c962446ccfcfa8be27b4d045ca3efb Mon Sep 17 00:00:00 2001 From: hackademix Date: Sun, 27 Sep 2020 01:04:13 +0200 Subject: [PATCH] [Mobile] Use tabs as prompts if the browser.windows API is missing. --- src/ui/Prompts.js | 9 ++++++++- src/ui/prompt.css | 39 ++++++++++++++++++++++++--------------- src/ui/prompt.js | 2 ++ src/ui/resize_hack.js | 2 +- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/ui/Prompts.js b/src/ui/Prompts.js index b1d08de..c4763e4 100644 --- a/src/ui/Prompts.js +++ b/src/ui/Prompts.js @@ -1,8 +1,8 @@ var Prompts = (() => { - var promptData; var backlog = []; + class WindowManager { async open(data) { promptData = data; @@ -17,6 +17,11 @@ var Prompts = (() => { if (UA.isMozilla) { options.allowScriptsToClose = true; } + if (!("windows" in browser)) { + // Android, most likely + this.currentTab = await browser.tabs.create({url: options.url}); + return; + } this.currentWindow = await browser.windows.create(options); // work around for https://bugzilla.mozilla.org/show_bug.cgi?id=1330882 let {left, top, width: cw, height: ch} = this.currentWindow; @@ -36,6 +41,8 @@ var Prompts = (() => { debug(e); } this.currentWindow = null; + } else if (this.currentTab) { + await browser.tabs.remove(this.currentTab.id); } } diff --git a/src/ui/prompt.css b/src/ui/prompt.css index 7d9f8a7..5016e8e 100644 --- a/src/ui/prompt.css +++ b/src/ui/prompt.css @@ -1,22 +1,30 @@ +html { + background: linear-gradient(to bottom, #e4f5fc 0%,#bfe8f9 41%,#9fd8ef 90%,#2ab0ed 100%) no-repeat; +} + body { - bottom: 8px; + bottom: .8em; font-family: sans-serif; font-size: 12px; color: #222; margin: 0px; - padding: 8px; - background: linear-gradient(to bottom, #e4f5fc 0%,#bfe8f9 41%,#9fd8ef 90%,#2ab0ed 100%) no-repeat; + padding: .8em; +} + +html.mobile > body { + font-family: Inter, sans-serif; + font-size: 12mm; + min-width: auto; } #header { text-align: left; margin: 0; - line-height: 24px; + line-height: 2em; color: #048; - font-size: 24px; z-index: 500; - padding: 8px 8px 0 8px; + padding: .8em .8em 0 .8em; display: block; background: url(/img/icon96.png) no-repeat top right; height: 96px; @@ -24,7 +32,7 @@ body { #title { margin-right: 96px; - font-size: 24px; + font-size: 1.3em; bottom: 0; top: 0; } @@ -33,7 +41,7 @@ body { display: flex; flex-direction: column; align-items: center; - padding: 0 16px; + padding: 0 1.6em; top: 0; left: 0; right:0; @@ -44,19 +52,19 @@ body { #message { flex-grow: 1; width: 100%; - max-height: 300px; - padding: 8px; + max-height: 28em; + padding: .8em; text-align: center; } #message.multiline { overflow: auto; - font-size: 12px; + font-size: 1em; text-align: justify; - margin-bottom: 16px; + margin-bottom: 1.2em; background: rgba(255,255,255,.5); } #message.multiline p { - margin: 1px; + margin: .1em; padding: 0; } #options { @@ -93,9 +101,10 @@ body { flex-grow: 0; flex-direction: row; align-items: center; - margin: 8px; + margin: .8em; justify-content: space-around; } #buttons button { - min-width: 100px; + min-width: 6em; + font-size: 1em; } diff --git a/src/ui/prompt.js b/src/ui/prompt.js index 7c45065..eb3b9b2 100644 --- a/src/ui/prompt.js +++ b/src/ui/prompt.js @@ -1,4 +1,5 @@ (async () => { + document.documentElement.classList.toggle("mobile", !!UA.isMobile); window.bg = await browser.runtime.getBackgroundPage(); ["Prompts"] .forEach(p => window[p] = bg[p]); @@ -90,6 +91,7 @@ } let resize = async () => { + if (!("windows" in browser)) return; let win = await browser.windows.getCurrent(); let delta = document.documentElement.offsetHeight - window.innerHeight; await browser.windows.update(win.id, { diff --git a/src/ui/resize_hack.js b/src/ui/resize_hack.js index c981e28..09f6a8f 100644 --- a/src/ui/resize_hack.js +++ b/src/ui/resize_hack.js @@ -1,4 +1,4 @@ -document.addEventListener("DOMContentLoaded", async e => { +if ("windows" in browser) document.addEventListener("DOMContentLoaded", async e => { // Fix for Fx57 bug where bundled page loaded using // browser.windows.create won't show contents unless resized. // See https://bugzilla.mozilla.org/show_bug.cgi?id=1402110