fix: 修复视频播放器快进后 ESC 无法关闭的问题
This commit is contained in:
parent
6fd0c6e7f6
commit
326c66f0e2
|
|
@ -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 { HttpClient } from '@angular/common/http';
|
||||||
import { Observable, distinctUntilChanged, map } from 'rxjs';
|
import { Observable, distinctUntilChanged, map } from 'rxjs';
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ export type DownloadTab = 'downloading' | 'queued' | 'completed';
|
||||||
styleUrls: ['./app.component.sass'],
|
styleUrls: ['./app.component.sass'],
|
||||||
standalone: false
|
standalone: false
|
||||||
})
|
})
|
||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit, OnDestroy {
|
||||||
formats: Format[] = Formats;
|
formats: Format[] = Formats;
|
||||||
qualities: Quality[];
|
qualities: Quality[];
|
||||||
themes: Theme[] = Themes;
|
themes: Theme[] = Themes;
|
||||||
|
|
@ -128,6 +128,15 @@ export class AppComponent implements OnInit {
|
||||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
||||||
if (this.activeTheme.id === 'auto') this.setTheme(this.activeTheme);
|
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 ----------
|
// ---------- Navigation ----------
|
||||||
|
|
@ -169,10 +178,11 @@ export class AppComponent implements OnInit {
|
||||||
this.playerTitle = '';
|
this.playerTitle = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('document:keydown.escape')
|
private onPlayerKeydown = (event: KeyboardEvent): void => {
|
||||||
onEscape(): void {
|
if (event.key === 'Escape' && this.playerUrl) {
|
||||||
if (this.playerUrl) this.closePlayer();
|
this.closePlayer();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// ---------- Library (媒体库) ----------
|
// ---------- Library (媒体库) ----------
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue