import { invoke } from '@tauri-apps/api/core' import { listen } from '@tauri-apps/api/event' export interface AuthStatus { logged_in: boolean profiles: string[] auth_dir: string } export interface Book { asin: string title: string authors: string narrators: string runtime_length_min: number cover_url: string percent_complete: number is_finished: boolean date_added: string genres: string subtitle: string release_date: string rating: number num_ratings: number purchase_date: string local: boolean } export const authStatus = () => invoke('auth_status') export const startLogin = () => invoke('start_login') export const startDecrypt = () => invoke('start_decrypt') export const getLibrary = () => invoke('get_library') export const getLocalBooks = () => invoke('get_local_books') export const getStreamOnly = () => invoke('stream_only') export const getAlterNotes = () => invoke>('get_alter_notes') export const setAlterNote = (asin: string, note: string | null) => invoke('set_alter_note', { asin, note }) import { convertFileSrc } from '@tauri-apps/api/core' export interface PChapter { title: string start: number end: number } export interface PlayerState { loaded: boolean playing: boolean position: number duration: number chapter: number chapters: PChapter[] speed: number asin: string | null title: string | null cover: string | null } export const playerLoad = (asin: string, title: string) => invoke('player_load', { asin, title }) export const playerToggle = () => invoke('player_toggle') export const playerSeek = (secs: number) => invoke('player_seek', { secs }) export const playerSetPosition = (pos: number) => invoke('player_set_position', { pos }) export const playerSetChapter = (idx: number) => invoke('player_set_chapter', { idx }) export const playerSetSpeed = (speed: number) => invoke('player_set_speed', { speed }) export const playerStop = () => invoke('player_stop') export const playerSnapshot = () => invoke('player_snapshot') export const onPlayerState = (cb: (s: PlayerState) => void) => listen('player-state', (ev) => cb(ev.payload)) export const assetUri = (path: string) => convertFileSrc(path) export interface Bm { time: number; note: string } export const bmList = (asin: string) => invoke('bookmark_list', { asin }) export const bmAdd = (asin: string, time: number, note: string) => invoke('bookmark_add', { asin, time, note }) export const bmRemove = (asin: string, index: number) => invoke('bookmark_remove', { asin, index }) export const bmSetNote = (asin: string, index: number, note: string) => invoke('bookmark_set_note', { asin, index, note }) export const autostartEnabled = () => invoke('autostart_enabled') export const autostartSet = (on: boolean) => invoke('autostart_set', { on }) export interface SerieRef { title: string sequence: number } export const bookSeriesBulk = (refresh = false) => invoke>('book_series_bulk', { refresh }) export interface BookExtra { description: string language: string format_type: string release_date: string } export const bookDetails = (asin: string) => invoke('book_details', { asin }) export function fmtClock(sec: number): string { const t = Math.max(0, Math.floor(sec)) const h = Math.floor(t / 3600) const m = Math.floor((t % 3600) / 60) const s = t % 60 return h > 0 ? `${h}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}` : `${m}:${String(s).padStart(2, '0')}` } export interface DlItem { asin: string status: 'queued' | 'running' | 'decrypting' | 'done' | 'failed' | 'cancelled' bytes: number msg: string } export const downloadList = () => invoke('download_list') export const downloadEnqueue = (asin: string) => invoke('download_enqueue', { asin }) export const downloadCancel = (asin: string) => invoke('download_cancel', { asin }) export const downloadDelete = (asin: string) => invoke('download_delete', { asin }) export const onDownloadUpdate = (cb: (it: DlItem) => void) => listen('download-update', (ev) => cb(ev.payload))