feat(qbz-slint): wire theme persistence + Rust-driven palette apply
Connect the qbz-theme registry to the running app and persist the choice across restarts (owner hard requirement 2026-06-20). - `src/theme.rs`: Rgba->slint::Color conversion, `to_slint` building the generated `ThemeColors` (55 fields, exact name parity with the Slint struct), `apply_theme` (set_c + set_is_system), and slug<->index<->id mapping with slug as the source of truth. Unit tests cover the roundtrip + fallbacks. - `ui_prefs.rs`: new `theme: String` slug field, `#[serde(default)]` -> `qbz_theme::default_slug()` (OLED). Old profiles without the field restore to OLED. Tests assert the default. - `main.rs`: add the missing `"theme"` arm in `on_appearance_select` (was falling into the debug `other =>` arm) — maps dropdown index to id, persists the slug, hot-switches the palette. Startup restore seeds the dropdown list from the registry, derives the index from the persisted slug, syncs the legacy `ThemeState.mode`, and applies the theme before first paint. - `app.slint`: export `Theme`/`ThemeColors`/`ThemeState` so Rust can drive them. - `AppearanceSettings.slint`/`state.slint`: the theme list is now Rust-seeded; comments updated (index no longer drives colors; slug is source of truth). Headline acceptance: pick a theme, quit, relaunch -> same theme; fresh profile boots into OLED Dark. The 4 existing themes are unchanged (legacy alias values preserved in the registry). cc
This commit is contained in:
8 files changed
+245
-7
No files matched your search
@@ -11,7 +11,8 @@ import "assets/fonts/Inter_18pt-Medium.ttf";
|
||||
import "assets/fonts/Inter_18pt-SemiBold.ttf";
|
||||
import "assets/fonts/Inter_18pt-Bold.ttf";
|
||||
|
||||
import { Theme } from "foundation/semantic-colors.slint";
|
||||
import { Theme, ThemeColors } from "foundation/semantic-colors.slint";
|
||||
import { ThemeState } from "foundation/theme-state.slint";
|
||||
import { SplashScreen } from "splash/SplashScreen.slint";
|
||||
import { LoginScreen } from "login/LoginScreen.slint";
|
||||
import { AppShell } from "shell/AppShell.slint";
|
||||
@@ -19,6 +20,11 @@ import { Toast } from "primitives/Toast.slint";
|
||||
import { ShellState, MiniPlayerState } from "state.slint";
|
||||
import { MiniShell } from "miniplayer/MiniShell.slint";
|
||||
|
||||
// Re-export the theming globals so the Rust layer can push palettes (Theme.c /
|
||||
// Theme.is-system) and keep the dropdown index (ThemeState.mode) in sync.
|
||||
export { Theme, ThemeColors } from "foundation/semantic-colors.slint";
|
||||
export { ThemeState } from "foundation/theme-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, AwardState, AwardActions, AwardEntry, 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, BlacklistState, BlacklistActions, BlacklistedArtistItem, 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, CastState, CastDevice, CastActions, 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, SuggestionsState, SuggestionsActions, SuggestionCard, VisualizerState, ImmersiveState, MiniPlayerState, WindowControlActions } from "state.slint";
|
||||
|
||||
|
||||
@@ -164,9 +164,10 @@ export component AppearanceSettings inherits VerticalLayout {
|
||||
current-index: AppearanceState.theme-index;
|
||||
selected(i) => {
|
||||
AppearanceState.theme-index = i;
|
||||
// The themes list is trimmed to the ported set, so the
|
||||
// dropdown index maps 1:1 to the mode (0 Dark, 1 OLED,
|
||||
// 2 Tokyo Night, 3 System).
|
||||
// The Rust handler ("theme" arm) maps this dropdown index to
|
||||
// a stable theme id, persists the slug, and hot-switches the
|
||||
// palette via Theme.set_c. ThemeState.mode is kept in sync
|
||||
// only as a legacy index reference (no longer drives colors).
|
||||
ThemeState.mode = i;
|
||||
AppearanceState.appearance-select("theme", i);
|
||||
}
|
||||
|
||||
@@ -2537,8 +2537,10 @@ export global SettingsState {
|
||||
// so the UI renders standalone even while unwired.
|
||||
export global AppearanceState {
|
||||
// --- THEME -------------------------------------------------------------
|
||||
// Only the themes that are actually ported/wired. Order is load-bearing:
|
||||
// the index maps 1:1 to ThemeState.mode (0 Dark, 1 OLED, 2 Tokyo, 3 System).
|
||||
// Seeded at startup by Rust from the qbz-theme registry
|
||||
// (theme::dropdown_labels), in registry display order. The list below is a
|
||||
// standalone-preview fallback only; the index is DERIVED from the persisted
|
||||
// theme slug (theme::index_for_id), never assumed.
|
||||
in-out property <[string]> themes: [
|
||||
"Dark", "OLED Black", "Tokyo Night", "System"
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user