chore: dummy

This commit is contained in:
Kingkor Roy Tirtho 2026-01-09 11:51:07 +06:00
parent 65701cb07c
commit 172714f13e
2 changed files with 37 additions and 95 deletions

View File

@ -125,7 +125,7 @@ pub struct SpotubePlugin {
pub track: PluginTrackSender, pub track: PluginTrackSender,
pub user: PluginUserSender, pub user: PluginUserSender,
event_tx: Sender<AuthEventObject>, event_tx: Sender<AuthEventObject>,
event_rx: Option<Receiver<AuthEventObject>>, pub event_rx: Option<Receiver<AuthEventObject>>,
} }
impl SpotubePlugin { impl SpotubePlugin {

View File

@ -2,93 +2,15 @@ mod api;
mod frb_generated; mod frb_generated;
mod internal; mod internal;
use rquickjs::function::{Async, Func}; use crate::api::plugin::models::auth::{AuthEventObject, AuthEventType};
use rquickjs::{async_with, AsyncContext, AsyncRuntime, Function, Object, Promise};
use tokio::time::Instant;
use crate::api::plugin::models::core::{PluginAbility, PluginConfiguration}; use crate::api::plugin::models::core::{PluginAbility, PluginConfiguration};
use crate::api::plugin::plugin::SpotubePlugin; use crate::api::plugin::plugin::SpotubePlugin;
use crate::frb_generated::StreamSink;
use tokio::io::sink;
use tokio::time::Instant;
async fn set_timeout(func: Function<'_>, timeout: u64) { async fn plugin(plugin_js: String) -> anyhow::Result<()> {
tokio::time::sleep(std::time::Duration::from_millis(timeout)).await; let mut plugin = SpotubePlugin::new();
func.call::<_, ()>(()).unwrap();
}
fn print(msg: String) {
println!("{}", msg);
}
async fn non_plugin() -> anyhow::Result<()> {
let start = Instant::now();
let rt = AsyncRuntime::new()?;
let ctx = AsyncContext::full(&rt).await?;
async_with!(ctx => |ctx| {
let global = ctx.globals();
let console = Object::new(ctx.clone()).unwrap();
console.set("log", Func::from(print)).unwrap();
global.set("console", console).unwrap();
global.set("setTimeout",
Function::new(ctx.clone(), Async(set_timeout)).unwrap().with_name("setTimeout")
).unwrap();
let check_update_fn: Function = ctx.eval(r#"
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
(async function checkUpdate() {
console.log('Core checkUpdate');
await sleep(1000);
console.log('No update available');
})
"#)?;
let (r1, r2) = tokio::join!(
check_update_fn.call::<_, Promise>(()).unwrap().into_future::<()>(),
check_update_fn.call::<_, Promise>(()).unwrap().into_future::<()>()
);
r1?;
r2?;
Ok::<(), rquickjs::Error>(())
})
.await
.map_err(|e| anyhow::anyhow!(e))?;
let duration = start.elapsed();
println!("[NON-PLUGIN] Execution time: {:?}", duration);
Ok(())
}
const PLUGIN_JS: &str = "\
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
class Core {
async checkUpdate() {
console.log('Core checkUpdate');
await sleep(1000);
console.log('No update available');
}
support() {
return 'Metadata';
}
}
class Auth {}
class TestingPlugin {
constructor() {
this.core = new Core();
this.auth = new Auth();
}
}
";
async fn plugin() -> anyhow::Result<()> {
let start = Instant::now();
let plugin = SpotubePlugin::new();
let config = PluginConfiguration { let config = PluginConfiguration {
entry_point: "TestingPlugin".to_string(), entry_point: "TestingPlugin".to_string(),
abilities: vec![PluginAbility::Metadata], abilities: vec![PluginAbility::Metadata],
@ -100,23 +22,43 @@ async fn plugin() -> anyhow::Result<()> {
repository: None, repository: None,
version: "0.1.0".to_string(), version: "0.1.0".to_string(),
}; };
let sender = plugin.create_context(PLUGIN_JS.to_string(), config.clone(), "".to_string(), "".to_string(), "".into()).await?; let sender = plugin
let (r1, r2) = tokio::join!( .create_context(
plugin.core.check_update(&sender, config.clone()), plugin_js,
plugin.core.check_update(&sender, config.clone()) config.clone(),
"https://localhost:3000".to_string(),
"1234567890_secret".to_string(),
"/home/krtirtho/.local/share/spotube".into(),
)
.await?;
tokio::spawn(async move {
while let Some(event) = plugin.event_rx.take().unwrap().recv().await {
println!("Auth event: {:?}", event);
if event.event_type != AuthEventType::Logout {
break;
}
}
});
println!(
"Is Authenticated: {}",
plugin.auth.is_authenticated(&sender).await?
); );
r1?;
r2?;
let duration = start.elapsed();
println!("[PLUGIN] Execution time: {:?}", duration);
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
Ok(()) Ok(())
} }
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { async fn main() -> anyhow::Result<()> {
non_plugin().await?; let js_code_path = std::env::args().nth(1);
plugin().await?; if js_code_path.is_none() {
panic!("Please provide the path to the plugin JS code as a command line argument.");
}
let js_code_path = js_code_path.unwrap();
let plugin_js = tokio::fs::read_to_string(js_code_path).await?;
plugin(plugin_js).await?;
Ok(()) Ok(())
} }