mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-21 22:15:40 +00:00
1dd74f0fa1
Each Rust<->React bridge concern moves into its own hook under hooks/tauriBridge/; TauriEventBridge just composes them: - useZipDownloadBridge download:zip:progress - usePreviewBridge audio:preview-* lifecycle - useAudioDeviceBridge audio:device-changed / -reset - useCliBridge full cli:* listener surface - useTrayIconSync tray-icon visibility - useInAppKeybindings configurable keydown chords - useMediaAndWindowBridge media keys, tray, shortcuts, close/force-quit - usePlayerSnapshotPublisher psysonic --info JSON snapshot Pure code-move — event names, payloads, effect deps and cleanup all verbatim. The MainApp call site is unchanged.
22 lines
1005 B
TypeScript
22 lines
1005 B
TypeScript
import { useEffect } from 'react';
|
|
import { listen } from '@tauri-apps/api/event';
|
|
import { usePreviewStore } from '../../store/previewStore';
|
|
|
|
/** Track-preview lifecycle: Rust audio engine emits start/progress/end. The
|
|
* store mirrors them so any tracklist row can render its preview UI. */
|
|
export function usePreviewBridge() {
|
|
useEffect(() => {
|
|
const unlistenFns: Array<() => void> = [];
|
|
listen<string>('audio:preview-start', e => {
|
|
usePreviewStore.getState()._onStart(e.payload);
|
|
}).then(u => unlistenFns.push(u));
|
|
listen<{ id: string; elapsed: number; duration: number }>('audio:preview-progress', e => {
|
|
usePreviewStore.getState()._onProgress(e.payload.id, e.payload.elapsed, e.payload.duration);
|
|
}).then(u => unlistenFns.push(u));
|
|
listen<{ id: string; reason: string }>('audio:preview-end', e => {
|
|
usePreviewStore.getState()._onEnd(e.payload.id);
|
|
}).then(u => unlistenFns.push(u));
|
|
return () => { unlistenFns.forEach(fn => fn()); };
|
|
}, []);
|
|
}
|