fix: thumbnailer crashing

feat: hide to tray
This commit is contained in:
ThaUnknown 2025-04-27 23:38:23 +02:00
parent 5f82f0649f
commit 5161ebf368
No known key found for this signature in database
5 changed files with 10 additions and 7 deletions

7
src/app.d.ts vendored
View file

@ -99,30 +99,29 @@ export interface Native {
updateSettings: (settings: TorrentSettings) => Promise<void> updateSettings: (settings: TorrentSettings) => Promise<void>
updateProgress: (cb: (progress: number) => void) => Promise<void> updateProgress: (cb: (progress: number) => void) => Promise<void>
spawnPlayer: (url: string) => Promise<void> spawnPlayer: (url: string) => Promise<void>
setHideToTray: (enabled: boolean) => Promise<void>
isApp: boolean isApp: boolean
version: () => Promise<string> version: () => Promise<string>
} }
declare global { declare global {
// eslint-disable-next-line no-unused-vars
namespace App { namespace App {
// interface Error {} // interface Error {}
// interface Locals {} // interface Locals {}
// interface PageData {} // interface PageData {}
// eslint-disable-next-line no-unused-vars
interface PageState { interface PageState {
search?: VariablesOf<typeof Search> search?: VariablesOf<typeof Search>
} }
// interface Platform {} // interface Platform {}
} }
// eslint-disable-next-line no-unused-vars
interface HTMLMediaElement { interface HTMLMediaElement {
videoTracks?: Track[] videoTracks?: Track[]
audioTracks?: Track[] audioTracks?: Track[]
} }
// eslint-disable-next-line no-unused-vars
interface ScreenOrientation { interface ScreenOrientation {
lock: (orientation: 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary') => Promise<void> lock: (orientation: 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary') => Promise<void>
} }

View file

@ -1,7 +1,7 @@
interface RenderItem { interface RenderItem {
index: number index: number
run: () => void run: () => void
promise: Promise<string> promise: Promise<string | undefined>
} }
export default class Thumbnailer { export default class Thumbnailer {
@ -35,7 +35,7 @@ export default class Thumbnailer {
} }
_createTask (index: number): RenderItem { _createTask (index: number): RenderItem {
const { promise, resolve } = Promise.withResolvers<string>() const { promise, resolve } = Promise.withResolvers<string | undefined>()
const run = () => { const run = () => {
this.video.requestVideoFrameCallback((_now, meta) => { this.video.requestVideoFrameCallback((_now, meta) => {
@ -79,6 +79,7 @@ export default class Thumbnailer {
// generate and store the thumbnail // generate and store the thumbnail
async _paintThumbnail (video: HTMLVideoElement, index: number, width = video.videoWidth, height = video.videoHeight) { async _paintThumbnail (video: HTMLVideoElement, index: number, width = video.videoWidth, height = video.videoHeight) {
if (this.thumbnails[index]) return this.thumbnails[index] if (this.thumbnails[index]) return this.thumbnails[index]
if (!width || !height) return undefined
this.canvas.width = this.size this.canvas.width = this.size
this.canvas.height = height / width * this.size this.canvas.height = height / width * this.size
this.ctx.drawImage(video, 0, 0, this.canvas.width, this.canvas.height) this.ctx.drawImage(video, 0, 0, this.canvas.width, this.canvas.height)
@ -86,7 +87,7 @@ export default class Thumbnailer {
return this.thumbnails[index] return this.thumbnails[index]
} }
async getThumbnail (index: number): Promise<string> { async getThumbnail (index: number): Promise<string | undefined> {
const thumbnail = this.thumbnails[index] const thumbnail = this.thumbnails[index]
if (thumbnail) return thumbnail if (thumbnail) return thumbnail

View file

@ -82,6 +82,7 @@ export default Object.assign<Native, Partial<Native>>({
setDOH: async () => undefined, setDOH: async () => undefined,
cachedTorrents: async () => ['40a9047de61859035659e449d7b84286934486b0'], cachedTorrents: async () => ['40a9047de61859035659e449d7b84286934486b0'],
spawnPlayer: () => sleep(rnd(100_000)), spawnPlayer: () => sleep(rnd(100_000)),
setHideToTray: async () => undefined,
updateProgress: async (cb: (progress: number) => void) => undefined, updateProgress: async (cb: (progress: number) => void) => undefined,
torrentStats: async (): Promise<TorrentInfo> => ({ peers: rnd(), seeders: rnd(), leechers: rnd(), progress: Math.random(), down: rnd(100000000), up: rnd(100000000), name: 'Amebku.webm', downloaded: rnd(100000), hash: '1234567890abcdef', size: 1234567890, eta: rnd() }), torrentStats: async (): Promise<TorrentInfo> => ({ peers: rnd(), seeders: rnd(), leechers: rnd(), progress: Math.random(), down: rnd(100000000), up: rnd(100000000), name: 'Amebku.webm', downloaded: rnd(100000), hash: '1234567890abcdef', size: 1234567890, eta: rnd() }),
torrents: async (): Promise<TorrentInfo[]> => [{ peers: rnd(), seeders: rnd(), leechers: rnd(), progress: Math.random(), down: rnd(100000000), up: rnd(100000000), name: 'Amebku.webm', downloaded: rnd(100000), hash: '1234567890abcdef', size: 1234567890, eta: rnd() }] torrents: async (): Promise<TorrentInfo[]> => [{ peers: rnd(), seeders: rnd(), leechers: rnd(), progress: Math.random(), down: rnd(100000000), up: rnd(100000000), name: 'Amebku.webm', downloaded: rnd(100000), hash: '1234567890abcdef', size: 1234567890, eta: rnd() }]

View file

@ -27,6 +27,7 @@ export default {
subtitleLanguage: 'eng' as keyof typeof languageCodes, subtitleLanguage: 'eng' as keyof typeof languageCodes,
audioLanguage: 'jpn' as keyof typeof languageCodes, audioLanguage: 'jpn' as keyof typeof languageCodes,
enableDoH: true, enableDoH: true,
hideToTray: false,
doHURL: 'https://cloudflare-dns.com/dns-query', doHURL: 'https://cloudflare-dns.com/dns-query',
disableSubtitleBlur: SUPPORTS.isAndroid, disableSubtitleBlur: SUPPORTS.isAndroid,
showDetailsInRPC: true, showDetailsInRPC: true,

View file

@ -9,5 +9,6 @@ export const settings = persisted('settings', defaults, { beforeRead: value => (
settings.subscribe(settings => { settings.subscribe(settings => {
const { torrentPersist, torrentDHT, torrentStreamedDownload, torrentSpeed, maxConns, torrentPort, dhtPort, torrentPeX } = settings const { torrentPersist, torrentDHT, torrentStreamedDownload, torrentSpeed, maxConns, torrentPort, dhtPort, torrentPeX } = settings
native.updateSettings({ torrentPersist, torrentDHT, torrentStreamedDownload, torrentSpeed, maxConns, torrentPort, dhtPort, torrentPeX }) native.updateSettings({ torrentPersist, torrentDHT, torrentStreamedDownload, torrentSpeed, maxConns, torrentPort, dhtPort, torrentPeX })
native.setHideToTray(settings.hideToTray)
if (settings.enableDoH) native.setDOH(settings.doHURL) if (settings.enableDoH) native.setDOH(settings.doHURL)
}) })