feat(slint): HiFi wizard review-and-apply + done steps — config generation (Slice 10)

The review step generates the copy-paste config per selected DAC (read-only —
QBZ never writes these files, Decision 2): an honest info banner, a backup
CommandBlock first, then one collapsible accordion per DAC (Decision 5 multi-DAC)
holding the three snippets ported 1:1 from the Tauri wizard — pipewire
allowed-rates, per-app bit-perfect client rules, and the WirePlumber rule that
pins node.name + rates + disables resample/channelmix — and finally an
init-aware restart CommandBlock. Rates are re-probed at generation time
(query_dac_capabilities); the filename slug is the description (fixes the old
dacShortName regex that only kept two underscore tokens). The done step lists
the config paths.

Controller: checked_dacs -> gen_configs_blocking (off-thread re-probe + template
build via line-join, no format!-brace escaping) -> apply_configs; toggle_config
flips an accordion. gen-configs fires on the select-dacs -> review transition.
2 unit tests (slugify, wireplumber pins node+rates). DacConfigRow state +
gen-configs/toggle-config actions.

cc
This commit is contained in:
vicrodh committed 2026-06-16 10:47:54 -06:00
1 parent 97fd942aa0
commit ca09b35917
5 files changed
+404 -8

No files matched your search

+218 -1
View File
@@ -11,7 +11,7 @@ use std::sync::Mutex;
use qbz_audio::{AudioStackHealth, Distro, InitSystem};
use slint::{ComponentHandle, Model, ModelRc, VecModel};
use crate::{AppWindow, DacCandidateRow, DacWizardState, RemediationRow};
use crate::{AppWindow, DacCandidateRow, DacConfigRow, DacWizardState, RemediationRow};
// Last probe result, so a distro override recomputes commands without
// re-shelling on every dropdown change.
@@ -559,3 +559,220 @@ fn khz(hz: u32) -> String {
format!("{:.1} kHz", hz as f64 / 1000.0)
}
}
// ── Slice 10: review-and-apply (per-DAC config generation) ─────────────────
/// Plain, `Send` per-DAC generated config (built on a worker thread).
pub struct DacConfigData {
name: String,
node_name: String,
pipewire_conf: String,
pulse_conf: String,
wireplumber_conf: String,
}
/// (node_name, display_name) for every checked candidate, or a valid manual one.
pub fn checked_dacs(window: &AppWindow) -> Vec<(String, String)> {
let st = window.global::<DacWizardState>();
let model = st.get_candidates();
let mut out = Vec::new();
for i in 0..model.row_count() {
if let Some(r) = model.row_data(i) {
if r.checked {
out.push((r.id.to_string(), r.description.to_string()));
}
}
}
if out.is_empty() {
let manual = st.get_manual_node_name().to_string();
if !manual.trim().is_empty() && st.get_manual_valid() {
out.push((manual.clone(), manual));
}
}
out
}
/// Re-probe rates + build the three config snippets per DAC (blocking).
pub fn gen_configs_blocking(dacs: Vec<(String, String)>) -> Vec<DacConfigData> {
dacs.into_iter()
.map(|(node_name, name)| {
let rates = qbz_audio::query_dac_capabilities(&node_name).sample_rates;
let short = short_name(&name, &node_name);
DacConfigData {
pipewire_conf: pipewire_conf(&short, &rates),
pulse_conf: pulse_conf(&short),
wireplumber_conf: wireplumber_conf(&short, &node_name, &rates, &name),
name,
node_name,
}
})
.collect()
}
/// Push generated configs + backup/restart/paths to the state.
pub fn apply_configs(window: &AppWindow, data: Vec<DacConfigData>) {
let st = window.global::<DacWizardState>();
let single = data.len() == 1;
let rows: Vec<DacConfigRow> = data
.iter()
.map(|d| DacConfigRow {
name: d.name.clone().into(),
node_name: d.node_name.clone().into(),
pipewire_conf: d.pipewire_conf.clone().into(),
pulse_conf: d.pulse_conf.clone().into(),
wireplumber_conf: d.wireplumber_conf.clone().into(),
expanded: single, // one DAC → expanded; multiple → collapsed accordions
})
.collect();
let mut paths: Vec<slint::SharedString> = Vec::new();
for d in &data {
let short = short_name(&d.name, &d.node_name);
paths.push(format!("~/.config/pipewire/pipewire.conf.d/99-qbz-dac-{short}.conf").into());
paths.push(format!("~/.config/pipewire/client.conf.d/99-qbz-bitperfect-{short}.conf").into());
paths
.push(format!("~/.config/wireplumber/wireplumber.conf.d/99-qbz-dac-{short}.conf").into());
}
st.set_dac_configs(ModelRc::new(VecModel::from(rows)));
st.set_created_paths(ModelRc::new(VecModel::from(paths)));
st.set_backup_cmd(BACKUP_CMD.into());
let init = InitSystem::ALL
.get(st.get_init_index().max(0) as usize)
.copied()
.unwrap_or(InitSystem::Unknown);
st.set_restart_cmd(restart_cmd(init).into());
}
/// Collapse/expand one DAC's generated-config accordion.
pub fn toggle_config(window: &AppWindow, index: i32) {
let model = window.global::<DacWizardState>().get_dac_configs();
if let Some(vm) = model.as_any().downcast_ref::<VecModel<DacConfigRow>>() {
if let Some(mut row) = vm.row_data(index.max(0) as usize) {
row.expanded = !row.expanded;
vm.set_row_data(index.max(0) as usize, row);
}
}
}
const BACKUP_CMD: &str = "BACKUP=~/.config/qbz/backups/pipewire-$(date +%Y%m%d-%H%M%S)\nmkdir -p \"$BACKUP\"\ncp -a ~/.config/pipewire \"$BACKUP/\" 2>/dev/null || true\ncp -a ~/.config/wireplumber \"$BACKUP/\" 2>/dev/null || true\necho \"Backup created at: $BACKUP\"";
/// A short, filename-safe DAC name: slug of the description, else the node.name.
fn short_name(name: &str, node_name: &str) -> String {
let slug = slugify(name);
if !slug.is_empty() {
return slug;
}
let nslug = slugify(node_name);
if nslug.is_empty() {
"dac".to_string()
} else {
nslug
}
}
fn slugify(s: &str) -> String {
let mut out = String::new();
let mut prev_dash = false;
for ch in s.chars() {
if ch.is_ascii_alphanumeric() {
out.push(ch.to_ascii_lowercase());
prev_dash = false;
} else if !prev_dash && !out.is_empty() {
out.push('-');
prev_dash = true;
}
}
out.trim_matches('-').to_string()
}
fn rates_list(rates: &[u32]) -> String {
if rates.is_empty() {
"44100 48000 88200 96000 176400 192000".to_string()
} else {
rates
.iter()
.map(|r| r.to_string())
.collect::<Vec<_>>()
.join(" ")
}
}
fn pipewire_conf(short: &str, rates: &[u32]) -> String {
let rates = rates_list(rates);
[
"mkdir -p ~/.config/pipewire/pipewire.conf.d".to_string(),
format!("cat > ~/.config/pipewire/pipewire.conf.d/99-qbz-dac-{short}.conf << 'EOF'"),
"# QBZ DAC Setup - Sample Rate Switching".to_string(),
"context.properties = {".to_string(),
format!(" default.clock.allowed-rates = [ {rates} ]"),
"}".to_string(),
"EOF".to_string(),
]
.join("\n")
}
fn pulse_conf(short: &str) -> String {
[
"mkdir -p ~/.config/pipewire/client.conf.d".to_string(),
format!("cat > ~/.config/pipewire/client.conf.d/99-qbz-bitperfect-{short}.conf << 'EOF'"),
"# QBZ DAC Setup - Per-App Bit-Perfect".to_string(),
"stream.rules = [".to_string(),
" {".to_string(),
" matches = [".to_string(),
" { application.process.binary = \"qbz\" }".to_string(),
" { application.name = \"PipeWire ALSA [qbz]\" }".to_string(),
" ]".to_string(),
" actions = { update-props = { resample.disable = true, channelmix.disable = true } }"
.to_string(),
" }".to_string(),
"]".to_string(),
"EOF".to_string(),
]
.join("\n")
}
fn wireplumber_conf(short: &str, node_name: &str, rates: &[u32], description: &str) -> String {
let rates = rates_list(rates);
[
"mkdir -p ~/.config/wireplumber/wireplumber.conf.d".to_string(),
format!("cat > ~/.config/wireplumber/wireplumber.conf.d/99-qbz-dac-{short}.conf << 'EOF'"),
format!("# QBZ DAC Setup - {description}"),
"monitor.alsa.rules = [".to_string(),
" {".to_string(),
" matches = [".to_string(),
format!(" {{ node.name = \"{node_name}\", media.class = \"Audio/Sink\" }}"),
" ]".to_string(),
" actions = {".to_string(),
" update-props = {".to_string(),
format!(" audio.allowed-rates = [ {rates} ]"),
" resample.disable = true".to_string(),
" channelmix.disable = true".to_string(),
" }".to_string(),
" }".to_string(),
" }".to_string(),
"]".to_string(),
"EOF".to_string(),
]
.join("\n")
}
#[cfg(test)]
mod slice10_tests {
use super::*;
#[test]
fn slugifies_descriptions() {
assert_eq!(slugify("DacMagic Plus Analog Stereo"), "dacmagic-plus-analog-stereo");
assert_eq!(slugify("Built-in Audio Analog Stereo"), "built-in-audio-analog-stereo");
assert_eq!(slugify(" weird__name!! "), "weird-name");
assert_eq!(slugify(""), "");
}
#[test]
fn wireplumber_conf_pins_node_and_rates() {
let c = wireplumber_conf("dacmagic", "alsa_output.usb-x.analog-stereo", &[44100, 192000], "DacMagic");
assert!(c.contains("node.name = \"alsa_output.usb-x.analog-stereo\""));
assert!(c.contains("audio.allowed-rates = [ 44100 192000 ]"));
assert!(c.contains("99-qbz-dac-dacmagic.conf"));
assert!(c.contains("resample.disable = true"));
}
}
+27
View File
@@ -11498,6 +11498,33 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let _ = runtime.core().resume();
});
}
{
// Generate the per-DAC copy-paste config (Slice 10): re-probe rates off
// the UI thread, then fill the review step.
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
window.global::<DacWizardActions>().on_gen_configs(move || {
let Some(w) = weak.upgrade() else {
return;
};
let dacs = dac_wizard::checked_dacs(&w);
let weak2 = w.as_weak();
handle.spawn_blocking(move || {
let data = dac_wizard::gen_configs_blocking(dacs);
let _ = weak2.upgrade_in_event_loop(move |w| {
dac_wizard::apply_configs(&w, data);
});
});
});
}
{
let weak = window.as_weak();
window.global::<DacWizardActions>().on_toggle_config(move |i| {
if let Some(w) = weak.upgrade() {
dac_wizard::toggle_config(&w, i);
}
});
}
{
window
.global::<DacWizardActions>()
+1 -1
View File
@@ -19,7 +19,7 @@ import { Toast } from "primitives/Toast.slint";
import { ShellState } from "state.slint";
// Re-export the state globals so the Rust layer can populate them.
export { HomeState, HomeActions, DiscoverState, DiscoverActions, SectionDescriptor, ConfigRow, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, ShellState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, LyricsState, LyricsLineItem, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, DuplicateConfirmState, DuplicateConfirmActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, SidebarFolderPopupState, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, MyQbzCreateState, MyQbzCreateActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, MyQbzState, MyQbzActions, MixtapeCardItem, MyQbzAddState, MyQbzAddActions, MyQbzAddRow, MyQbzDetailState, MyQbzDetailActions, MixtapeDetailItem, MyQbzEditState, MyQbzEditActions, MyQbzMixState, MyQbzMixActions, DiscoBuilderState, DiscoBuilderActions, DiscoGroup, DiscoCandidate, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, LibAlbumFilterState, LocalAlbumState, LocalAlbumActions, TagEditorState, TagEditorActions, FolderEditState, FolderEditActions, ToastState, TextUtil, QconnectDevState, QconnectDevice, AppearanceState, MyQbzBrandingState, EphemeralPlayChoiceState, EphemeralPlayChoiceActions, PlexSettingsState, PlexAuthActions, PlexSectionItem, ScrobbleState, ScrobbleActions, OfflineState, OfflineModeActions, OfflineFavoritesState, OfflineFavoritesActions, ImportLogEntry, PlaylistImportState, PlaylistImportActions, DacWizardState, DacWizardActions, DacCandidateRow, RemediationRow, InfoCreditRow, InfoCreditPair, AlbumCreditPerformer, AlbumCreditTrack, TrackInfoState, TrackInfoActions, AlbumInfoState, AlbumInfoActions, VisualizerState, ImmersiveState } from "state.slint";
export { HomeState, HomeActions, DiscoverState, DiscoverActions, SectionDescriptor, ConfigRow, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, ShellState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, LyricsState, LyricsLineItem, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, DuplicateConfirmState, DuplicateConfirmActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, SidebarFolderPopupState, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, MyQbzCreateState, MyQbzCreateActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, MyQbzState, MyQbzActions, MixtapeCardItem, MyQbzAddState, MyQbzAddActions, MyQbzAddRow, MyQbzDetailState, MyQbzDetailActions, MixtapeDetailItem, MyQbzEditState, MyQbzEditActions, MyQbzMixState, MyQbzMixActions, DiscoBuilderState, DiscoBuilderActions, DiscoGroup, DiscoCandidate, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, LibAlbumFilterState, LocalAlbumState, LocalAlbumActions, TagEditorState, TagEditorActions, FolderEditState, FolderEditActions, ToastState, TextUtil, QconnectDevState, QconnectDevice, AppearanceState, MyQbzBrandingState, EphemeralPlayChoiceState, EphemeralPlayChoiceActions, PlexSettingsState, PlexAuthActions, PlexSectionItem, ScrobbleState, ScrobbleActions, OfflineState, OfflineModeActions, OfflineFavoritesState, OfflineFavoritesActions, ImportLogEntry, PlaylistImportState, PlaylistImportActions, DacWizardState, DacWizardActions, DacCandidateRow, RemediationRow, DacConfigRow, InfoCreditRow, InfoCreditPair, AlbumCreditPerformer, AlbumCreditTrack, TrackInfoState, TrackInfoActions, AlbumInfoState, AlbumInfoActions, VisualizerState, ImmersiveState } from "state.slint";
// Which top-level screen is shown. The app starts on `splash` while it
// restores a saved session, then resolves to `shell` or `login`.
@@ -459,9 +459,100 @@ export component DacWizardModal inherits Rectangle {
}
}
}
if DacWizardState.step == 3: StepPlaceholder {
title: @tr("Review & Apply");
note: @tr("Backup, per-DAC sample rates, and the copy-paste config files (Slice 10).");
// ── Step 3: review & apply (copy-paste config) ───
if DacWizardState.step == 3: VerticalLayout {
spacing: 14px;
Text {
text: @tr("Review & Apply");
color: Theme.text-primary;
font-size: Typography.heading;
font-weight: Typography.semibold;
}
WarningBanner {
variant: "info";
title: @tr("QBZ never writes these files");
body: @tr("QBZ already pins rate, sink and exclusive mode at runtime. These files only change system-wide behavior — copy and run them yourself if you want them. Back up first.");
}
// 1. Backup.
CommandBlock {
caption: @tr("1. Back up your current PipeWire/WirePlumber config");
command: DacWizardState.backup-cmd;
copy => {
DacWizardActions.copy-command(DacWizardState.backup-cmd);
}
}
// 2. Per-DAC config — collapsible accordions.
for cfg[i] in DacWizardState.dac-configs: VerticalLayout {
spacing: 8px;
Rectangle {
height: 40px;
border-radius: Radius.sm;
background: chead.has-hover ? Theme.surface-hover : Theme.surface-elevated;
border-width: 1px;
border-color: Theme.border-subtle;
HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
spacing: 8px;
QbzIcon {
width: 16px;
height: 16px;
y: (parent.height - self.height) / 2;
source: cfg.expanded
? @image-url("../assets/icons/chevron-down.svg")
: @image-url("../assets/icons/chevron-right.svg");
tint: Theme.text-muted;
}
Text {
text: cfg.name;
color: Theme.text-primary;
font-size: Typography.body;
font-weight: Typography.medium;
vertical-alignment: center;
overflow: elide;
horizontal-stretch: 1;
}
}
chead := TouchArea {
mouse-cursor: pointer;
clicked => {
DacWizardActions.toggle-config(i);
}
}
}
if cfg.expanded: VerticalLayout {
spacing: 8px;
CommandBlock {
caption: @tr("Sample-rate switching (PipeWire)");
command: cfg.pipewire-conf;
copy => {
DacWizardActions.copy-command(cfg.pipewire-conf);
}
}
CommandBlock {
caption: @tr("Per-app bit-perfect (PipeWire client)");
command: cfg.pulse-conf;
copy => {
DacWizardActions.copy-command(cfg.pulse-conf);
}
}
CommandBlock {
caption: @tr("Pin the DAC + rates (WirePlumber)");
command: cfg.wireplumber-conf;
copy => {
DacWizardActions.copy-command(cfg.wireplumber-conf);
}
}
}
}
// 3. Restart (init-aware).
CommandBlock {
caption: @tr("3. Restart the audio services to load the config");
command: DacWizardState.restart-cmd;
copy => {
DacWizardActions.copy-command(DacWizardState.restart-cmd);
}
}
}
// ── Step 4: self-service playback test ───────────
if DacWizardState.step == 4: VerticalLayout {
@@ -590,9 +681,48 @@ export component DacWizardModal inherits Rectangle {
}
}
}
if DacWizardState.step == 5: StepPlaceholder {
title: @tr("All set");
note: @tr("Summary and the config paths you created (Slice 10).");
// ── Step 5: done ─────────────────────────────────
if DacWizardState.step == 5: VerticalLayout {
spacing: 14px;
HorizontalLayout {
spacing: 10px;
alignment: start;
QbzIcon {
width: 24px;
height: 24px;
source: @image-url("../assets/icons/circle-check-big.svg");
tint: #3fae6a;
}
Text {
text: @tr("All set");
color: Theme.text-primary;
font-size: Typography.heading;
font-weight: Typography.semibold;
vertical-alignment: center;
}
}
Text {
text: @tr("Your DAC is ready for bit-perfect playback. If you applied the config files, restart the audio services (or log out and back in) for them to take effect.");
color: Theme.text-secondary;
font-size: Typography.body;
wrap: word-wrap;
}
if DacWizardState.created-paths.length > 0: VerticalLayout {
spacing: 6px;
Text {
text: @tr("Config files you can create:");
color: Theme.text-secondary;
font-size: Typography.legal;
font-weight: Typography.medium;
}
for p in DacWizardState.created-paths: Text {
text: p;
color: Theme.text-muted;
font-size: Typography.legal;
font-family: "monospace";
overflow: elide;
}
}
}
}
}
@@ -638,6 +768,10 @@ export component DacWizardModal inherits Rectangle {
if (DacWizardState.step == 1) {
DacWizardActions.run-detect();
}
// Entering review generates the per-DAC config.
if (DacWizardState.step == 2) {
DacWizardActions.gen-configs();
}
DacWizardState.step += 1;
}
}
+18
View File
@@ -3876,6 +3876,16 @@ export struct DacCandidateRow {
rates-label: string, // pre-filled supported rates, e.g. "44.1 / 96 / 192 kHz"
}
// One selected DAC's generated copy-paste config (Slice 10, read-only).
export struct DacConfigRow {
name: string,
node-name: string,
pipewire-conf: string,
pulse-conf: string,
wireplumber-conf: string,
expanded: bool, // accordion state
}
export global DacWizardState {
in-out property <bool> open: false;
// 0 welcome · 1 check · 2 select-dacs · 3 review · 4 test · 5 done
@@ -3912,6 +3922,12 @@ export global DacWizardState {
in-out property <string> test-negotiated-label: ""; // "DAC running at 96000 Hz" (N6)
in-out property <bool> test-rate-matched: false;
in-out property <bool> test-playing: false;
// review-and-apply (Slice 10): generated copy-paste config per selected DAC.
in-out property <[DacConfigRow]> dac-configs: [];
in-out property <string> backup-cmd: "";
in-out property <string> restart-cmd: "";
in-out property <[string]> created-paths: []; // done step
}
export global DacWizardActions {
@@ -3929,4 +3945,6 @@ export global DacWizardActions {
callback poll-test(); // refresh the requested-vs-negotiated read-back
callback test-play-index(int); // jump straight to one of the 4 test tracks
callback stop-test();
callback gen-configs(); // build the per-DAC copy-paste config (Slice 10)
callback toggle-config(int); // collapse/expand one DAC's config accordion
}