Add settings reset defaults
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use std::{collections::BTreeMap, time::SystemTime};
|
||||
|
||||
use ely_domain::{
|
||||
ArchivePolicy, ArchivedTab, BookmarkEntry, BrowserTab, DomainError, DownloadEntry,
|
||||
DownloadPolicy, FavoriteLimit, HistoryEntry, HistoryRecordingPolicy, NewTabDestination,
|
||||
NoteEntry, Profile, ProfileId, ProfileKind, ReadingListEntry, SearchEngine,
|
||||
ArchivePolicy, ArchivedTab, BookmarkEntry, BrowserTab, DEFAULT_SIDEBAR_WIDTH_PX, DomainError,
|
||||
DownloadEntry, DownloadPolicy, FavoriteLimit, HistoryEntry, HistoryRecordingPolicy,
|
||||
NewTabDestination, NoteEntry, Profile, ProfileId, ProfileKind, ReadingListEntry, SearchEngine,
|
||||
SitePermissionAuditEvent, SitePermissionEntry, Space, SpaceId, SplitLayout, SyncStatus,
|
||||
TabGroup, TabId, UrlText,
|
||||
};
|
||||
@@ -292,6 +292,10 @@ impl BrowserCore {
|
||||
self.search_engine = search_engine;
|
||||
}
|
||||
|
||||
pub fn reset_search_settings(&mut self) {
|
||||
self.set_search_engine(SearchEngine::default());
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn search_engine(&self) -> SearchEngine {
|
||||
self.search_engine
|
||||
@@ -301,6 +305,10 @@ impl BrowserCore {
|
||||
self.new_tab_destination = destination;
|
||||
}
|
||||
|
||||
pub fn reset_general_settings(&mut self) {
|
||||
self.set_new_tab_destination(NewTabDestination::default());
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new_tab_destination(&self) -> NewTabDestination {
|
||||
self.new_tab_destination
|
||||
@@ -310,6 +318,10 @@ impl BrowserCore {
|
||||
self.history_recording_policy = policy;
|
||||
}
|
||||
|
||||
pub fn reset_privacy_settings(&mut self) {
|
||||
self.set_history_recording_policy(HistoryRecordingPolicy::default());
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn history_recording_policy(&self) -> HistoryRecordingPolicy {
|
||||
self.history_recording_policy
|
||||
@@ -319,6 +331,14 @@ impl BrowserCore {
|
||||
self.favorite_limit = favorite_limit;
|
||||
}
|
||||
|
||||
pub fn reset_sidebar_tabs_settings(&mut self) -> Result<(), CoreError> {
|
||||
let active_space_id = self.active_space_id.clone();
|
||||
self.set_space_archive_policy(&active_space_id, ArchivePolicy::Manual)?;
|
||||
self.set_space_sidebar_width(&active_space_id, DEFAULT_SIDEBAR_WIDTH_PX)?;
|
||||
self.set_favorite_limit(FavoriteLimit::default());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn favorite_limit(&self) -> FavoriteLimit {
|
||||
self.favorite_limit
|
||||
|
||||
@@ -90,6 +90,10 @@ impl BrowserCore {
|
||||
self.set_profile_download_policy(&profile_id, download_policy)
|
||||
}
|
||||
|
||||
pub fn reset_active_profile_download_settings(&mut self) -> Result<(), CoreError> {
|
||||
self.set_active_profile_download_policy(DownloadPolicy::ask_every_time())
|
||||
}
|
||||
|
||||
pub fn set_profile_sync_policy(
|
||||
&mut self,
|
||||
profile_id: &ProfileId,
|
||||
@@ -108,6 +112,12 @@ impl BrowserCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reset_profile_sync_settings(&mut self) {
|
||||
for profile in &mut self.profiles {
|
||||
profile.set_sync_policy(ProfileSyncPolicy::default());
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn cleanup_private_profile_session_data(&mut self, profile_id: &ProfileId) {
|
||||
if self
|
||||
.profiles
|
||||
|
||||
@@ -66,6 +66,10 @@ impl BrowserCore {
|
||||
self.sync_object_policies.set(kind, policy);
|
||||
}
|
||||
|
||||
pub fn reset_sync_settings(&mut self) {
|
||||
self.sync_object_policies = SyncObjectPolicies::default();
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn sync_object_policy(&self, kind: SyncObjectKind) -> SyncObjectPolicy {
|
||||
self.sync_object_policies.get(kind)
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
use std::{error::Error, path::PathBuf};
|
||||
|
||||
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||
use ely_domain::{
|
||||
ArchivePolicy, DEFAULT_SIDEBAR_WIDTH_PX, DownloadPolicy, FavoriteLimit, HistoryRecordingPolicy,
|
||||
NewTabDestination, ProfileKind, ProfileSyncPolicy, SearchEngine, SyncObjectKind,
|
||||
SyncObjectPolicy,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn section_resets_restore_settings_defaults() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
core.set_new_tab_destination(NewTabDestination::Bookmarks);
|
||||
core.reset_general_settings();
|
||||
assert_eq!(core.snapshot()?.new_tab_destination, NewTabDestination::ElyNewTab);
|
||||
|
||||
core.set_search_engine(SearchEngine::Google);
|
||||
core.reset_search_settings();
|
||||
assert_eq!(core.snapshot()?.search_engine, SearchEngine::DuckDuckGo);
|
||||
|
||||
core.set_history_recording_policy(HistoryRecordingPolicy::Pause);
|
||||
core.reset_privacy_settings();
|
||||
assert_eq!(core.snapshot()?.history_recording_policy, HistoryRecordingPolicy::Record);
|
||||
|
||||
let active_space_id = core.snapshot()?.active_space_id;
|
||||
core.set_active_space_archive_policy(ArchivePolicy::IdleDays(30))?;
|
||||
core.set_space_sidebar_width(&active_space_id, 56)?;
|
||||
core.set_favorite_limit(FavoriteLimit::Six);
|
||||
core.reset_sidebar_tabs_settings()?;
|
||||
|
||||
let snapshot = core.snapshot()?;
|
||||
let Some(active_space) = snapshot.spaces.iter().find(|space| space.id() == &active_space_id)
|
||||
else {
|
||||
return Err("missing active space".into());
|
||||
};
|
||||
assert_eq!(active_space.archive_policy(), &ArchivePolicy::Manual);
|
||||
assert_eq!(active_space.sidebar_width_px(), DEFAULT_SIDEBAR_WIDTH_PX);
|
||||
assert_eq!(snapshot.favorite_limit, FavoriteLimit::Twelve);
|
||||
|
||||
core.set_active_profile_download_policy(DownloadPolicy::fixed_directory(PathBuf::from(
|
||||
"/tmp",
|
||||
))?)?;
|
||||
core.reset_active_profile_download_settings()?;
|
||||
assert_eq!(core.snapshot()?.active_download_policy, DownloadPolicy::ask_every_time());
|
||||
|
||||
core.set_sync_object_policy(SyncObjectKind::Tabs, SyncObjectPolicy::Paused);
|
||||
core.reset_sync_settings();
|
||||
assert_eq!(core.sync_object_policy(SyncObjectKind::Tabs), SyncObjectPolicy::Enabled);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn profile_sync_reset_restores_profile_kind_defaults() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let standard_profile_id = core.snapshot()?.active_profile_id;
|
||||
let private_profile_id = core.create_profile("Private", 0x807d72, ProfileKind::Private)?;
|
||||
|
||||
core.select_profile(&standard_profile_id)?;
|
||||
core.set_profile_sync_policy(&standard_profile_id, ProfileSyncPolicy::Paused)?;
|
||||
core.reset_profile_sync_settings();
|
||||
|
||||
let snapshot = core.snapshot()?;
|
||||
let Some(standard_profile) =
|
||||
snapshot.profiles.iter().find(|profile| profile.id() == &standard_profile_id)
|
||||
else {
|
||||
return Err("missing standard profile".into());
|
||||
};
|
||||
let Some(private_profile) =
|
||||
snapshot.profiles.iter().find(|profile| profile.id() == &private_profile_id)
|
||||
else {
|
||||
return Err("missing private profile".into());
|
||||
};
|
||||
|
||||
assert_eq!(standard_profile.sync_policy(), ProfileSyncPolicy::Enabled);
|
||||
assert_eq!(private_profile.sync_policy(), ProfileSyncPolicy::Paused);
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user