MCPcopy Create free account
hub / github.com/Moosync/Moosync / handle_command

Method handle_command

src-tauri/librespot/src/spirc.rs:214–305  ·  view source on GitHub ↗
(
        message: Message,
        tx: Sender<Result<MessageReply>>,
        spirc: &mut Spirc,
        session: &mut Session,
    )

Source from the content-addressed store, hash-verified

212
213 #[tracing::instrument(level = "debug", skip(message, tx, spirc, session))]
214 fn handle_command(
215 message: Message,
216 tx: Sender<Result<MessageReply>>,
217 spirc: &mut Spirc,
218 session: &mut Session,
219 ) {
220 match message {
221 Message::Play => {
222 let res = (spirc)
223 .play()
224 .map(|_| MessageReply::None)
225 .map_err(MoosyncError::Librespot);
226
227 tx.send(res).unwrap();
228 }
229
230 Message::Pause => {
231 let res = (spirc)
232 .pause()
233 .map(|_| MessageReply::None)
234 .map_err(MoosyncError::Librespot);
235
236 tx.send(res).unwrap();
237 }
238
239 Message::GetToken(scopes) => {
240 let rt = Builder::new_current_thread().build().unwrap();
241 let data = rt.block_on(async move {
242 session
243 .token_provider()
244 .get_token(scopes.as_str())
245 .await
246 .map(MessageReply::GetToken)
247 .map_err(MoosyncError::Librespot)
248 });
249
250 tx.send(data).unwrap();
251 }
252 Message::Seek(pos) => {
253 let res = spirc
254 .set_position_ms(pos)
255 .map(|_| MessageReply::None)
256 .map_err(MoosyncError::Librespot);
257 tx.send(res).unwrap();
258 }
259 Message::Load(uri, autoplay) => {
260 let track_id = SpotifyId::from_uri(uri.as_str()).map_err(MoosyncError::Librespot);
261 match track_id {
262 Err(e) => {
263 tx.send(Err(e)).unwrap();
264 }
265 Ok(_track_id) => {
266 // track_ref.set_gid(Vec::from(track_id.to_raw()));
267 let command = LoadRequest::from_context_uri(
268 uri,
269 LoadRequestOptions {
270 start_playing: autoplay,
271 seek_to: 0,

Callers

nothing calls this directly

Calls 8

get_canvasFunction · 0.85
sendMethod · 0.80
cloneMethod · 0.80
get_lyricsFunction · 0.70
playMethod · 0.45
pauseMethod · 0.45
loadMethod · 0.45
set_volumeMethod · 0.45

Tested by

no test coverage detected