Wire AppearanceSettings into BrowserCore + snapshot
BrowserCore now owns an AppearanceSettings, exposes it through BrowserSnapshot.appearance, and offers set_wallpaper_theme, set_theme_mode, set_reduce_motion, reset_appearance mutators. Defaults match the domain defaults (Dawn / System / motion-on) so existing behaviour is unchanged for callers who don't touch appearance. Integration tests cover initial snapshot defaults, mutation persistence across snapshots, and reset behaviour.
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
use std::{collections::BTreeMap, time::SystemTime};
|
use std::{collections::BTreeMap, time::SystemTime};
|
||||||
|
|
||||||
use ely_domain::{
|
use ely_domain::{
|
||||||
ArchivePolicy, ArchivedTab, BookmarkEntry, BrowserTab, DEFAULT_SIDEBAR_WIDTH_PX,
|
AppearanceSettings, ArchivePolicy, ArchivedTab, BookmarkEntry, BrowserTab,
|
||||||
DiagnosticEvent, DiagnosticsReportingPolicy, DomainError, DownloadEntry, DownloadPolicy,
|
DEFAULT_SIDEBAR_WIDTH_PX, DiagnosticEvent, DiagnosticsReportingPolicy, DomainError,
|
||||||
FavoriteLimit, HistoryEntry, HistoryRecordingPolicy, NewTabDestination, NoteEntry, Profile,
|
DownloadEntry, DownloadPolicy, FavoriteLimit, HistoryEntry, HistoryRecordingPolicy,
|
||||||
ProfileId, ProfileKind, ReadingListEntry, SearchEngine, SitePermissionAuditEvent,
|
NewTabDestination, NoteEntry, Profile, ProfileId, ProfileKind, ReadingListEntry, SearchEngine,
|
||||||
SitePermissionEntry, Space, SpaceId, SplitLayout, SyncStatus, TabGroup, TabId, UpdatePolicy,
|
SitePermissionAuditEvent, SitePermissionEntry, Space, SpaceId, SplitLayout, SyncStatus,
|
||||||
UrlText,
|
TabGroup, TabId, ThemeMode, UpdatePolicy, UrlText, WallpaperTheme,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{CoreError, navigation::tab_title};
|
use crate::{CoreError, navigation::tab_title};
|
||||||
@@ -124,6 +124,7 @@ pub struct BrowserSnapshot {
|
|||||||
pub diagnostics_reporting_policy: DiagnosticsReportingPolicy,
|
pub diagnostics_reporting_policy: DiagnosticsReportingPolicy,
|
||||||
pub favorite_limit: FavoriteLimit,
|
pub favorite_limit: FavoriteLimit,
|
||||||
pub update_policy: UpdatePolicy,
|
pub update_policy: UpdatePolicy,
|
||||||
|
pub appearance: AppearanceSettings,
|
||||||
pub command_query: String,
|
pub command_query: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +159,7 @@ pub struct BrowserCore {
|
|||||||
diagnostics_reporting_policy: DiagnosticsReportingPolicy,
|
diagnostics_reporting_policy: DiagnosticsReportingPolicy,
|
||||||
favorite_limit: FavoriteLimit,
|
favorite_limit: FavoriteLimit,
|
||||||
update_policy: UpdatePolicy,
|
update_policy: UpdatePolicy,
|
||||||
|
appearance: AppearanceSettings,
|
||||||
sync_object_policies: SyncObjectPolicies,
|
sync_object_policies: SyncObjectPolicies,
|
||||||
command_query: String,
|
command_query: String,
|
||||||
}
|
}
|
||||||
@@ -205,6 +207,7 @@ impl BrowserCore {
|
|||||||
diagnostics_reporting_policy: DiagnosticsReportingPolicy::default(),
|
diagnostics_reporting_policy: DiagnosticsReportingPolicy::default(),
|
||||||
favorite_limit: FavoriteLimit::default(),
|
favorite_limit: FavoriteLimit::default(),
|
||||||
update_policy: UpdatePolicy::default(),
|
update_policy: UpdatePolicy::default(),
|
||||||
|
appearance: AppearanceSettings::default(),
|
||||||
sync_object_policies: SyncObjectPolicies::default(),
|
sync_object_policies: SyncObjectPolicies::default(),
|
||||||
spaces: vec![space],
|
spaces: vec![space],
|
||||||
profiles: vec![profile],
|
profiles: vec![profile],
|
||||||
@@ -365,6 +368,27 @@ impl BrowserCore {
|
|||||||
self.update_policy
|
self.update_policy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn appearance(&self) -> AppearanceSettings {
|
||||||
|
self.appearance
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_wallpaper_theme(&mut self, wallpaper: WallpaperTheme) {
|
||||||
|
self.appearance.set_wallpaper(wallpaper);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_theme_mode(&mut self, theme_mode: ThemeMode) {
|
||||||
|
self.appearance.set_theme_mode(theme_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_reduce_motion(&mut self, reduce_motion: bool) {
|
||||||
|
self.appearance.set_reduce_motion(reduce_motion);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset_appearance(&mut self) {
|
||||||
|
self.appearance = AppearanceSettings::default();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_command_query(&mut self, query: impl Into<String>) {
|
pub fn set_command_query(&mut self, query: impl Into<String>) {
|
||||||
self.command_query = query.into();
|
self.command_query = query.into();
|
||||||
}
|
}
|
||||||
@@ -414,6 +438,7 @@ impl BrowserCore {
|
|||||||
diagnostics_reporting_policy: self.diagnostics_reporting_policy,
|
diagnostics_reporting_policy: self.diagnostics_reporting_policy,
|
||||||
favorite_limit: self.favorite_limit,
|
favorite_limit: self.favorite_limit,
|
||||||
update_policy: self.update_policy,
|
update_policy: self.update_policy,
|
||||||
|
appearance: self.appearance,
|
||||||
command_query: self.command_query.clone(),
|
command_query: self.command_query.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
use std::error::Error;
|
||||||
|
|
||||||
|
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||||
|
use ely_domain::{ThemeMode, WallpaperTheme};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn snapshot_starts_with_default_appearance() -> Result<(), Box<dyn Error>> {
|
||||||
|
let core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
let snapshot = core.snapshot()?;
|
||||||
|
|
||||||
|
assert_eq!(snapshot.appearance.wallpaper(), WallpaperTheme::Dawn);
|
||||||
|
assert_eq!(snapshot.appearance.theme_mode(), ThemeMode::System);
|
||||||
|
assert!(!snapshot.appearance.reduce_motion());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn setters_persist_into_subsequent_snapshots() -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
|
||||||
|
core.set_wallpaper_theme(WallpaperTheme::Mint);
|
||||||
|
core.set_theme_mode(ThemeMode::Dark);
|
||||||
|
core.set_reduce_motion(true);
|
||||||
|
|
||||||
|
let snapshot = core.snapshot()?;
|
||||||
|
assert_eq!(snapshot.appearance.wallpaper(), WallpaperTheme::Mint);
|
||||||
|
assert_eq!(snapshot.appearance.theme_mode(), ThemeMode::Dark);
|
||||||
|
assert!(snapshot.appearance.reduce_motion());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn reset_appearance_restores_defaults() -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
|
||||||
|
core.set_wallpaper_theme(WallpaperTheme::Slate);
|
||||||
|
core.set_theme_mode(ThemeMode::Light);
|
||||||
|
core.set_reduce_motion(true);
|
||||||
|
core.reset_appearance();
|
||||||
|
|
||||||
|
let snapshot = core.snapshot()?;
|
||||||
|
assert_eq!(snapshot.appearance.wallpaper(), WallpaperTheme::Dawn);
|
||||||
|
assert_eq!(snapshot.appearance.theme_mode(), ThemeMode::System);
|
||||||
|
assert!(!snapshot.appearance.reduce_motion());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user