mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-04-19 21:22:03 +00:00
fix: stuff
This commit is contained in:
parent
9a73497fc6
commit
6c93cdf22d
4 changed files with 18 additions and 75 deletions
|
|
@ -4,7 +4,8 @@ const ipcRendererUI = new EventEmitter()
|
|||
|
||||
export default {
|
||||
emit: (event, data) => {
|
||||
ipcRendererUI.emit(event, data)
|
||||
// ipcRendererUI.emit(event, data)
|
||||
if (event === 'portRequest') portRequest(data)
|
||||
},
|
||||
on: (event, callback) => {
|
||||
ipcRendererUI.on(event, (event, ...args) => callback(...args))
|
||||
|
|
@ -17,7 +18,7 @@ export default {
|
|||
}
|
||||
}
|
||||
|
||||
ipcRendererUI.on('portRequest', async () => {
|
||||
async function portRequest (data) {
|
||||
const { port1, port2 } = new MessageChannel()
|
||||
window.port = {
|
||||
onmessage: cb => {
|
||||
|
|
@ -28,13 +29,16 @@ ipcRendererUI.on('portRequest', async () => {
|
|||
}
|
||||
}
|
||||
await window.controller
|
||||
ipcRendererWebTorrent.emit('port', { ports: [port1] })
|
||||
ipcRendererUI.emit('port', { ports: [port2] })
|
||||
})
|
||||
ipcRendererWebTorrent.emit('port', { ports: [port1] })
|
||||
}
|
||||
|
||||
export const ipcRendererWebTorrent = new EventEmitter()
|
||||
|
||||
const [_platform, arch] = navigator.platform.split(' ')
|
||||
|
||||
window.version = {
|
||||
arch: 'uwu',
|
||||
platform: 'nyaa'
|
||||
platform: globalThis.cordova.platformId,
|
||||
arch,
|
||||
version: globalThis.cordova.version
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,12 @@ const controller = (async () => {
|
|||
|
||||
const worker = reg.active || reg.waiting || reg.installing
|
||||
return new Promise(resolve => {
|
||||
function checkState (worker) {
|
||||
return worker.state === 'activated' && resolve(reg)
|
||||
function checkState ({ state }) {
|
||||
if (state === 'activated') {
|
||||
resolve(reg)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
if (!checkState(worker)) {
|
||||
worker.addEventListener('statechange', ({ target }) => checkState(target))
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
export const platformMap = {
|
||||
aix: 'Aix',
|
||||
darwin: 'MacOS',
|
||||
android: 'Android',
|
||||
ios: 'iOS',
|
||||
freebsd: 'Linux',
|
||||
linux: 'Linux',
|
||||
openbsd: 'Linux',
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
import { fontRx } from 'common/util.js'
|
||||
import Metadata from 'matroska-metadata'
|
||||
|
||||
export default class Parser {
|
||||
parsed = false
|
||||
/** @type {Metadata} */
|
||||
metadata = null
|
||||
client = null
|
||||
file = null
|
||||
destroyed = false
|
||||
constructor (client, file) {
|
||||
this.client = client
|
||||
this.file = file
|
||||
this.metadata = new Metadata(file)
|
||||
|
||||
this.metadata.getTracks().then(tracks => {
|
||||
if (this.destroyed) return
|
||||
if (!tracks.length) {
|
||||
this.parsed = true
|
||||
this.destroy()
|
||||
} else {
|
||||
this.client.dispatch('tracks', tracks)
|
||||
}
|
||||
})
|
||||
|
||||
this.metadata.getChapters().then(chapters => {
|
||||
if (this.destroyed) return
|
||||
this.client.dispatch('chapters', chapters)
|
||||
})
|
||||
|
||||
this.metadata.getAttachments().then(files => {
|
||||
if (this.destroyed) return
|
||||
for (const file of files) {
|
||||
if (fontRx.test(file.filename) || file.mimetype.toLowerCase().includes('font')) {
|
||||
const data = new Uint8Array(file.data)
|
||||
this.client.dispatch('file', { data }, [data.buffer])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.metadata.on('subtitle', (subtitle, trackNumber) => {
|
||||
if (this.destroyed) return
|
||||
this.client.dispatch('subtitle', { subtitle, trackNumber })
|
||||
})
|
||||
|
||||
if (this.file.name.endsWith('.mkv') || this.file.name.endsWith('.webm')) {
|
||||
this.file.on('iterator', ({ iterator }, cb) => {
|
||||
if (this.destroyed) return cb(iterator)
|
||||
cb(this.metadata.parseStream(iterator))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async parseSubtitles () {
|
||||
if (this.file.name.endsWith('.mkv') || this.file.name.endsWith('.webm')) {
|
||||
console.log('Sub parsing started')
|
||||
await this.metadata.parseFile()
|
||||
console.log('Sub parsing finished')
|
||||
}
|
||||
}
|
||||
|
||||
destroy () {
|
||||
this.destroyed = true
|
||||
this.metadata?.destroy()
|
||||
this.metadata = undefined
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue