Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat: add batch file status handling with callback support for Telegram downloads

Tonhof85a8a12a8bf
diff --git a/src/lib/stores/download-listener.ts b/src/lib/stores/download-listener.ts
index a57330f5..f6c467b4 100644
--- a/src/lib/stores/download-listener.ts
+++ b/src/lib/stores/download-listener.ts
@@ -46,6 +46,21 @@ type GenericCompletePayload = {
file_count: number | null;
};
+export type BatchFileStatusPayload = {
+ batch_id: number;
+ message_id: number;
+ status: "waiting" | "downloading" | "done" | "error" | "skipped";
+ percent: number;
+ error: string | null;
+};
+
+type BatchFileStatusCallback = (payload: BatchFileStatusPayload) => void;
+let batchFileStatusCallback: BatchFileStatusCallback | null = null;
+
+export function onBatchFileStatus(cb: BatchFileStatusCallback | null) {
+ batchFileStatusCallback = cb;
+}
+
const seenCourseIds = new Set<number>();
const seenGenericIds = new Set<number>();
@@ -119,10 +134,20 @@ export async function initDownloadListener(): Promise<() => void> {
},
);
+ const unlistenBatchFileStatus = await listen<BatchFileStatusPayload>(
+ "telegram-batch-file-status",
+ (event) => {
+ if (batchFileStatusCallback) {
+ batchFileStatusCallback(event.payload);
+ }
+ },
+ );
+
return () => {
unlistenProgress();
unlistenComplete();
unlistenGenericProgress();
unlistenGenericComplete();
+ unlistenBatchFileStatus();
};
}