// Typed bridge to the Rust backend (detection-only build). import { invoke } from "@tauri-apps/api/core"; import { listen, type UnlistenFn } from "@tauri-apps/api/event"; import { getCurrentWebview } from "@tauri-apps/api/webview"; import { open } from "@tauri-apps/plugin-dialog"; import { revealItemInDir } from "@tauri-apps/plugin-opener"; export interface Tools { ffmpeg: string | null; ffprobe: string | null; } export interface Segment { index: number; start: number; end: number; duration: number; } export interface DetectResult { segments: Segment[]; stats: Record; } export interface ExportResult { files: string[]; } export interface DetectionStatus { python: boolean; packages: boolean; model: boolean; ready: boolean; detail: string; } export interface SetupProgress { message: string; pct: number; } export const getTools = () => invoke("get_tools"); export const checkDetection = () => invoke("check_detection"); export const setupDetection = () => invoke("setup_detection"); export const detectSongs = (video: string, gap: number, minDuration: number, padding: number) => invoke("detect_songs", { video, gap, minDuration, padding }); export const exportSegments = (segments: Segment[], sourceVideo: string, outDir: string | null, fps: number) => invoke("export_segments", { segments, sourceVideo, outDir, fps }); export const cancel = () => invoke("cancel"); export const onDetectProgress = (cb: (msg: string) => void): Promise => listen<{ message: string }>("detect-progress", (e) => cb(e.payload.message)); export const onDetectSetupProgress = (cb: (p: SetupProgress) => void): Promise => listen("detect-setup-progress", (e) => cb(e.payload)); export const onFilesDropped = (cb: (paths: string[]) => void): Promise => getCurrentWebview().onDragDropEvent((e) => { if (e.payload.type === "drop") cb(e.payload.paths); }); export async function pickVideo(): Promise { const sel = await open({ multiple: false, filters: [{ name: "Video", extensions: ["mp4", "mov", "mkv", "avi", "flv", "ts", "wmv", "m4v", "webm", "mts", "m2ts"] }], }); return typeof sel === "string" ? sel : null; } export const reveal = (path: string) => revealItemInDir(path);