From e6cdce4a149233365428108840ac9cc62eceea5b Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Tue, 2 Dec 2025 10:58:10 +0600 Subject: [PATCH] chore: add supported presets call --- rust/src/api/plugin/commands.rs | 7 ++++--- rust/src/api/plugin/executors.rs | 11 +++++++++-- rust/src/internal/audio_source.rs | 25 ++++++++++++++++++++++--- rust/src/main.rs | 6 +++++- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/rust/src/api/plugin/commands.rs b/rust/src/api/plugin/commands.rs index 6e2b3db2..214353b5 100644 --- a/rust/src/api/plugin/commands.rs +++ b/rust/src/api/plugin/commands.rs @@ -1,9 +1,7 @@ use flutter_rust_bridge::frb; use crate::api::plugin::models::album::SpotubeFullAlbumObject; use crate::api::plugin::models::artist::SpotubeFullArtistObject; -use crate::api::plugin::models::audio_source::{ - SpotubeAudioSourceMatchObject, SpotubeAudioSourceStreamObject, -}; +use crate::api::plugin::models::audio_source::{SpotubeAudioSourceContainerPreset, SpotubeAudioSourceMatchObject, SpotubeAudioSourceStreamObject}; use crate::api::plugin::models::core::{ PluginConfiguration, PluginUpdateAvailable, ScrobbleDetails, }; @@ -77,6 +75,9 @@ pub enum AlbumCommands { #[derive(Debug)] pub enum AudioSourceCommands { + SupportedPresets { + response_tx: oneshot::Sender>>, + }, Matches { track: SpotubeTrackObject, response_tx: oneshot::Sender>>, diff --git a/rust/src/api/plugin/executors.rs b/rust/src/api/plugin/executors.rs index b725c3ff..5fde1730 100644 --- a/rust/src/api/plugin/executors.rs +++ b/rust/src/api/plugin/executors.rs @@ -13,8 +13,8 @@ use crate::internal::search::PluginSearchEndpoint; use crate::internal::track::PluginTrackEndpoint; use crate::internal::user::PluginUserEndpoint; use flutter_rust_bridge::frb; -use std::fmt::Debug; use rquickjs::AsyncContext; +use std::fmt::Debug; use tokio::sync::oneshot; fn send_response(tx: oneshot::Sender, response: T) -> anyhow::Result<()> @@ -26,7 +26,10 @@ where } #[frb(ignore)] -pub async fn execute_artists(command: ArtistCommands, context: &AsyncContext) -> anyhow::Result<()> { +pub async fn execute_artists( + command: ArtistCommands, + context: &AsyncContext, +) -> anyhow::Result<()> { let artist = PluginArtistEndpoint::new(context); match command { ArtistCommands::GetArtist { id, response_tx } => { @@ -114,6 +117,10 @@ pub async fn execute_audio_source( ) -> anyhow::Result<()> { let audio_source = PluginAudioSourceEndpoint::new(context); match command { + AudioSourceCommands::SupportedPresets { response_tx } => { + let audio_source = audio_source.supported_presets().await; + send_response(response_tx, audio_source) + } AudioSourceCommands::Matches { track, response_tx } => { let audio_source = audio_source.matches(track).await; send_response(response_tx, audio_source) diff --git a/rust/src/internal/audio_source.rs b/rust/src/internal/audio_source.rs index 870d6bc2..43ccf2cc 100644 --- a/rust/src/internal/audio_source.rs +++ b/rust/src/internal/audio_source.rs @@ -1,8 +1,9 @@ use crate::api::plugin::models::audio_source::{ - SpotubeAudioSourceMatchObject, SpotubeAudioSourceStreamObject, + SpotubeAudioSourceContainerPreset, SpotubeAudioSourceMatchObject, + SpotubeAudioSourceStreamObject, }; use crate::api::plugin::models::track::SpotubeTrackObject; -use crate::internal::utils::js_invoke_async_method_to_json; +use crate::internal::utils::{js_invoke_async_method_to_json, js_invoke_method_to_json}; use flutter_rust_bridge::frb; use rquickjs::{async_with, AsyncContext}; @@ -14,6 +15,24 @@ impl<'a> PluginAudioSourceEndpoint<'a> { PluginAudioSourceEndpoint(context) } + pub async fn supported_presets( + &self, + ) -> anyhow::Result> { + self.0 + .with(|ctx| { + anyhow::Ok( + js_invoke_method_to_json::<(), Vec>( + ctx.clone(), + "audioSource", + "supportedPresets", + &[], + )? + .expect("[hey][smartypants] audioSource.supportedPresets should return a vector of SpotubeAudioSourceContainerPreset"), + ) + }) + .await + } + pub async fn matches( &self, track: SpotubeTrackObject, @@ -49,4 +68,4 @@ impl<'a> PluginAudioSourceEndpoint<'a> { ) }).await } -} \ No newline at end of file +} diff --git a/rust/src/main.rs b/rust/src/main.rs index b8711ab6..59b18624 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -66,7 +66,11 @@ function sleep(ms) { class Core { async checkUpdate() { - console.log(globalThis); + console.log('Core checkUpdate'); + const response = await fetch('https://api.github.com/repos/KRTirtho/spotube/releases/latest'); + const data = await response.json(); + console.log(data); + console.log('No update available'); } support() { return 'Metadata';