Skip to content

Commit 5f07817

Browse files
TrackInfo: Improve error handling & update to Svelte 5
1 parent 2893a6e commit 5f07817

File tree

7 files changed

+262
-237
lines changed

7 files changed

+262
-237
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Next
44
- Add genre autocomplete
55
- Make macOS media key permission request non-intrusive
6-
- Improve crashing behaviour
6+
- Improve error and crashing behaviour
77

88
## 0.19.9 - 2025 Jul 4
99
- Fix column size not updating when resizing window

src-native/tracks/cover.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
use super::{Tag, id_to_track};
2-
use crate::data_js::get_data;
1+
use super::Tag;
32
use anyhow::{Context, Result, anyhow, bail};
43
use fast_image_resize::images::Image;
54
use fast_image_resize::{IntoImageView, Resizer};
65
use image::codecs::jpeg::JpegEncoder;
76
use image::codecs::png::PngEncoder;
87
use image::{ImageEncoder, ImageFormat, ImageReader};
98
use lazy_static::lazy_static;
10-
use napi::Env;
11-
use napi::bindgen_prelude::{Buffer, PromiseRaw};
9+
use napi::bindgen_prelude::Buffer;
1210
use redb::{Database, TableDefinition};
1311
use std::fs;
1412
use std::io::{BufWriter, Cursor};

src-native/tracks/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ pub fn import_file(path: String, now: MsSinceUnixEpoch, env: Env) -> Result<()>
162162
pub fn load_tags(track_id: String, env: Env) -> Result<()> {
163163
let data: &mut Data = get_data(&env);
164164
data.current_tag = None;
165-
let track = id_to_track(&env, &track_id)?;
165+
let track = id_to_track(&env, &track_id).context("Could not load tags")?;
166166

167167
let path = data.paths.tracks_dir.join(&track.file);
168-
let tag = Tag::read_from_path(&path)?;
168+
let tag = Tag::read_from_path(&path).context("Could not load tags")?;
169169
data.current_tag = Some(tag);
170170
Ok(())
171171
}
@@ -185,9 +185,12 @@ pub fn get_image(index: u32, env: Env) -> Result<Option<JsImage>> {
185185

186186
let tag = match &data.current_tag {
187187
Some(tag) => tag,
188-
None => return Ok(None),
188+
None => bail!("Could not load image: No tag loaded"),
189189
};
190-
let img = match tag.get_image_ref(index as usize)? {
190+
let img = match tag
191+
.get_image_ref(index as usize)
192+
.context("Could not load image")?
193+
{
191194
Some(image) => image,
192195
None => return Ok(None),
193196
};

src/App.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Player from './components/Player.svelte'
66
import Sidebar from './components/Sidebar.svelte'
77
import Queue from './components/Queue.svelte'
8-
import TrackInfo, { current_list } from './components/TrackInfo.svelte'
8+
import TrackInfo, { track_info_state } from './components/TrackInfo.svelte'
99
import PlaylistInfoModal from './components/PlaylistInfo.svelte'
1010
import { queue_visible } from './lib/queue'
1111
import { ipc_listen, ipc_renderer } from '@/lib/window'
@@ -294,8 +294,8 @@
294294
</main>
295295

296296
<QuickNav />
297-
{#if $current_list}
298-
<TrackInfo />
297+
{#if track_info_state.instance}
298+
<TrackInfo bind:instance={track_info_state.instance} />
299299
{/if}
300300
{#if playlist_info}
301301
<PlaylistInfoModal info={playlist_info} cancel={() => (playlist_info = null)} />

0 commit comments

Comments
 (0)