Skip to content

Commit 8a6a1da

Browse files
committed
desktop-app: Extract application logic from rendering
1 parent ae9eec7 commit 8a6a1da

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

demo-app/src/library/mod.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,23 @@ impl Library {
131131
}
132132
}
133133

134+
pub fn could_reset_music_dir(&self) -> bool {
135+
self.state()
136+
.settings()
137+
.read_observable()
138+
.music_dir
139+
.is_some()
140+
}
141+
134142
pub fn reset_music_dir(&self) {
135143
self.update_music_dir(None);
136144
}
137145

146+
pub fn could_spawn_rescan_collection_task(&self) -> bool {
147+
self.pending_rescan_collection_task.is_none()
148+
&& self.state().collection().read_observable().is_ready()
149+
}
150+
138151
pub fn spawn_rescan_collection_task(&mut self, rt: &tokio::runtime::Handle) -> bool {
139152
if let Some(rescan_collection_task) = self.pending_rescan_collection_task.as_ref() {
140153
if rescan_collection_task.is_finished() {
@@ -165,10 +178,6 @@ impl Library {
165178
changed
166179
}
167180

168-
pub const fn has_pending_rescan_collection_task(&self) -> bool {
169-
self.pending_rescan_collection_task.is_some()
170-
}
171-
172181
pub fn abort_pending_rescan_collection_task(&mut self) -> Option<SynchronizeVfsTask> {
173182
let pending_rescan_collection_task = self.pending_rescan_collection_task.take();
174183
let Some(rescan_collection_task) = pending_rescan_collection_task else {
@@ -200,6 +209,14 @@ impl Library {
200209
}
201210
}
202211

212+
pub fn could_spawn_fetch_more_track_search_results(&self) -> bool {
213+
self.state
214+
.track_search()
215+
.read_observable()
216+
.can_fetch_more()
217+
.unwrap_or(false)
218+
}
219+
203220
pub fn spawn_fetch_more_track_search_results<E>(
204221
&self,
205222
tokio_rt: &tokio::runtime::Handle,

demo-app/src/main.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl eframe::App for App {
476476
ui.label("");
477477
if ui
478478
.add_enabled(
479-
settings_state.music_dir.is_some(),
479+
self.library.could_reset_music_dir(),
480480
Button::new("Reset music directory"),
481481
)
482482
.clicked()
@@ -521,8 +521,7 @@ impl eframe::App for App {
521521
ui.label("");
522522
if ui
523523
.add_enabled(
524-
collection_state.is_ready()
525-
&& !self.library.has_pending_rescan_collection_task(),
524+
self.library.could_spawn_rescan_collection_task(),
526525
Button::new("Rescan collection"),
527526
)
528527
.clicked()
@@ -556,7 +555,7 @@ impl eframe::App for App {
556555
.show(ui, |ui| {
557556
if ui
558557
.add_enabled(
559-
track_search_state.can_fetch_more().unwrap_or(false),
558+
self.library.could_spawn_fetch_more_track_search_results(),
560559
Button::new("Fetch more"),
561560
)
562561
.clicked()

0 commit comments

Comments
 (0)