feat(qbz-nix): Phase 6.2 - CoreBridge and V2 commands
Add bridge layer connecting QbzCore to Tauri and example V2 commands. New files: - core_bridge.rs: CoreBridge wraps QbzCore for Tauri integration - commands_v2.rs: Example commands using new architecture V2 commands implemented: - v2_is_logged_in, v2_login, v2_logout (auth) - v2_get_queue_state, v2_set_repeat_mode, v2_toggle_shuffle, v2_clear_queue These coexist with old commands during migration. Frontend can gradually switch to V2 commands as they're tested.
This commit is contained in:
1 parent
d0e46aca05
commit
f59f0e1b87
3 files changed
+192
-1
No files matched your search
@@ -0,0 +1,82 @@
|
|||||||
|
//! V2 Commands - Using the new multi-crate architecture
|
||||||
|
//!
|
||||||
|
//! These commands use QbzCore via CoreBridge instead of the old AppState.
|
||||||
|
//! They coexist with the old commands during migration.
|
||||||
|
|
||||||
|
use tauri::State;
|
||||||
|
|
||||||
|
use qbz_models::{QueueState, RepeatMode, UserSession};
|
||||||
|
|
||||||
|
use crate::core_bridge::CoreBridgeState;
|
||||||
|
|
||||||
|
// ==================== Auth Commands (V2) ====================
|
||||||
|
|
||||||
|
/// Check if user is logged in (V2 - uses QbzCore)
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn v2_is_logged_in(
|
||||||
|
bridge: State<'_, CoreBridgeState>,
|
||||||
|
) -> Result<bool, String> {
|
||||||
|
let bridge = bridge.get().await;
|
||||||
|
Ok(bridge.is_logged_in().await)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Login with email and password (V2 - uses QbzCore)
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn v2_login(
|
||||||
|
email: String,
|
||||||
|
password: String,
|
||||||
|
bridge: State<'_, CoreBridgeState>,
|
||||||
|
) -> Result<UserSession, String> {
|
||||||
|
let bridge = bridge.get().await;
|
||||||
|
bridge.login(&email, &password).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Logout current user (V2 - uses QbzCore)
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn v2_logout(
|
||||||
|
bridge: State<'_, CoreBridgeState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let bridge = bridge.get().await;
|
||||||
|
bridge.logout().await
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== Queue Commands (V2) ====================
|
||||||
|
|
||||||
|
/// Get current queue state (V2 - uses QbzCore)
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn v2_get_queue_state(
|
||||||
|
bridge: State<'_, CoreBridgeState>,
|
||||||
|
) -> Result<QueueState, String> {
|
||||||
|
let bridge = bridge.get().await;
|
||||||
|
Ok(bridge.get_queue_state().await)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set repeat mode (V2 - uses QbzCore)
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn v2_set_repeat_mode(
|
||||||
|
mode: RepeatMode,
|
||||||
|
bridge: State<'_, CoreBridgeState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let bridge = bridge.get().await;
|
||||||
|
bridge.set_repeat_mode(mode).await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Toggle shuffle (V2 - uses QbzCore)
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn v2_toggle_shuffle(
|
||||||
|
bridge: State<'_, CoreBridgeState>,
|
||||||
|
) -> Result<bool, String> {
|
||||||
|
let bridge = bridge.get().await;
|
||||||
|
Ok(bridge.toggle_shuffle().await)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clear the queue (V2 - uses QbzCore)
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn v2_clear_queue(
|
||||||
|
bridge: State<'_, CoreBridgeState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let bridge = bridge.get().await;
|
||||||
|
bridge.clear_queue().await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
//! Core Bridge
|
||||||
|
//!
|
||||||
|
//! Bridges the new QbzCore architecture with the existing Tauri app.
|
||||||
|
//! This allows gradual migration - new code uses QbzCore, old code
|
||||||
|
//! continues to work until migrated.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
|
use qbz_core::QbzCore;
|
||||||
|
use qbz_models::{QueueState, RepeatMode, UserSession};
|
||||||
|
|
||||||
|
use crate::tauri_adapter::TauriAdapter;
|
||||||
|
|
||||||
|
/// Bridge to the new QbzCore architecture
|
||||||
|
///
|
||||||
|
/// This struct provides access to QbzCore functionality while
|
||||||
|
/// the old AppState continues to handle unmigrated features.
|
||||||
|
pub struct CoreBridge {
|
||||||
|
core: Arc<QbzCore<TauriAdapter>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CoreBridge {
|
||||||
|
/// Create a new CoreBridge with the given TauriAdapter
|
||||||
|
pub async fn new(adapter: TauriAdapter) -> Result<Self, String> {
|
||||||
|
let core = QbzCore::new(adapter);
|
||||||
|
core.init().await.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
core: Arc::new(core),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a reference to the underlying QbzCore
|
||||||
|
pub fn core(&self) -> &Arc<QbzCore<TauriAdapter>> {
|
||||||
|
&self.core
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== Auth Commands ====================
|
||||||
|
|
||||||
|
/// Check if user is logged in
|
||||||
|
pub async fn is_logged_in(&self) -> bool {
|
||||||
|
self.core.has_session().await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Login with email and password
|
||||||
|
pub async fn login(&self, email: &str, password: &str) -> Result<UserSession, String> {
|
||||||
|
self.core.login(email, password).await.map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Logout current user
|
||||||
|
pub async fn logout(&self) -> Result<(), String> {
|
||||||
|
self.core.logout().await.map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== Queue Commands ====================
|
||||||
|
|
||||||
|
/// Get current queue state
|
||||||
|
pub async fn get_queue_state(&self) -> QueueState {
|
||||||
|
self.core.get_queue_state().await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set repeat mode
|
||||||
|
pub async fn set_repeat_mode(&self, mode: RepeatMode) {
|
||||||
|
self.core.set_repeat_mode(mode).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Toggle shuffle
|
||||||
|
pub async fn toggle_shuffle(&self) -> bool {
|
||||||
|
self.core.toggle_shuffle().await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clear the queue
|
||||||
|
pub async fn clear_queue(&self) {
|
||||||
|
self.core.clear_queue().await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// State wrapper for Tauri's managed state
|
||||||
|
pub struct CoreBridgeState(pub Arc<RwLock<Option<CoreBridge>>>);
|
||||||
|
|
||||||
|
impl CoreBridgeState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self(Arc::new(RwLock::new(None)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialize the core bridge with the app handle
|
||||||
|
pub async fn init(&self, adapter: TauriAdapter) -> Result<(), String> {
|
||||||
|
let bridge = CoreBridge::new(adapter).await?;
|
||||||
|
*self.0.write().await = Some(bridge);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the bridge (panics if not initialized)
|
||||||
|
pub async fn get(&self) -> impl std::ops::Deref<Target = CoreBridge> + '_ {
|
||||||
|
tokio::sync::RwLockReadGuard::map(
|
||||||
|
self.0.read().await,
|
||||||
|
|opt| opt.as_ref().expect("CoreBridge not initialized")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CoreBridgeState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,10 @@
|
|||||||
//!
|
//!
|
||||||
//! This application uses the Qobuz API but is not certified by Qobuz.
|
//! This application uses the Qobuz API but is not certified by Qobuz.
|
||||||
|
|
||||||
// New multi-crate architecture adapter
|
// New multi-crate architecture
|
||||||
pub mod tauri_adapter;
|
pub mod tauri_adapter;
|
||||||
|
pub mod core_bridge;
|
||||||
|
pub mod commands_v2;
|
||||||
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod api_cache;
|
pub mod api_cache;
|
||||||
|
|||||||
Reference in new issue
Block a user