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
Fix video button staying visible after mouse focus (#483)
Atishay Kasliwalcd1b2b55076e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ddc4bc7d..bd1a2d89 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 button fades again after a click on the player, in fullscreen too, and stays while you use the keyboard ([#480](https://github.com/anefzaoui/misterdownloadmanager/issues/480)).- The window no longer freezes when a video or a gallery finishes: marking its files as downloaded from the web, which can wait on the disk and the antivirus for a while with a big video, now happens beside the window ([#510](https://github.com/anefzaoui/misterdownloadmanager/issues/510)).- Linux: **View → Dark Mode support** turns dark on window managers such as Hyprland and sway when only GNOME's setting says so (`gsettings set org.gnome.desktop.interface color-scheme prefer-dark`), as it did when a desktop portal answered ([#324](https://github.com/anefzaoui/misterdownloadmanager/issues/324)).- Dark mode no longer draws a bright white line under the menu bar, across the whole window, in the Classic and Native themes ([#379](https://github.com/anefzaoui/misterdownloadmanager/issues/379)).diff --git a/ROADMAP.md b/ROADMAP.mdindex c97ecbc6..f509c38f 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -519,6 +519,7 @@ These ship in a later version, when they're ready.### Bugs being looked into+- 🔄 The video button staying on screen after a click on the player, in fullscreen too\n ([#480](https://github.com/anefzaoui/misterdownloadmanager/issues/480)): fix in review- 🔄 A freeze when a video finishes, while its file is marked as downloaded from the web([#510](https://github.com/anefzaoui/misterdownloadmanager/issues/510)): fix in review- 🔄 Linux: Dark Mode support on window managers such as Hyprland and sway, which often have nodiff --git a/extension/video.js b/extension/video.jsindex 5de69694..dc35d72d 100644--- a/extension/video.js+++ b/extension/video.js@@ -150,7 +150,8 @@Boolean(shadow.activeElement && shadow.activeElement.matches(":focus-visible")) || playerFocused();let focusedPlayer = null;const playerFocused = () =>- Boolean(video && focusedPlayer && document.activeElement === focusedPlayer && focusedPlayer.contains(video));+ Boolean(video && focusedPlayer && document.activeElement === focusedPlayer &&+ focusedPlayer.contains(video) && focusedPlayer.matches(":focus-visible"));// ---- the button: a closed shadow tree the page's styles and scripts can't reach ----------const root = document.createElement("mdm-video-button");diff --git a/tools/extension/e2e.mjs b/tools/extension/e2e.mjsindex b383d945..450e321a 100644--- a/tools/extension/e2e.mjs+++ b/tools/extension/e2e.mjs@@ -23,7 +23,8 @@// .m3u8 or .mpd, served as text/plain or octet-stream, #171), sniffed (#171 without yt-dlp: such// streams found only when asked, by the button and the media list, a text decoy never), media (the// toolbar button's list of the media a tab loaded: streams, files, a protected stream; #38), video (shown, clicked, dragged,-// kept; "never on the site" in the last browser), start (MDM not running: the host starts it),+// kept; "never on the site" in the last browser), videoFocus (mouse idle/fullscreen and keyboard+// focus, #480), start (MDM not running: the host starts it),// remote (Send downloads to → Another MDM, #157: paired from the popup, a link downloaded by a// headless MDM; E2E_REMOTE_URL for one running elsewhere, such as the Docker image: remoteServer).//@@ -300,7 +301,7 @@ async function chromium(bin, profile, dl, page, ready) {await cdp.send("Input.dispatchMouseEvent", { type: "mouseReleased", ...at, buttons: 0, clickCount: 1 }, sessionId);}};- const KEYS = { ArrowDown: 40, Enter: 13 };+ const KEYS = { ArrowDown: 40, Enter: 13, Tab: 9 };const key = async (k) => {for (const type of ["keyDown", "keyUp"]) {// Enter carries its text, as a real key press does.@@ -480,7 +481,7 @@ async function firefox(bin, profile, dl, page, ready) {await bidi.send("input.performActions", { context, actions: sources });};// WebDriver key codes.- const KEYS = { ArrowDown: "\uE015", Enter: "\uE007" };+ const KEYS = { ArrowDown: "\uE015", Enter: "\uE007", Tab: "\uE004" };const key = (k) =>bidi.send("input.performActions", {context,@@ -945,6 +946,82 @@ const rect = (session, sel) =>if (!e || (e.localName === "mdm-video-button" && e.style.display !== "block")) return null;const r = e.getBoundingClientRect(); return { l: r.left, t: r.top, r: r.right, b: r.bottom }; })()`);+// #480: a mouse-focused player must still fade, including after entering fullscreen. Run+// against a local player so YouTube's network, sign-in and changing layout aren't involved.+export async function videoFocus(session) {+ await session.navigate(`${LAB}/page?video=${encodeURIComponent("/gen/1M/clip.mp4")}`);+ await session.evaluate(`(() => {+ const v = document.querySelector("#video");+ const player = document.createElement("div");+ player.id = "focus-player";+ player.tabIndex = 0;+ player.style.cssText = "width:640px;height:360px;background:#18212d";+ v.before(player);+ player.append(v);+ v.controls = false;+ v.tabIndex = -1;+ v.style.cssText = "width:100%;height:100%;pointer-events:none";+ const after = document.createElement("button");+ after.id = "after-player";+ after.textContent = "After the player";+ player.after(after);+ })()`);+ const focused = (id) => session.evaluate(`document.activeElement?.id === ${JSON.stringify(id)}`);+ const keyboard = () => session.evaluate('document.querySelector("#focus-player").matches(":focus-visible")');+ const shown = () => rect(session, "mdm-video-button");+ const idle = () => sleep(3100); // 2600 ms idle + the 180 ms fade, with room for a slow frame.+ const v = await rect(session, "#video");+ await session.mouse((v.l + v.r) / 2, (v.t + v.b) / 2, "click");+ if (!(await focused("focus-player")) || await keyboard()) throw new Error("player did not receive mouse focus");+ await until("the video button", 5000, shown);+ await idle();+ if (await shown()) throw new Error("#480: mouse focus keeps the video button visible after idle");++ await session.evaluate('document.querySelector("#focus-player").requestFullscreen()');+ if (!(await session.evaluate('document.fullscreenElement?.id === "focus-player"'))) throw new Error("player did not enter fullscreen");+ const fs = await rect(session, "#video");+ await session.mouse((fs.l + fs.r) / 2, (fs.t + fs.b) / 2);+ await until("the fullscreen video button", 5000, shown);+ if (!(await session.evaluate('document.querySelector("mdm-video-button").parentNode === document.fullscreenElement'))) throw new Error("button is outside fullscreen player");+ await idle();+ if (await shown()) throw new Error("#480: mouse focus keeps the fullscreen video button visible after idle");+ await session.evaluate("document.exitFullscreen()");++ // Tab into the player from a preceding control, without a pointer over the video.+ await session.evaluate(`(() => {+ const before = document.createElement("button");+ before.textContent = "Before the player";+ document.querySelector("#focus-player").before(before);+ before.focus();+ })()`);+ await session.mouse(1, 1);+ await session.key("Tab");+ if (!(await focused("focus-player")) || !(await keyboard())) throw new Error("Tab did not give the player keyboard focus");+ await until("the keyboard video button", 5000, shown);+ await idle();+ if (!(await shown())) throw new Error("keyboard-focused player lost its video button");+ await session.key("Tab");+ if (!(await session.evaluate('document.activeElement?.localName === "mdm-video-button"'))) throw new Error("Tab skipped the video button");+ await idle();+ if (!(await shown())) throw new Error("keyboard-focused video button faded");+ await session.key("Tab"); // Back through the player to the next page control.+ if (!(await focused("after-player"))) throw new Error("Tab could not leave the video button");+ await until("the video button hidden after focus leaves", 5000, async () => !(await shown()));++ // Return to the player by mouse after using the keyboard.+ await session.mouse((v.l + v.r) / 2, (v.t + v.b) / 2, "click");+ if (await keyboard()) throw new Error("mouse click did not clear keyboard focus");+ await until("the player button again", 5000, shown);+ await idle();+ if (await shown()) throw new Error("switching to the mouse kept the button visible");+ // Hover shows it again; Tab from a clicked player must still reach the button.+ await session.mouse((v.l + v.r) / 2 + 1, (v.t + v.b) / 2);+ await until("the hovered video button", 5000, shown);+ await session.key("Tab");+ if (!(await session.evaluate('document.activeElement?.localName === "mdm-video-button"'))) throw new Error("Tab from a mouse-focused player skipped the video button");+ return "mouse focus fades in normal view and fullscreen; keyboard focus stays, Tab enters and leaves, switching to the mouse fades again";+}+// Point at the video (rectangle `v`) until the button shows; its rectangle, or null.async function hover(session, v) {for (let i = 0; i < 40; i++) {@@ -1823,6 +1900,12 @@ const CASES = {return videoButton(t.session, t.last);},+ async videoFocus(t) {+ // Headless Firefox refuses the player's fullscreen request and Tab's focus on it here.+ if (t.kind === "firefox") throw new Skip("headless Firefox denies fullscreen and keyboard focus to the test page");+ return videoFocus(t.session);+ },+// MDM not running: the host starts it (off the screens, with the test's data folder: both// reach it through the browser's environment) and hands the download over.async start(t) {