feat(locallibrary): library scan engine + progress (Slice B)

Lift the Tauri scan-orchestration loop into the core crate and drive it from
Settings > Local Library with live progress + cancel.

Core (qbz-library/src/scan.rs): scan_with_progress(db, folder_ids, artwork_cache,
cancel, on_event) replicates v2_library_scan (full) and v2_library_scan_folder
(single) byte-for-byte: CUE files first, per-album sidecar override, embedded ->
folder artwork with a per-folder cache, insert, and missing-file cleanup (whole
DB for full, folder-prefix for single). Progress is pushed through a ScanEvent
callback (no IPC poll) and a cancel AtomicBool is checked at every file boundary
(no cleanup/scan-time on cancel, Tauri parity). Two verified improvements: the
full scan now stamps each folder's last_scan, and network status is re-detected
for every non-overridden scanned folder.

Slint: LibraryScanState global (single poll target; progress computed Rust-side);
a determinate 2-rect progress bar + counts + current-file + Stop button in the
panel; scan-all disabled while running. Controller run_scan() on spawn_blocking
with a ~100ms-coalesced sink (terminal/phase events bypass throttling), an owned
SCAN_CANCEL token, an outcome toast, and a post-scan reload (folder list +
reset browse models so the tabs re-fetch). scan-all/scan-folder/stop-scan wired.

cc
This commit is contained in:
vicrodh committed 2026-05-29 13:16:21 -06:00
1 parent 3826298f77
commit aa7c320b94
7 files changed
+644 -5

No files matched your search

@@ -9,7 +9,7 @@
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { LibraryFoldersState, LibraryManageActions } from "../state.slint";
import { LibraryFoldersState, LibraryManageActions, LibraryScanState } from "../state.slint";
import { SettingRow } from "SettingRow.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
import { QbzCheckbox } from "../primitives/QbzCheckbox.slint";
@@ -178,6 +178,7 @@ export component LocalLibrarySettings inherits VerticalLayout {
// Toolbar: scan-all / add / edit (one selected) / remove (any selected).
IconBtn {
icon: @image-url("../assets/icons/refresh-cw.svg");
enabled: !LibraryScanState.scanning;
clicked => { LibraryManageActions.scan-all(); }
}
IconBtn {
@@ -237,6 +238,82 @@ export component LocalLibrarySettings inherits VerticalLayout {
}
}
// --- Scan progress (determinate; only while scanning) ----------------
if LibraryScanState.scanning: Rectangle {
height: scan-box.preferred-height + 24px;
VerticalLayout {
scan-box := VerticalLayout {
padding-top: 14px;
spacing: 8px;
HorizontalLayout {
Text {
text: @tr("Scanning") + ": \{LibraryScanState.processed-files} / \{LibraryScanState.total-files}";
color: Theme.text-secondary;
font-size: Typography.body;
font-weight: Typography.medium;
horizontal-stretch: 1;
vertical-alignment: center;
}
// Stop scan.
Rectangle {
width: stop-row.preferred-width + 22px;
height: 30px;
border-radius: Radius.sm;
border-width: 1px;
border-color: #e0564f;
background: stop-ta.has-hover ? #e0564f22 : transparent;
stop-row := HorizontalLayout {
x: (parent.width - self.width) / 2;
spacing: 6px;
VerticalLayout {
alignment: center;
QbzIcon {
source: @image-url("../assets/icons/x.svg");
width: 13px;
height: 13px;
tint: #e0564f;
}
}
VerticalLayout {
alignment: center;
Text {
text: @tr("Stop");
color: #e0564f;
font-size: Typography.legal;
font-weight: Typography.semibold;
}
}
}
stop-ta := TouchArea {
mouse-cursor: pointer;
clicked => { LibraryManageActions.stop-scan(); }
}
}
}
// Determinate bar (2 rectangles; ADR-008-clean).
Rectangle {
height: 6px;
border-radius: 3px;
background: Theme.surface-elevated;
clip: true;
Rectangle {
x: 0;
width: parent.width * LibraryScanState.progress;
height: parent.height;
border-radius: 3px;
background: Theme.accent;
}
}
if LibraryScanState.current-file != "": Text {
text: LibraryScanState.current-file;
color: Theme.text-muted;
font-size: Typography.legal;
overflow: elide;
}
}
}
}
Rectangle { height: 22px; }
// --- Maintenance -----------------------------------------------------