fix: callback for time-changed event (#2577)

Co-authored-by: Derek Alsop <15299183+Azorant@users.noreply.github.com>
This commit is contained in:
JellyBrick
2024-11-03 19:18:06 +09:00
committed by GitHub
parent 516fbff3d7
commit 1e4cd699db
13 changed files with 137 additions and 91 deletions

View File

@ -30,12 +30,13 @@ import registerCallback, {
getImage,
MediaType,
type SongInfo,
SongInfoEvent,
} from '@/providers/song-info';
import { getNetFetchAsFetch } from '@/plugins/utils/main';
import { t } from '@/i18n';
import { YoutubeFormatList, type Preset, DefaultPresetList } from '../types';
import { DefaultPresetList, type Preset, YoutubeFormatList } from '../types';
import type { DownloaderPluginConfig } from '../index';
@ -68,7 +69,12 @@ const sendError = (error: Error, source?: string) => {
sendFeedback_(win); // Reset feedback
const songNameMessage = source ? `\nin ${source}` : '';
const cause = error.cause ? `\n\n${String(error.cause)}` : '';
const cause = error.cause
? `\n\n${
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
error.cause instanceof Error ? error.cause.toString() : error.cause
}`
: '';
const message = `${error.toString()}${songNameMessage}${cause}`;
console.error(message);
@ -174,7 +180,12 @@ function downloadSongOnFinishSetup({
const defaultDownloadFolder = app.getPath('downloads');
registerCallback((songInfo: SongInfo) => {
registerCallback((songInfo: SongInfo, event) => {
if (event === SongInfoEvent.TimeChanged) {
const elapsedSeconds = songInfo.elapsedSeconds ?? 0;
if (elapsedSeconds > time) time = elapsedSeconds;
return;
}
if (
!songInfo.isPaused &&
songInfo.url !== currentUrl &&
@ -213,10 +224,6 @@ function downloadSongOnFinishSetup({
ipcMain.on('ytmd:player-api-loaded', () => {
ipc.send('ytmd:setup-time-changed-listener');
});
ipcMain.on('ytmd:time-changed', (_, t: number) => {
if (t > time) time = t;
});
}
async function downloadSongUnsafe(