@@ -3,7 +3,6 @@ use std::{
33 time:: Duration ,
44} ;
55
6- use base64:: Engine ;
76use souvlaki:: { MediaControlEvent , MediaControls , MediaMetadata , MediaPlayback , PlatformConfig } ;
87use termusiclib:: {
98 common:: const_unknown:: { UNKNOWN_ARTIST , UNKNOWN_TITLE } ,
@@ -58,18 +57,18 @@ impl Mpris {
5857 /// Set Mpris metadata based on the given track.
5958 pub fn set_track ( & mut self , track : & Track ) {
6059 let cover_art = match track. get_picture ( ) {
61- Ok ( v) => v. map ( |v| {
62- format ! (
63- "data:{};base64,{}" ,
64- v. mime_type( ) . map_or_else (
65- || {
66- error! ( "Unknown mimetype for picture of track {track:#?}" ) ;
67- "application/octet-stream"
68- } ,
69- |v| v . as_str ( )
70- ) ,
71- base64 :: engine :: general_purpose :: STANDARD_NO_PAD . encode ( v . data ( ) )
72- )
60+ Ok ( v) => v. and_then ( |v| {
61+ let mut path = std :: env :: temp_dir ( ) ;
62+ path . push ( "termusic-cover" ) ;
63+ if let Some ( mime ) = v. mime_type ( )
64+ && let Some ( ext ) = mime . ext ( )
65+ {
66+ path . set_extension ( ext ) ;
67+ }
68+ std :: fs :: write ( & path , v . data ( ) )
69+ . inspect_err ( |e| error ! ( "Saving cover to file failed: {e}" ) )
70+ . ok ( ) ? ;
71+ Some ( format ! ( "file://{}" , path . display ( ) ) )
7372 } ) ,
7473 Err ( err) => {
7574 error ! ( "Fetching the cover failed: {err:#?}" ) ;
@@ -374,26 +373,6 @@ mod windows {
374373 // }
375374 // }
376375 // }
377-
378- // The following does not seem to be necessary, hence disabled
379- // /// Blockingly handle the windows event queue.
380- // ///
381- // /// This should be spawned on a extra thread
382- // pub fn pump_event_queue() {
383- // use windows::Win32::UI::WindowsAndMessaging::{MSG, WM_QUIT, GetMessageW, TranslateMessage, DispatchMessageW};
384-
385- // let mut msg = MSG::default();
386-
387- // info!("Windows Event Queue Pump Starting");
388- // unsafe {
389- // while GetMessageW(&mut msg, None, 0, 0).as_bool() && msg.message != WM_QUIT {
390- // debug!("Windows Message: {:#?}", msg);
391- // let _ = TranslateMessage(&msg);
392- // DispatchMessage(&msg);
393- // }
394- // }
395- // info!("Windows Event Queue Pump Ending");
396- // }
397376}
398377
399378#[ cfg( target_os = "macos" ) ]
@@ -521,4 +500,3 @@ pub mod macos {
521500 handle. join ( ) . expect ( "termusic-tokio thread panicked" )
522501 }
523502}
524-
0 commit comments