mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-06 07:29: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 flutter_rust_bridge::frb;
|
||||||
use crate::api::plugin::models::album::SpotubeFullAlbumObject;
|
use crate::api::plugin::models::album::SpotubeFullAlbumObject;
|
||||||
use crate::api::plugin::models::artist::SpotubeFullArtistObject;
|
use crate::api::plugin::models::artist::SpotubeFullArtistObject;
|
||||||
use crate::api::plugin::models::audio_source::{
|
use crate::api::plugin::models::audio_source::{SpotubeAudioSourceContainerPreset, SpotubeAudioSourceMatchObject, SpotubeAudioSourceStreamObject};
|
||||||
SpotubeAudioSourceMatchObject, SpotubeAudioSourceStreamObject,
|
|
||||||
};
|
|
||||||
use crate::api::plugin::models::core::{
|
use crate::api::plugin::models::core::{
|
||||||
PluginConfiguration, PluginUpdateAvailable, ScrobbleDetails,
|
PluginConfiguration, PluginUpdateAvailable, ScrobbleDetails,
|
||||||
};
|
};
|
||||||
@ -77,6 +75,9 @@ pub enum AlbumCommands {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum AudioSourceCommands {
|
pub enum AudioSourceCommands {
|
||||||
|
SupportedPresets {
|
||||||
|
response_tx: oneshot::Sender<anyhow::Result<Vec<SpotubeAudioSourceContainerPreset>>>,
|
||||||
|
},
|
||||||
Matches {
|
Matches {
|
||||||
track: SpotubeTrackObject,
|
track: SpotubeTrackObject,
|
||||||
response_tx: oneshot::Sender<anyhow::Result<Vec<SpotubeAudioSourceMatchObject>>>,
|
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::track::PluginTrackEndpoint;
|
||||||
use crate::internal::user::PluginUserEndpoint;
|
use crate::internal::user::PluginUserEndpoint;
|
||||||
use flutter_rust_bridge::frb;
|
use flutter_rust_bridge::frb;
|
||||||
use std::fmt::Debug;
|
|
||||||
use rquickjs::AsyncContext;
|
use rquickjs::AsyncContext;
|
||||||
|
use std::fmt::Debug;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
fn send_response<T>(tx: oneshot::Sender<T>, response: T) -> anyhow::Result<()>
|
fn send_response<T>(tx: oneshot::Sender<T>, response: T) -> anyhow::Result<()>
|
||||||
@ -26,7 +26,10 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[frb(ignore)]
|
#[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);
|
let artist = PluginArtistEndpoint::new(context);
|
||||||
match command {
|
match command {
|
||||||
ArtistCommands::GetArtist { id, response_tx } => {
|
ArtistCommands::GetArtist { id, response_tx } => {
|
||||||
@ -114,6 +117,10 @@ pub async fn execute_audio_source(
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let audio_source = PluginAudioSourceEndpoint::new(context);
|
let audio_source = PluginAudioSourceEndpoint::new(context);
|
||||||
match command {
|
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 } => {
|
AudioSourceCommands::Matches { track, response_tx } => {
|
||||||
let audio_source = audio_source.matches(track).await;
|
let audio_source = audio_source.matches(track).await;
|
||||||
send_response(response_tx, audio_source)
|
send_response(response_tx, audio_source)
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
use crate::api::plugin::models::audio_source::{
|
use crate::api::plugin::models::audio_source::{
|
||||||
SpotubeAudioSourceMatchObject, SpotubeAudioSourceStreamObject,
|
SpotubeAudioSourceContainerPreset, SpotubeAudioSourceMatchObject,
|
||||||
|
SpotubeAudioSourceStreamObject,
|
||||||
};
|
};
|
||||||
use crate::api::plugin::models::track::SpotubeTrackObject;
|
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 flutter_rust_bridge::frb;
|
||||||
use rquickjs::{async_with, AsyncContext};
|
use rquickjs::{async_with, AsyncContext};
|
||||||
|
|
||||||
@ -14,6 +15,24 @@ impl<'a> PluginAudioSourceEndpoint<'a> {
|
|||||||
PluginAudioSourceEndpoint(context)
|
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(
|
pub async fn matches(
|
||||||
&self,
|
&self,
|
||||||
track: SpotubeTrackObject,
|
track: SpotubeTrackObject,
|
||||||
|
|||||||
@ -66,7 +66,11 @@ function sleep(ms) {
|
|||||||
|
|
||||||
class Core {
|
class Core {
|
||||||
async checkUpdate() {
|
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() {
|
support() {
|
||||||
return 'Metadata';
|
return 'Metadata';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user