mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-03-29 03:38:41 +00:00
fix: thumbnailer crashing
feat: hide to tray
This commit is contained in:
parent
5f82f0649f
commit
5161ebf368
5 changed files with 10 additions and 7 deletions
7
src/app.d.ts
vendored
7
src/app.d.ts
vendored
|
|
@ -99,30 +99,29 @@ export interface Native {
|
|||
updateSettings: (settings: TorrentSettings) => Promise<void>
|
||||
updateProgress: (cb: (progress: number) => void) => Promise<void>
|
||||
spawnPlayer: (url: string) => Promise<void>
|
||||
setHideToTray: (enabled: boolean) => Promise<void>
|
||||
isApp: boolean
|
||||
version: () => Promise<string>
|
||||
}
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
||||
interface PageState {
|
||||
search?: VariablesOf<typeof Search>
|
||||
}
|
||||
// interface Platform {}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
interface HTMLMediaElement {
|
||||
videoTracks?: Track[]
|
||||
audioTracks?: Track[]
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
interface ScreenOrientation {
|
||||
lock: (orientation: 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary') => Promise<void>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
interface RenderItem {
|
||||
index: number
|
||||
run: () => void
|
||||
promise: Promise<string>
|
||||
promise: Promise<string | undefined>
|
||||
}
|
||||
|
||||
export default class Thumbnailer {
|
||||
|
|
@ -35,7 +35,7 @@ export default class Thumbnailer {
|
|||
}
|
||||
|
||||
_createTask (index: number): RenderItem {
|
||||
const { promise, resolve } = Promise.withResolvers<string>()
|
||||
const { promise, resolve } = Promise.withResolvers<string | undefined>()
|
||||
|
||||
const run = () => {
|
||||
this.video.requestVideoFrameCallback((_now, meta) => {
|
||||
|
|
@ -79,6 +79,7 @@ export default class Thumbnailer {
|
|||
// generate and store the thumbnail
|
||||
async _paintThumbnail (video: HTMLVideoElement, index: number, width = video.videoWidth, height = video.videoHeight) {
|
||||
if (this.thumbnails[index]) return this.thumbnails[index]
|
||||
if (!width || !height) return undefined
|
||||
this.canvas.width = this.size
|
||||
this.canvas.height = height / width * this.size
|
||||
this.ctx.drawImage(video, 0, 0, this.canvas.width, this.canvas.height)
|
||||
|
|
@ -86,7 +87,7 @@ export default class Thumbnailer {
|
|||
return this.thumbnails[index]
|
||||
}
|
||||
|
||||
async getThumbnail (index: number): Promise<string> {
|
||||
async getThumbnail (index: number): Promise<string | undefined> {
|
||||
const thumbnail = this.thumbnails[index]
|
||||
if (thumbnail) return thumbnail
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ export default Object.assign<Native, Partial<Native>>({
|
|||
setDOH: async () => undefined,
|
||||
cachedTorrents: async () => ['40a9047de61859035659e449d7b84286934486b0'],
|
||||
spawnPlayer: () => sleep(rnd(100_000)),
|
||||
setHideToTray: async () => 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() }),
|
||||
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() }]
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ export default {
|
|||
subtitleLanguage: 'eng' as keyof typeof languageCodes,
|
||||
audioLanguage: 'jpn' as keyof typeof languageCodes,
|
||||
enableDoH: true,
|
||||
hideToTray: false,
|
||||
doHURL: 'https://cloudflare-dns.com/dns-query',
|
||||
disableSubtitleBlur: SUPPORTS.isAndroid,
|
||||
showDetailsInRPC: true,
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ export const settings = persisted('settings', defaults, { beforeRead: value => (
|
|||
settings.subscribe(settings => {
|
||||
const { torrentPersist, torrentDHT, torrentStreamedDownload, torrentSpeed, maxConns, torrentPort, dhtPort, torrentPeX } = settings
|
||||
native.updateSettings({ torrentPersist, torrentDHT, torrentStreamedDownload, torrentSpeed, maxConns, torrentPort, dhtPort, torrentPeX })
|
||||
native.setHideToTray(settings.hideToTray)
|
||||
if (settings.enableDoH) native.setDOH(settings.doHURL)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue