tauri-plugin-audio 0.1.1

Desktop audio capture plugin for Tauri
use tauri::{
    plugin::{Builder as PluginBuilder, TauriPlugin},
    Manager, Runtime,
};
use tauri_specta::{collect_commands, Builder as SpectaBuilder};

mod devices;
#[cfg(target_os = "linux")]
mod pipewire;
mod stream;

pub fn specta_builder<R: Runtime>() -> SpectaBuilder<R> {
    SpectaBuilder::<R>::new()
        .plugin_name("audio")
        .commands(collect_commands![
            devices::get_devices,
            stream::create_stream,
            stream::stop_stream
        ])
}

pub fn init<R: Runtime>() -> TauriPlugin<R> {
    PluginBuilder::new("audio")
        .setup(|app, _api| {
            app.manage(stream::ActiveInputStream::default());
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![
            devices::get_devices,
            stream::create_stream,
            stream::stop_stream
        ])
        .build()
}

#[cfg(test)]
mod tests {
    use super::specta_builder;

    #[test]
    fn exports_plugin_prefixed_typescript_bindings() {
        let output_path = std::env::temp_dir().join("tauri-plugin-audio-bindings-test.ts");
        specta_builder::<tauri::Wry>()
            .export(specta_typescript::Typescript::default(), &output_path)
            .expect("typescript binding export should succeed");

        let output = std::fs::read_to_string(&output_path).expect("bindings should be readable");
        assert!(output.contains(r#"__TAURI_INVOKE("plugin:audio|get_devices")"#));
        assert!(output.contains(r#"__TAURI_INVOKE("plugin:audio|create_stream""#));
        assert!(output.contains(r#"__TAURI_INVOKE("plugin:audio|stop_stream")"#));

        let _ = std::fs::remove_file(output_path);
    }
}