[READ-ONLY] Mirror of https://github.com/probablykasper/ferrum. Music library app for Mac, Linux and Windows ferrum.kasper.space
electron linux macos music music-library music-player napi windows
0

Configure Feed

Select the types of activity you want to include in your feed.

Don't log error when cover missing from player

Kasper (Sep 27, 2024, 7:42 AM +0200) 76382303 62b487df

+17 -8
+1 -1
ferrum-addon/addon.d.ts
··· 141 141 export declare function move_tracks(playlistId: string, itemIds: Array<ItemId>, toIndex: number): void 142 142 /** Returns `None` if the file does not have an image */ 143 143 export declare function read_small_cover_async(path: string, index: number, cacheDbPath: string): Promise<Buffer | null> 144 + export declare function read_cover_async(trackId: string, index: number): Promise<ArrayBuffer | null> 144 145 export interface TrackMd { 145 146 name: string 146 147 artist: string ··· 168 169 export declare function add_play(trackId: string): void 169 170 export declare function add_skip(trackId: string): void 170 171 export declare function add_play_time(id: TrackID, start: MsSinceUnixEpoch, durMs: number): void 171 - export declare function read_cover_async(trackId: string, index: number): Promise<ArrayBuffer> 172 172 export declare function import_file(path: string, now: MsSinceUnixEpoch): void 173 173 export declare function load_tags(trackId: string): void 174 174 export interface JsImage {
+12 -7
src-native/tracks/cover.rs
··· 221 221 /// File path, artwork index 222 222 struct ReadCover(PathBuf, usize); 223 223 impl Task for ReadCover { 224 - type Output = Vec<u8>; 225 - type JsValue = JsBuffer; 224 + type Output = Option<Vec<u8>>; 225 + type JsValue = Option<JsBuffer>; 226 226 fn compute(&mut self) -> napi::Result<Self::Output> { 227 227 let path = &self.0; 228 228 let index = self.1; ··· 231 231 let image = match tag.get_image_consume(index)? { 232 232 Some(image) => image, 233 233 None => { 234 - return Err(anyhow!("No image").into()); 234 + return Ok(None); 235 235 } 236 236 }; 237 237 238 - Ok(image.data) 238 + Ok(Some(image.data)) 239 239 } 240 240 fn resolve(&mut self, env: Env, output: Self::Output) -> napi::Result<Self::JsValue> { 241 - let result = env.create_buffer_copy(output)?; 242 - return Ok(result.into_raw()); 241 + match output { 242 + Some(output) => Ok(Some(env.create_buffer_copy(output)?.into_raw())), 243 + None => Ok(None), 244 + } 243 245 } 244 246 } 245 - #[napi(js_name = "read_cover_async", ts_return_type = "Promise<ArrayBuffer>")] 247 + #[napi( 248 + js_name = "read_cover_async", 249 + ts_return_type = "Promise<ArrayBuffer | null>" 250 + )] 246 251 #[allow(dead_code)] 247 252 pub fn read_cover_async(track_id: String, index: u16, env: Env) -> napi::Result<JsObject> { 248 253 let data: &mut Data = get_data(&env)?;
+4
src/lib/player.ts
··· 80 80 async newFromTrackId(id: TrackID) { 81 81 try { 82 82 const buf = await read_cover_async(id, 0) 83 + if (buf === null) { 84 + set(null) 85 + return 86 + } 83 87 const url = URL.createObjectURL(new Blob([buf], {})) 84 88 set(url) 85 89 } catch (_) {