diff --git a/package.json b/package.json index 4341ece..29d53db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Miru", - "version": "1.2.7", + "version": "1.3.0", "author": "ThaUnknown_ ", "main": "src/index.js", "homepage": "https://github.com/ThaUnknown/miru#readme", diff --git a/src/main/torrent.js b/src/main/torrent.js index be4cd5e..8039519 100644 --- a/src/main/torrent.js +++ b/src/main/torrent.js @@ -165,6 +165,9 @@ ipcMain.on('settings', (event, data) => { downloadSpeed: (client?.torrents.length && client?.torrents[0].downloadSpeed) || 0 }) }, 200) + setInterval(() => { + if (client?.torrents[0]?.pieces) window?.webContents?.send('pieces', [...client?.torrents[0]?.pieces.map(piece => piece === null ? 77 : 33)]) + }, 2000) client.on('torrent', torrent => { const files = torrent.files.map(file => { return { @@ -177,6 +180,7 @@ ipcMain.on('settings', (event, data) => { } }) window?.webContents.send('files', files) + window?.webContents.send('pieces', torrent.pieces.length) window?.webContents.send('torrent', Array.from(torrent.torrentFile)) }) } diff --git a/src/renderer/src/lib/pages/Player.svelte b/src/renderer/src/lib/pages/Player.svelte index ed7895d..301b929 100644 --- a/src/renderer/src/lib/pages/Player.svelte +++ b/src/renderer/src/lib/pages/Player.svelte @@ -2,6 +2,7 @@ import { set } from './Settings.svelte' import { playAnime } from '../RSSView.svelte' import { title } from '../Menubar.svelte' + import { onMount } from 'svelte' export let media = null let fileMedia = null let hadImage = false @@ -203,6 +204,7 @@ window.IPC.emit('current', file) video?.load() checkAvail(current) + clearCanvas() } } @@ -718,6 +720,35 @@ torrent.up = stats.uploadSpeed || 0 torrent.down = stats.downloadSpeed || 0 } + let bufferCanvas = null + let ctx = null + onMount(() => { + ctx = bufferCanvas.getContext('2d') + clearCanvas() + }) + function clearCanvas() { + ctx.fillStyle = 'rgba(255, 255, 255, 0.2)' + ctx.fillRect(0, 0, bufferCanvas.width, 1) + ctx.fillStyle = 'rgba(255, 255, 255, 0.4)' + } + let imageData = null + function handlePieces(data) { + if (data.constructor === Array) { + if (imageData) { + for (let i = 0; i < data.length; ++i) { + imageData.data[i * 4 + 3] = data[i] + } + ctx.putImageData(imageData, 0, 0) + } + } else { + const uint32 = new Uint32Array(data) + uint32.fill(872415231) // rgba(255, 255, 255, 0.2) to HEX to DEC + imageData = new ImageData(new Uint8ClampedArray(uint32.buffer), data, 1) + bufferCanvas.width = data + clearCanvas() + } + } + window.IPC.on('pieces', handlePieces) @@ -831,8 +862,9 @@
{toTS(targetTime, duration > 3600 ? 2 : 3)}
+