use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PrivacyMode {
#[default]
Standard,
Strict,
Portable,
Diagnostics,
}
impl PrivacyMode {
pub fn as_str(self) -> &'static str {
match self {
PrivacyMode::Standard => "standard",
PrivacyMode::Strict => "strict",
PrivacyMode::Portable => "portable",
PrivacyMode::Diagnostics => "diagnostics",
}
}
pub fn from_str(s: &str) -> Self {
match s {
"strict" => PrivacyMode::Strict,
"portable" => PrivacyMode::Portable,
"diagnostics" => PrivacyMode::Diagnostics,
_ => PrivacyMode::Standard,
}
}
pub fn allows_recent_searches(self) -> bool {
!matches!(self, PrivacyMode::Strict)
}
pub fn allows_snippet_persistence(self) -> bool {
!matches!(self, PrivacyMode::Strict)
}
pub fn allows_diagnostics_sensitive_optins(self) -> bool {
!matches!(self, PrivacyMode::Strict)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PrivacySettings {
pub mode: PrivacyMode,
pub remember_recent_searches: bool,
pub persist_snippets: bool,
pub clear_temporary_previews_on_exit: bool,
pub diagnostics_include_paths: bool,
pub diagnostics_include_recent_searches: bool,
}
impl Default for PrivacySettings {
fn default() -> Self {
Self {
mode: PrivacyMode::Standard,
remember_recent_searches: true,
persist_snippets: true,
clear_temporary_previews_on_exit: false,
diagnostics_include_paths: false,
diagnostics_include_recent_searches: false,
}
}
}
impl PrivacySettings {
pub fn with_mode_applied(mut self) -> Self {
if self.mode == PrivacyMode::Strict {
self.remember_recent_searches = false;
self.persist_snippets = false;
self.diagnostics_include_paths = false;
self.diagnostics_include_recent_searches = false;
}
self
}
pub fn effective_recent_searches(&self) -> bool {
self.mode.allows_recent_searches() && self.remember_recent_searches
}
pub fn effective_snippet_persistence(&self) -> bool {
self.mode.allows_snippet_persistence() && self.persist_snippets
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LocalDataCategory {
SourcePaths,
FileMetadata,
ExtractedText,
KeywordIndex,
Embeddings,
Snippets,
TemporaryPreviews,
RecentSearches,
Logs,
Diagnostics,
ModelFiles,
Settings,
}
impl LocalDataCategory {
pub fn user_label(self) -> &'static str {
match self {
LocalDataCategory::SourcePaths => "Folder list",
LocalDataCategory::FileMetadata => "File information",
LocalDataCategory::ExtractedText => "Prepared text",
LocalDataCategory::KeywordIndex => "Search data",
LocalDataCategory::Embeddings => "Better search data",
LocalDataCategory::Snippets => "Temporary previews",
LocalDataCategory::TemporaryPreviews => "Temporary previews",
LocalDataCategory::RecentSearches => "Recent searches",
LocalDataCategory::Logs => "Logs",
LocalDataCategory::Diagnostics => "Support files",
LocalDataCategory::ModelFiles => "Search helper",
LocalDataCategory::Settings => "App settings",
}
}
}
#[derive(Debug, Clone)]
pub struct DiagnosticsPolicy {
pub include_raw_paths: bool,
pub include_folder_names: bool,
pub include_recent_searches: bool,
pub include_detailed_logs: bool,
pub privacy_mode: PrivacyMode,
}
impl Default for DiagnosticsPolicy {
fn default() -> Self {
Self {
include_raw_paths: false,
include_folder_names: false,
include_recent_searches: false,
include_detailed_logs: false,
privacy_mode: PrivacyMode::Standard,
}
}
}
impl DiagnosticsPolicy {
pub fn from_privacy(settings: &PrivacySettings) -> Self {
let strict = settings.mode == PrivacyMode::Strict;
Self {
include_raw_paths: false, include_folder_names: if strict { false } else { false }, include_recent_searches: if strict {
false
} else {
settings.diagnostics_include_recent_searches
},
include_detailed_logs: false,
privacy_mode: settings.mode,
}
}
pub fn allows_sensitive_optins(&self) -> bool {
self.privacy_mode.allows_diagnostics_sensitive_optins()
}
}