qframe/storage/preferences.rs
1//! The preferences every application of a family shares: language, theme and icons.
2//!
3//! The family's shared file holds one value of each, and each application's own file either
4//! names its own value or the family's id, which means "use the shared one":
5//!
6//! ```toml
7//! # quvyta.conf
8//! language = "tr"
9//! theme = "monochrome"
10//! icons = "nerd"
11//!
12//! # code.conf
13//! language = "quvyta"
14//! theme = "nordic"
15//! ```
16//!
17//! [`Family::preferences`] resolves each key on its own, in this order:
18//!
19//! 1. the application's value, when it is anything but the family's id;
20//! 2. the shared file's value, when the application's value is the family's id or the key is
21//! missing from the application's file;
22//! 3. the value detected on this machine, when the shared file does not hold one either.
23//!
24//! [`Family::set`] changes one key for the whole family or for one application, and
25//! [`Family::follow`] puts one application back on the family's value without touching it.
26
27use std::fs;
28use std::io;
29use std::path::{Path, PathBuf};
30
31use super::{Family, SettingValue, Settings, atomic_write};
32use crate::diagnostics::{Diagnostic, Severity};
33use crate::i18n::I18n;
34use crate::icons::{GlyphMode, IconMode, default_font_dirs, detect_glyph_mode};
35use crate::runtime::Command;
36
37/// The theme a machine starts with: every theme is dark, so there is nothing to detect.
38const DETECTED_THEME: &str = "monochrome";
39
40/// The language when the system names none the application speaks.
41const FALLBACK_LANGUAGE: &str = "en";
42
43/// A preference every application of a family shares.
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
45pub enum Shared {
46 /// The language, a locale code such as `tr`.
47 Language,
48 /// The colour theme, a theme id such as `nordic`.
49 Theme,
50 /// The icon mode: `auto`, `nerd`, `unicode` or `ascii`.
51 Icons,
52}
53
54impl Shared {
55 /// Every shared preference, in the order a settings screen lists them.
56 pub const ALL: [Self; 3] = [Self::Language, Self::Theme, Self::Icons];
57
58 /// The key the preference is written under, in the shared file and in each application's.
59 #[must_use]
60 pub fn key(self) -> &'static str {
61 match self {
62 Self::Language => Settings::LANGUAGE,
63 Self::Theme => Settings::THEME,
64 Self::Icons => Settings::ICONS,
65 }
66 }
67}
68
69/// Where [`Family::set`] writes a change: the "In every Quvyta application" choice of a settings
70/// screen.
71#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
72pub enum Scope {
73 /// The shared file takes the value and the application follows it again, so every
74 /// application that follows the family changes with it. Applications that chose their own
75 /// value keep it.
76 Family,
77 /// Only the application's own file takes the value; the shared file is left alone.
78 App,
79}
80
81/// Where a resolved preference came from, so a settings screen can say "follows every Quvyta
82/// application" or "only here".
83#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
84pub enum Source {
85 /// The application's own file names it.
86 App,
87 /// The family's shared file holds it and the application follows it.
88 Family,
89 /// Neither file holds it; it was detected on this machine.
90 Detected,
91}
92
93/// A preference's value together with where it came from.
94#[derive(Debug, Clone, PartialEq, Eq)]
95pub struct Resolved<T> {
96 /// The value to use.
97 pub value: T,
98 /// Where the value came from.
99 pub source: Source,
100}
101
102/// The shared preferences as one application sees them, from [`Family::preferences`].
103///
104/// ```
105/// use qframe::i18n::I18n;
106/// use qframe::storage::{Family, Source};
107///
108/// # let folder = std::env::temp_dir().join(format!("quvyta-preferences-doc-{}", std::process::id()));
109/// // An application calls `Family::QUVYTA.preferences("code", &i18n)`; the example keeps to a
110/// // folder of its own.
111/// let prefs = Family::QUVYTA.preferences_in(&folder, "code", &I18n::builtin());
112/// let theme = prefs.theme();
113/// assert_eq!((theme.value.as_str(), theme.source), ("monochrome", Source::Detected), "never detected");
114/// assert!(folder.join("quvyta.conf").is_file(), "the first start writes the shared file");
115/// # std::fs::remove_dir_all(&folder).ok();
116/// ```
117#[derive(Debug, Clone, PartialEq)]
118pub struct Preferences {
119 language: Resolved<String>,
120 theme: Resolved<String>,
121 icons: Resolved<IconMode>,
122 diagnostics: Vec<Diagnostic>,
123}
124
125impl Preferences {
126 /// The locale code to speak.
127 #[must_use]
128 pub fn language(&self) -> &Resolved<String> {
129 &self.language
130 }
131
132 /// The theme id to draw with.
133 #[must_use]
134 pub fn theme(&self) -> &Resolved<String> {
135 &self.theme
136 }
137
138 /// The icon mode to draw with.
139 #[must_use]
140 pub fn icons(&self) -> &Resolved<IconMode> {
141 &self.icons
142 }
143
144 /// Where `key` came from.
145 #[must_use]
146 pub fn source(&self, key: Shared) -> Source {
147 match key {
148 Shared::Language => self.language.source,
149 Shared::Theme => self.theme.source,
150 Shared::Icons => self.icons.source,
151 }
152 }
153
154 /// Records that `key` now holds `value`, which came from `source`, after a change written
155 /// with [`Family::set`].
156 pub(crate) fn record(&mut self, key: Shared, value: &str, source: Source) {
157 match key {
158 Shared::Language => self.language = Resolved { value: value.to_owned(), source },
159 Shared::Theme => self.theme = Resolved { value: value.to_owned(), source },
160 Shared::Icons => {
161 let mode = IconMode::from_name(value).unwrap_or(self.icons.value);
162 self.icons = Resolved { value: mode, source };
163 }
164 }
165 }
166
167 /// The value of `key` as it is written in a file.
168 pub(crate) fn text(&self, key: Shared) -> String {
169 match key {
170 Shared::Language => self.language.value.clone(),
171 Shared::Theme => self.theme.value.clone(),
172 Shared::Icons => self.icons.value.name().to_owned(),
173 }
174 }
175
176 /// Problems found on the way: a broken line in the shared file, a shared file that could not
177 /// be written. Each is located where a file is to blame; the key it concerns fell back to the
178 /// detected value. Problems in the application's own file are reported by the application's
179 /// own [`Settings`] load and are not repeated here.
180 #[must_use]
181 pub fn diagnostics(&self) -> &[Diagnostic] {
182 &self.diagnostics
183 }
184
185 /// Commands that switch the running application to the resolved language, theme and icons,
186 /// for use after a change in `update`. At start give the preferences to
187 /// [`Runtime::preferences`](crate::runtime::Runtime::preferences) instead, so the first
188 /// frame is already drawn with them.
189 #[must_use]
190 pub fn apply<Msg: Send + 'static>(&self) -> Command<Msg> {
191 Command::batch([
192 Command::set_theme(self.theme.value.clone()),
193 Command::set_locale(self.language.value.clone()),
194 Command::set_icon_mode(self.icons.value),
195 ])
196 }
197}
198
199/// What a resolution does about a shared file that is not there.
200#[derive(Debug, Clone, Copy, PartialEq, Eq)]
201enum Missing {
202 /// Write it with the detected values, so the next application finds them.
203 Create,
204 /// Leave it missing and detect its keys, so nothing is written before a setup wizard finishes.
205 Leave,
206}
207
208/// What this machine would choose for each shared preference.
209struct Detected {
210 language: String,
211 icons: IconMode,
212}
213
214impl Detected {
215 fn on_this_machine(i18n: &I18n, lookup: impl Fn(&str) -> Option<String>, font_dirs: &[PathBuf]) -> Self {
216 let language = i18n.detect(&lookup).unwrap_or_else(|| FALLBACK_LANGUAGE.to_owned());
217 let icons = match detect_glyph_mode(IconMode::Auto, &lookup, font_dirs) {
218 GlyphMode::Nerd => IconMode::Nerd,
219 GlyphMode::Unicode => IconMode::Unicode,
220 GlyphMode::Ascii => IconMode::Ascii,
221 };
222 Self { language, icons }
223 }
224
225 /// The detected value of `key` as it is written in a file.
226 fn text(&self, key: Shared) -> String {
227 match key {
228 Shared::Language => self.language.clone(),
229 Shared::Theme => DETECTED_THEME.to_owned(),
230 Shared::Icons => self.icons.name().to_owned(),
231 }
232 }
233
234 /// The shared file as it is first written: the detected value of every key.
235 fn file(&self) -> String {
236 let mut settings = Settings::in_memory();
237 for key in Shared::ALL {
238 settings.set(key.key(), self.text(key));
239 }
240 settings.to_toml()
241 }
242}
243
244impl Family {
245 /// Resolves the shared preferences of application `app`: for each of language, theme and
246 /// icons, the application's own value when its file names one other than the family's id,
247 /// else the value in the [shared file](Self::shared_file), else the value detected on this
248 /// machine. A key missing from the application's file follows the family, as the family's id
249 /// does, so a file written by hand before the family shared anything follows it too.
250 ///
251 /// Detection reads the environment: the language as [`I18n::detect`] finds it among the
252 /// languages `i18n` knows (English when it knows none of the system's), the theme always
253 /// `monochrome`, the icons as the strongest set the terminal and the installed fonts allow
254 /// ([`detect_glyph_mode`]).
255 ///
256 /// When the shared file does not exist it is created with the detected values, so the next
257 /// application that starts finds them. A broken line never stops anything: that key falls
258 /// back to the detected value and the reason, located at file, line and column, is in
259 /// [`Preferences::diagnostics`]. Without a home folder nothing is read or written and every
260 /// value is detected.
261 ///
262 /// The rest of the application's settings are read as before, with
263 /// [`Settings::load_member`]; this only resolves the keys [`Shared`] names.
264 #[must_use]
265 pub fn preferences(&self, app: &str, i18n: &I18n) -> Preferences {
266 let lookup = |name: &str| std::env::var(name).ok();
267 let font_dirs = default_font_dirs(lookup);
268 let detected = Detected::on_this_machine(i18n, lookup, &font_dirs);
269 match self.config_dir() {
270 Some(dir) => self.resolve(&dir, app, &detected, Missing::Create),
271 None => {
272 let mut prefs = resolved_from(&detected, |_| None, |_| None);
273 prefs
274 .diagnostics
275 .push(Diagnostic::warning(None, "no config directory found; preferences are not saved"));
276 prefs
277 }
278 }
279 }
280
281 /// [`preferences`](Self::preferences) with `config_dir` as the family's folder instead of
282 /// this platform's, for a test or a demo that must leave the user's own files alone.
283 #[must_use]
284 pub fn preferences_in(&self, config_dir: &Path, app: &str, i18n: &I18n) -> Preferences {
285 let lookup = |name: &str| std::env::var(name).ok();
286 let detected = Detected::on_this_machine(i18n, lookup, &default_font_dirs(lookup));
287 self.resolve(config_dir, app, &detected, Missing::Create)
288 }
289
290 /// [`preferences`](Self::preferences) without writing anything: a missing shared file is left
291 /// missing and its keys are detected instead.
292 ///
293 /// For an application whose first start shows a [setup wizard](crate::widgets::Setup): a
294 /// wizard closed half-way leaves the user's settings folder as empty as it found it, and the
295 /// wizard's Finish writes both files. An application without a wizard uses
296 /// [`preferences`](Self::preferences), so the first application to start leaves the shared
297 /// file for the next one.
298 #[must_use]
299 pub fn preferences_without_saving(&self, app: &str, i18n: &I18n) -> Preferences {
300 let lookup = |name: &str| std::env::var(name).ok();
301 let font_dirs = default_font_dirs(lookup);
302 let detected = Detected::on_this_machine(i18n, lookup, &font_dirs);
303 match self.config_dir() {
304 Some(dir) => self.resolve(&dir, app, &detected, Missing::Leave),
305 None => resolved_from(&detected, |_| None, |_| None),
306 }
307 }
308
309 /// [`preferences_without_saving`](Self::preferences_without_saving) with `config_dir` as the
310 /// family's folder instead of this platform's, for a test or a demo.
311 #[must_use]
312 pub fn preferences_without_saving_in(&self, config_dir: &Path, app: &str, i18n: &I18n) -> Preferences {
313 let lookup = |name: &str| std::env::var(name).ok();
314 let detected = Detected::on_this_machine(i18n, lookup, &default_font_dirs(lookup));
315 self.resolve(config_dir, app, &detected, Missing::Leave)
316 }
317
318 /// [`preferences_in`](Self::preferences_in) with the machine's detection read through
319 /// `lookup` and `font_dirs` instead of the process environment, for tests.
320 #[cfg(test)]
321 fn preferences_detecting(
322 &self,
323 config_dir: &Path,
324 app: &str,
325 i18n: &I18n,
326 lookup: impl Fn(&str) -> Option<String>,
327 ) -> Preferences {
328 self.resolve(config_dir, app, &Detected::on_this_machine(i18n, lookup, &[]), Missing::Create)
329 }
330
331 /// Changes shared preference `key` of application `app` to `value`, for the whole family or
332 /// for the application alone:
333 ///
334 /// | `scope` | shared file | application's file |
335 /// |---|---|---|
336 /// | [`Scope::Family`] | `key = value` | `key = "<family id>"` |
337 /// | [`Scope::App`] | unchanged | `key = value` |
338 ///
339 /// Each file is read from disk right before it is written and only `key` changes in it, so
340 /// two applications changing preferences at the same time both keep their change instead
341 /// of one writing back what it read earlier. On Unix systems the family's folder is held
342 /// with an advisory lock from the reading to the writing, so even two changes in the same
343 /// instant follow one another; elsewhere the window between them is a few microseconds. Files are written with [`atomic_write`]; the
344 /// other keys stay as they were, though comments do not survive, as with
345 /// [`Settings::save`]. The running application is not switched; use
346 /// [`Preferences::apply`] or the matching [`Command`] for that.
347 ///
348 /// # Errors
349 ///
350 /// Returns an error of kind [`io::ErrorKind::InvalidInput`] when `value` is not a valid
351 /// value of `key` (an unknown icon mode, the family's own id, an empty text), of kind
352 /// [`io::ErrorKind::NotFound`] when there is no home folder, and any error from writing.
353 pub fn set(&self, app: &str, key: Shared, value: &str, scope: Scope) -> io::Result<()> {
354 match self.config_dir() {
355 Some(dir) => self.set_in(&dir, app, key, value, scope),
356 None => Err(io::Error::new(io::ErrorKind::NotFound, "no config directory found")),
357 }
358 }
359
360 /// [`set`](Self::set) with `config_dir` as the family's folder instead of this platform's.
361 ///
362 /// # Errors
363 ///
364 /// As [`set`](Self::set), except that there is always a folder.
365 pub fn set_in(&self, config_dir: &Path, app: &str, key: Shared, value: &str, scope: Scope) -> io::Result<()> {
366 let value = self.checked(key, value)?;
367 fs::create_dir_all(config_dir)?;
368 let _held = hold_folder(config_dir)?;
369 let app_file = config_dir.join(super::family::file_name(app));
370 match scope {
371 Scope::Family => {
372 let shared_file = config_dir.join(super::family::file_name(self.id()));
373 rewrite(&shared_file, key.key(), SettingValue::Text(value), None)?;
374 rewrite(&app_file, key.key(), SettingValue::Text(self.id().to_owned()), Some(self))
375 }
376 Scope::App => rewrite(&app_file, key.key(), SettingValue::Text(value), Some(self)),
377 }
378 }
379
380 /// Puts application `app` back on the family's value of `key`: its own file says the family's
381 /// id and the [shared file](Self::shared_file) is neither read nor written, so the next
382 /// resolution answers the shared value with [`Source::Family`] and no other application
383 /// changes. The one way back from a value of an application's own, for the settings screen
384 /// that lists every member of the family: "follow the shared setting" on one member's cell
385 /// must not change what the whole family draws with.
386 ///
387 /// The file is read from disk right before it is written and only `key` changes in it, as
388 /// [`set`](Self::set) does, with the family's folder held by an advisory lock on Unix. A
389 /// missing file is created holding that one key. A key that already follows the family is
390 /// left alone, file and all. Comments do not survive a change, as with [`Settings::save`].
391 /// The running application is not switched; use [`Preferences::apply`] for that.
392 ///
393 /// # Errors
394 ///
395 /// Returns an error of kind [`io::ErrorKind::NotFound`] when there is no home folder, of kind
396 /// [`io::ErrorKind::InvalidData`] when the application's file cannot be read as settings,
397 /// and any error from writing. A file that could not be read is left exactly as it was.
398 pub fn follow(&self, app: &str, key: Shared) -> io::Result<()> {
399 match self.config_dir() {
400 Some(dir) => self.follow_in(&dir, app, key),
401 None => Err(io::Error::new(io::ErrorKind::NotFound, "no config directory found")),
402 }
403 }
404
405 /// [`follow`](Self::follow) with `config_dir` as the family's folder instead of this
406 /// platform's, for a test or a demo that must leave the user's own files alone.
407 ///
408 /// ```
409 /// use qframe::storage::{Family, Shared};
410 ///
411 /// # let folder = std::env::temp_dir().join(format!("quvyta-follow-doc-{}", std::process::id()));
412 /// # std::fs::create_dir_all(&folder).expect("folder");
413 /// std::fs::write(folder.join("code.conf"), "theme = \"amber\"\n").expect("the file");
414 /// Family::QUVYTA.follow_in(&folder, "code", Shared::Theme).expect("follow");
415 /// assert_eq!(std::fs::read_to_string(folder.join("code.conf")).expect("read"), "theme = \"quvyta\"\n");
416 /// assert!(!folder.join("quvyta.conf").exists(), "the shared file is left alone");
417 /// # std::fs::remove_dir_all(&folder).ok();
418 /// ```
419 ///
420 /// # Errors
421 ///
422 /// As [`follow`](Self::follow), except that there is always a folder.
423 pub fn follow_in(&self, config_dir: &Path, app: &str, key: Shared) -> io::Result<()> {
424 fs::create_dir_all(config_dir)?;
425 let _held = hold_folder(config_dir)?;
426 let path = config_dir.join(super::family::file_name(app));
427 let mut settings = Settings::open(&path).member_of(self);
428 if let Some(problem) = settings.diagnostics().iter().find(|problem| problem.severity == Severity::Error) {
429 return Err(io::Error::new(io::ErrorKind::InvalidData, problem.to_string()));
430 }
431 let value = SettingValue::Text(self.id().to_owned());
432 if settings.value(key.key()) == Some(&value) && path.exists() {
433 return Ok(());
434 }
435 settings.store(key.key(), value);
436 settings.save()
437 }
438
439 /// Changes `key` in application `app`'s own file in `config_dir` to `value`, the way
440 /// [`set_in`](Self::set_in) changes a shared key: read right before writing, only that key,
441 /// with the folder held. For the application's settings that sit beside the shared ones on an
442 /// appearance screen, such as reduced motion.
443 pub(crate) fn set_own_in(&self, config_dir: &Path, app: &str, key: &str, value: SettingValue) -> io::Result<()> {
444 fs::create_dir_all(config_dir)?;
445 let _held = hold_folder(config_dir)?;
446 rewrite(&config_dir.join(super::family::file_name(app)), key, value, Some(self))
447 }
448
449 /// `value` as it is written under `key`, or why it cannot be.
450 fn checked(&self, key: Shared, value: &str) -> io::Result<String> {
451 let invalid = |why: String| io::Error::new(io::ErrorKind::InvalidInput, why);
452 let value = value.trim();
453 if value.is_empty() {
454 return Err(invalid(format!("`{}` cannot be empty", key.key())));
455 }
456 if value == self.id() {
457 return Err(invalid(format!("`{}` cannot be set to the family's own id `{value}`", key.key())));
458 }
459 match key {
460 Shared::Icons => IconMode::from_name(value)
461 .map(|mode| mode.name().to_owned())
462 .ok_or_else(|| invalid(format!("`{value}` is not an icon mode; use auto, nerd, unicode or ascii"))),
463 Shared::Language | Shared::Theme => Ok(value.to_owned()),
464 }
465 }
466
467 /// Resolves the preferences of `app` from the files in `config_dir`, creating the shared file
468 /// with the `detected` values when it is missing and `missing` says to.
469 fn resolve(&self, config_dir: &Path, app: &str, detected: &Detected, missing: Missing) -> Preferences {
470 let mut diagnostics = Vec::new();
471 let shared_path = config_dir.join(super::family::file_name(self.id()));
472 let shared = if shared_path.exists() {
473 let shared = Settings::open(&shared_path);
474 diagnostics.extend(shared.diagnostics().iter().cloned());
475 Some(shared)
476 } else {
477 if missing == Missing::Create
478 && let Err(error) = create(&shared_path, &detected.file())
479 {
480 diagnostics.push(Diagnostic::error(
481 None,
482 format!("{}: shared preferences not saved: {error}", shared_path.display()),
483 ));
484 }
485 None
486 };
487 let own = Settings::open(config_dir.join(super::family::file_name(app))).member_of(self);
488 let family_value = |key: Shared| -> Option<String> {
489 let shared = shared.as_ref()?;
490 let text = shared.get::<String>(key.key()).filter(|text| valid(key, text))?;
491 (text != self.id()).then_some(text)
492 };
493 let app_value = |key: Shared| -> Option<String> {
494 own.get::<String>(key.key()).filter(|text| text != self.id() && valid(key, text))
495 };
496 if let Some(shared) = &shared {
497 for key in Shared::ALL {
498 if shared.get::<String>(key.key()).is_some_and(|text| text == self.id()) {
499 diagnostics.push(Diagnostic::warning(
500 shared.origin(key.key()),
501 format!(
502 "`{}` cannot follow the family in the family's own file; the detected value is used",
503 key.key()
504 ),
505 ));
506 }
507 }
508 }
509 let mut prefs = resolved_from(detected, app_value, family_value);
510 prefs.diagnostics = diagnostics;
511 prefs
512 }
513}
514
515/// Whether `text` is a usable value of `key`; what is not was already reported by the settings
516/// load that read it.
517fn valid(key: Shared, text: &str) -> bool {
518 match key {
519 Shared::Icons => IconMode::from_name(text).is_some(),
520 Shared::Language | Shared::Theme => !text.trim().is_empty(),
521 }
522}
523
524/// Each key from the application's value, the family's value or the detected one, in that order.
525fn resolved_from(
526 detected: &Detected,
527 app_value: impl Fn(Shared) -> Option<String>,
528 family_value: impl Fn(Shared) -> Option<String>,
529) -> Preferences {
530 let text = |key: Shared| -> Resolved<String> {
531 if let Some(value) = app_value(key) {
532 Resolved { value, source: Source::App }
533 } else if let Some(value) = family_value(key) {
534 Resolved { value, source: Source::Family }
535 } else {
536 Resolved { value: detected.text(key), source: Source::Detected }
537 }
538 };
539 let icons = text(Shared::Icons);
540 Preferences {
541 language: text(Shared::Language),
542 theme: text(Shared::Theme),
543 icons: Resolved { value: IconMode::from_name(&icons.value).unwrap_or(detected.icons), source: icons.source },
544 diagnostics: Vec::new(),
545 }
546}
547
548/// Holds the family's folder with an advisory lock while it lives, so no other writer reads a file
549/// between this writer's reading and writing it. Locking the folder rather than a file of its own
550/// leaves nothing behind in the user's settings. Unix only: elsewhere the framework has no
551/// advisory lock, as for [`AppLock`](super::AppLock).
552#[cfg(unix)]
553fn hold_folder(dir: &Path) -> io::Result<Option<fs::File>> {
554 let folder = fs::File::open(dir)?;
555 folder.lock()?;
556 Ok(Some(folder))
557}
558
559#[cfg(not(unix))]
560fn hold_folder(_dir: &Path) -> io::Result<Option<fs::File>> {
561 Ok(None)
562}
563
564/// Writes the first shared file, creating its folder.
565fn create(path: &Path, text: &str) -> io::Result<()> {
566 if let Some(dir) = path.parent() {
567 fs::create_dir_all(dir)?;
568 }
569 atomic_write(path, text.as_bytes())
570}
571
572/// Reads the file at `path` as it is on disk now, changes only `key` to `value` and writes it
573/// back. `family` marks an application's file, whose own values follow the family.
574fn rewrite(path: &Path, key: &str, value: SettingValue, family: Option<&Family>) -> io::Result<()> {
575 let mut settings = Settings::open(path);
576 if let Some(family) = family {
577 settings = settings.member_of(family);
578 }
579 if settings.value(key) == Some(&value) && path.exists() {
580 return Ok(());
581 }
582 settings.store(key, value);
583 settings.save()
584}
585
586#[cfg(test)]
587#[path = "preferences_tests.rs"]
588mod tests;