From 326c66f0e24e2ab2e438a106b9877cc1a7cc880a Mon Sep 17 00:00:00 2001 From: tigerenwork Date: Sat, 15 Aug 2026 14:44:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E5=99=A8=E5=BF=AB=E8=BF=9B=E5=90=8E=20ESC=20?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=85=B3=E9=97=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/app/app.component.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index f29326a..5e12ea6 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -1,4 +1,4 @@ -import { Component, HostListener, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, distinctUntilChanged, map } from 'rxjs'; @@ -17,7 +17,7 @@ export type DownloadTab = 'downloading' | 'queued' | 'completed'; styleUrls: ['./app.component.sass'], standalone: false }) -export class AppComponent implements OnInit { +export class AppComponent implements OnInit, OnDestroy { formats: Format[] = Formats; qualities: Quality[]; themes: Theme[] = Themes; @@ -128,6 +128,15 @@ export class AppComponent implements OnInit { window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { if (this.activeTheme.id === 'auto') this.setTheme(this.activeTheme); }); + + // Listen in the capture phase so Escape closes the player even when the + // native video controls (shadow DOM) hold focus after seeking and would + // otherwise swallow the keydown before it bubbles to the document. + document.addEventListener('keydown', this.onPlayerKeydown, true); + } + + ngOnDestroy(): void { + document.removeEventListener('keydown', this.onPlayerKeydown, true); } // ---------- Navigation ---------- @@ -169,10 +178,11 @@ export class AppComponent implements OnInit { this.playerTitle = ''; } - @HostListener('document:keydown.escape') - onEscape(): void { - if (this.playerUrl) this.closePlayer(); - } + private onPlayerKeydown = (event: KeyboardEvent): void => { + if (event.key === 'Escape' && this.playerUrl) { + this.closePlayer(); + } + }; // ---------- Library (媒体库) ----------