#[cfg(desktop)]
(app: AppHandle, access_token: String)
| 33 | #[tauri::command()] |
| 34 | // #[cfg(desktop)] |
| 35 | pub fn initialize_librespot(app: AppHandle, access_token: String) -> Result<()> { |
| 36 | tracing::debug!("Initializing librespot with {:?}", access_token); |
| 37 | let credentials = Credentials::with_access_token(access_token); |
| 38 | |
| 39 | let player_config = PlayerConfig::default(); |
| 40 | |
| 41 | let connect_config = ConnectConfig { |
| 42 | name: "Moosync".into(), |
| 43 | device_type: DeviceType::Computer, |
| 44 | initial_volume: 0, |
| 45 | is_group: false, |
| 46 | ..Default::default() |
| 47 | }; |
| 48 | |
| 49 | let credentials_path = app.path().app_config_dir()?; |
| 50 | let audio_path = app.path().app_cache_dir()?; |
| 51 | let cache_config = Cache::new( |
| 52 | Some(credentials_path.clone()), |
| 53 | Some(credentials_path), |
| 54 | Some(audio_path), |
| 55 | None, |
| 56 | )?; |
| 57 | |
| 58 | let librespot: State<LibrespotHolder> = app.state(); |
| 59 | librespot.initialize( |
| 60 | credentials, |
| 61 | player_config, |
| 62 | connect_config, |
| 63 | cache_config, |
| 64 | "".to_string(), |
| 65 | "".to_string(), |
| 66 | )?; |
| 67 | |
| 68 | // TODO: Check if event loop ends on closing librespot |
| 69 | let events_channel = librespot.get_events_channel()?; |
| 70 | tauri::async_runtime::spawn(async move { |
| 71 | let events_channel = events_channel.lock().unwrap(); |
| 72 | loop { |
| 73 | tracing::trace!("Waiting for librespot player events"); |
| 74 | let event = events_channel.recv(); |
| 75 | match event { |
| 76 | Ok(event) => { |
| 77 | if let PlayerEvent::Unavailable { |
| 78 | play_request_id: _, |
| 79 | track_id: _, |
| 80 | } = event |
| 81 | { |
| 82 | tracing::error!("Got track unavailable {:?}", event); |
| 83 | continue; |
| 84 | } |
| 85 | |
| 86 | let parsed_event = event_to_map(event.clone()); |
| 87 | |
| 88 | let registered_events = REGISTERED_EVENTS.lock().unwrap(); |
| 89 | if registered_events.contains(&format!( |
| 90 | "librespot_event_{}", |
| 91 | parsed_event.get("event").unwrap(), |
| 92 | )) { |
no test coverage detected