mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-05 23:19:42 +00:00
chore: add supported presets call
This commit is contained in:
parent
f3a809752a
commit
e6cdce4a14
@ -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<anyhow::Result<Vec<SpotubeAudioSourceContainerPreset>>>,
|
||||
},
|
||||
Matches {
|
||||
track: SpotubeTrackObject,
|
||||
response_tx: oneshot::Sender<anyhow::Result<Vec<SpotubeAudioSourceMatchObject>>>,
|
||||
|
||||
@ -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<T>(tx: oneshot::Sender<T>, 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)
|
||||
|
||||
@ -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<Vec<SpotubeAudioSourceContainerPreset>> {
|
||||
self.0
|
||||
.with(|ctx| {
|
||||
anyhow::Ok(
|
||||
js_invoke_method_to_json::<(), Vec<SpotubeAudioSourceContainerPreset>>(
|
||||
ctx.clone(),
|
||||
"audioSource",
|
||||
"supportedPresets",
|
||||
&[],
|
||||
)?
|
||||
.expect("[hey][smartypants] audioSource.supportedPresets should return a vector of SpotubeAudioSourceContainerPreset"),
|
||||
)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn matches(
|
||||
&self,
|
||||
track: SpotubeTrackObject,
|
||||
|
||||
@ -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';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user