Skip to content

Commit 5cd6977

Browse files
committed
fix(ui): image cache safety, discord state, settings freq editing
1 parent f71c01d commit 5cd6977

3 files changed

Lines changed: 37 additions & 16 deletions

File tree

src/ui/assets/image_cache.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,12 @@ impl ImageCache for VleerImageCache {
108108
let hash = hash(resource);
109109

110110
if let Some(item) = self.cache.get_mut(&hash) {
111-
let current_idx = self
112-
.usage_list
113-
.iter()
114-
.position(|item| *item == hash)
115-
.expect("cache has an item usage_list doesn't");
116-
117-
self.usage_list.remove(current_idx);
118-
self.usage_list.push_front(hash);
111+
if let Some(current_idx) = self.usage_list.iter().position(|h| *h == hash) {
112+
self.usage_list.remove(current_idx);
113+
self.usage_list.push_front(hash);
114+
} else {
115+
self.usage_list.push_front(hash);
116+
}
119117

120118
return item.0.get();
121119
}
@@ -131,11 +129,8 @@ impl ImageCache for VleerImageCache {
131129
if self.usage_list.len() >= self.max_items {
132130
trace!("Image cache is full, evicting oldest item");
133131

134-
let oldest = self.usage_list.pop_back().unwrap();
135-
let mut image = self
136-
.cache
137-
.remove(&oldest)
138-
.expect("usage_list has an item cache doesn't");
132+
let oldest = self.usage_list.pop_back()?;
133+
let mut image = self.cache.remove(&oldest)?;
139134

140135
if let Some(Ok(image)) = image.0.get() {
141136
trace!("requesting image to be dropped");

src/ui/discord_presence.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,16 @@ impl DiscordPresence {
123123

124124
let mut act = activity::Activity::new()
125125
.details(&song.title)
126-
.state("Playing")
127126
.activity_type(activity::ActivityType::Listening)
128127
.timestamps(activity::Timestamps::new().start(start).end(end));
129128

130-
if let Some(ref name) = song.artist_name {
131-
act = act.state(name);
129+
match &song.artist_name {
130+
Some(name) => {
131+
act = act.state(name);
132+
}
133+
None => {
134+
act = act.state("Playing");
135+
}
132136
}
133137

134138
if client.set_activity(act).is_err() {

src/ui/views/settings.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,28 @@ impl SettingsView {
389389
.detach();
390390
}
391391

392+
for (i, input) in freq_inputs.iter().enumerate() {
393+
cx.subscribe(input, move |_this, _entity, event, cx| {
394+
if let InputEvent::Submit(text) = event
395+
&& let Ok(new_freq) = text.parse::<i32>()
396+
{
397+
let new_freq = new_freq.clamp(20, 20000);
398+
cx.update_global::<Config, _>(|config, _cx| {
399+
config.set(|s| {
400+
if let Some(f) = s.equalizer.frequencies.get_mut(i) {
401+
*f = new_freq;
402+
}
403+
});
404+
});
405+
cx.update_global::<Playback, _>(|playback, cx| {
406+
let config = cx.global::<Config>().clone();
407+
playback.apply_config(&config);
408+
});
409+
}
410+
})
411+
.detach();
412+
}
413+
392414
Self {
393415
gain_inputs,
394416
freq_inputs,

0 commit comments

Comments
 (0)