misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
Video button: a free corner instead of covering the page's own control (#421) (#435)
Ahmed Nefzaouidad3af3bc59c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b467911c..a8ec2238 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see### Fixed+- The video download button moves to a free corner instead of covering a control of the page, such as a thumbnail's watch-later button ([#421](https://github.com/anefzaoui/misterdownloadmanager/issues/421)). Dragging it still puts it where you want it.- Crash reports: no report any more when one of the download engine's background tasks panics while MDM is already closing ([#422](https://github.com/anefzaoui/misterdownloadmanager/issues/422)).- Crash reports: a freeze whose window had recovered by the time its dump was taken is reported as a freeze, not as a crash in MDM's own watchdog ([#420](https://github.com/anefzaoui/misterdownloadmanager/issues/420)).- Text in a script outside the interface language (a video title in Bangla, a playlist in Japanese) now shows its letters, instead of boxes: the font for that script is loaded the first time it is needed ([#405](https://github.com/anefzaoui/misterdownloadmanager/issues/405)).diff --git a/ROADMAP.md b/ROADMAP.mdindex f7c38e89..f7adc827 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -13,6 +13,9 @@ Everything below ships together, in version 0.5.0.### Done+- ✅ The video button no longer covers a control of the page (a preview's own button): it takes+ a free corner, and dragging it keeps it where you put it+ ([#421](https://github.com/anefzaoui/misterdownloadmanager/issues/421))- ✅ A background task stopping as MDM closes no longer shows a crash report([#422](https://github.com/anefzaoui/misterdownloadmanager/issues/422))- ✅ A freeze that was over before its dump was taken is reported as a freeze, not a crash in thediff --git a/extension/video.js b/extension/video.jsindex 2b48a3ad..5de69694 100644--- a/extension/video.js+++ b/extension/video.js@@ -132,6 +132,9 @@const isDismissed = (v) => dismissed.has(v) || (v.currentSrc && dismissedSrc.has(v.currentSrc));let allowed = null; // asked once per page: may it show here?let place = { x: 1, y: 0 }; // where on the edge: fractions of the room, top right by default+ let chosen = false; // the user put it where it is (dragged it, on this site): theirs, never moved for a page's control+ let auto = { v: null, at: null, t: 0 }; // the spot found for this video, kept for a moment+ const AUTO_MS = 400;let video = null; // the video it is overlet lastMove = 0;let pointer = { x: -1, y: -1 };@@ -317,12 +320,57 @@ button:focus-visible { outline: 2px solid #2a78d6; outline-offset: -2px; }return { r, w, h, roomX: Math.max(0, r.width - w - 2 * INSET), roomY: Math.max(0, r.height - h - 2 * INSET) };}+ // Is a control of the page under this spot (a viewport rectangle)? What counts is something+ // on top of the video that the user clicks and that is much smaller than the video: a button,+ // a small link, a watch-later or menu button on a preview (#421); a link or layer over the+ // whole video isn't one. On the video itself, and below it, is nothing to cover.+ function onControl(b, video, videoRect) {+ const area = (x) => Math.max(0, x.width) * Math.max(0, x.height);+ const small = (el) => area(el.getBoundingClientRect()) < area(videoRect) / 5;+ const points = [+ [(b.left + b.right) / 2, (b.top + b.bottom) / 2],+ [b.left + 4, b.top + 4],+ [b.right - 4, b.top + 4],+ [b.left + 4, b.bottom - 4],+ [b.right - 4, b.bottom - 4],+ ];+ for (const [x, y] of points) {+ for (const el of document.elementsFromPoint(x, y)) {+ if (el === root) continue;+ if (el === video || el.contains(video)) break;+ const control = el.closest("button, [role=button], a[href], input, select, [onclick]");+ if (control && !control.contains(video) && small(control)) return true;+ if (small(el) && getComputedStyle(el).cursor === "pointer") return true;+ }+ }+ return false;+ }++ // Where it goes now: the place the user gave it, else the default corner, or the next corner+ // free of the page's own controls (a thumbnail's watch-later button at the top right, #421).+ function spot(r, w, h, roomX, roomY) {+ if (chosen) return place;+ const now = Date.now();+ if (auto.v === video && now - auto.t < AUTO_MS) return auto.at;+ let at = place;+ for (const c of [place, { x: 0, y: 0 }, { x: 0, y: 1 }, { x: 1, y: 1 }]) {+ const left = r.left + INSET + c.x * roomX;+ const top = r.top + INSET + c.y * roomY;+ if (!onControl({ left, top, right: left + w, bottom: top + h }, video, r)) {+ at = c;+ break;+ }+ }+ auto = { v: video, at, t: now };+ return at;+ }+function position() {if (!video) return;const { r, w, roomX, roomY } = rects();// A narrow video gets the icon only.pill.classList.toggle("compact", r.width < 360);- const at = dragging ? dragging.at : place;+ const at = dragging ? dragging.at : spot(r, w, pill.offsetHeight || 32, roomX, roomY);const left = r.left + INSET + at.x * roomX;// In the part of the video on screen: one scrolled half out keeps its button in view.const h = pill.offsetHeight || 32;@@ -437,7 +485,10 @@ button:focus-visible { outline: 2px solid #2a78d6; outline-offset: -2px; }if (allowed) {try {const { positions } = await ext.storage.local.get({ positions: {} });- if (positions[host]) place = snap(positions[host]);+ if (positions[host]) {+ place = snap(positions[host]);+ chosen = true;+ }} catch {// Default spot.}@@ -553,9 +604,9 @@ button:focus-visible { outline: 2px solid #2a78d6; outline-offset: -2px; }startX: e.clientX,startY: e.clientY,// Where in the button it was taken.- dx: e.clientX - (r.left + INSET + place.x * roomX),- dy: e.clientY - (r.top + INSET + place.y * roomY),- at: place,+ dx: e.clientX - (r.left + INSET + (chosen ? place : auto.at || place).x * roomX),+ dy: e.clientY - (r.top + INSET + (chosen ? place : auto.at || place).y * roomY),+ at: chosen ? place : auto.at || place,moved: false,};go.setPointerCapture(e.pointerId);@@ -587,6 +638,7 @@ button:focus-visible { outline: 2px solid #2a78d6; outline-offset: -2px; }return;}place = snap(d.at);+ chosen = true;position();lastMove = Date.now();// Remembered per site, not in a private window (it would keep the site's name), and thediff --git a/tools/extension/e2e.mjs b/tools/extension/e2e.mjsindex 9e77479c..b5e6e831 100644--- a/tools/extension/e2e.mjs+++ b/tools/extension/e2e.mjs@@ -16,7 +16,8 @@// The cases (per browser): link (a .zip link, throttled and not), ask (Firefox set to ask what to// do with each new type, as Waterfox is: caught before its dialog, #208), cookie (cookies and referrer// forwarded), names (Content-Disposition), redirect, leadon (a page going to the file by script, #374), form (POST, 303), alt (Alt+click leaves it-// to the browser), opened (a PDF or MP3 the browser would show or play), csp (the video button+// to the browser), opened (a PDF or MP3 the browser would show or play), spot (the video button+// clear of the page's controls, #421), csp (the video button// under a strict CSP), hls (the stream a player loaded), streams (HLS and DASH players handed over// by the button, the right-click menu and the media list, and read by yt-dlp; #155; also with no// .m3u8 or .mpd, served as text/plain or octet-stream, #171), sniffed (#171 without yt-dlp: such@@ -342,6 +343,10 @@ async function chromium(bin, profile, dl, page, ready) {major,evaluate,mouse,+ screenshot: async (file) => {+ const { data } = await cdp.send("Page.captureScreenshot", { format: "png" }, sessionId);+ fs.writeFileSync(file, Buffer.from(data, "base64"));+ },navigate,key,pill,@@ -1557,6 +1562,33 @@ const CASES = {return `styled (${Math.round(pill.h)}px, ${pill.image.slice(0, 15)}...), sent ${address.replace(LAB, "")}`;},+ // The button doesn't sit on a control of the page (#421: a thumbnail's watch-later button at+ // the top right): it moves to a free corner.+ async spot(t) {+ // E2E_SPOT_SHOT: a screenshot of the page with the button shown, for a PR's body.+ const shoot = async () => {+ if (process.env.E2E_SPOT_SHOT && t.session.screenshot) await t.session.screenshot(process.env.E2E_SPOT_SHOT);+ };+ await t.session.navigate(`${LAB}/page?video=${encodeURIComponent("/gen/1M/clip.mp4")}`);+ await t.session.evaluate(`(() => {+ const r = document.querySelector("#video").getBoundingClientRect();+ const c = document.createElement("button");+ c.id = "page-control";+ c.textContent = "x";+ c.style.cssText = "position:fixed;left:" + (r.right - 44) + "px;top:" + (r.top + 4) + "px;width:40px;height:40px;z-index:9";+ document.body.appendChild(c);+ return true;+ })()`);+ const v = await rect(t.session, "#video");+ const b = await hover(t.session, v);+ if (!b) throw new Error("no button over the video");+ await shoot();+ const c = await rect(t.session, "#page-control");+ const overlaps = b.l < c.r && b.r > c.l && b.t < c.b && b.b > c.t;+ if (overlaps) throw new Error(`the button covers the page's control: ${JSON.stringify({ b, c })}`);+ return `at ${Math.round(b.l - v.l)},${Math.round(b.t - v.t)}, clear of the page's control`;+ },+// A player playing a stream (a blob: in the page): the button sends the manifest it loaded.async hls(t) {await t.session.navigate(`${LAB}/page?hls=1`);