user_setting.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. use flowy_derive::ProtoBuf;
  2. use serde::{Deserialize, Serialize};
  3. #[derive(ProtoBuf, Default, Debug, Clone)]
  4. pub struct UserPreferences {
  5. #[pb(index = 1)]
  6. user_id: String,
  7. #[pb(index = 2)]
  8. appearance_setting: AppearanceSettings,
  9. }
  10. #[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
  11. pub struct AppearanceSettings {
  12. #[pb(index = 1)]
  13. pub theme: String,
  14. #[pb(index = 2)]
  15. #[serde(default)]
  16. pub locale: LocaleSettings,
  17. #[pb(index = 3)]
  18. #[serde(default = "reset_default_value")]
  19. pub reset_as_default: bool,
  20. }
  21. #[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
  22. pub struct LocaleSettings {
  23. #[pb(index = 1)]
  24. pub language_code: String,
  25. #[pb(index = 2)]
  26. pub country_code: String,
  27. }
  28. impl std::default::Default for LocaleSettings {
  29. fn default() -> Self {
  30. Self {
  31. language_code: "en".to_owned(),
  32. country_code: "".to_owned(),
  33. }
  34. }
  35. }
  36. fn reset_default_value() -> bool {
  37. APPEARANCE_RESET_AS_DEFAULT
  38. }
  39. pub const APPEARANCE_DEFAULT_THEME: &str = "light";
  40. pub const APPEARANCE_RESET_AS_DEFAULT: bool = true;
  41. impl std::default::Default for AppearanceSettings {
  42. fn default() -> Self {
  43. AppearanceSettings {
  44. theme: APPEARANCE_DEFAULT_THEME.to_owned(),
  45. locale: LocaleSettings::default(),
  46. reset_as_default: APPEARANCE_RESET_AS_DEFAULT,
  47. }
  48. }
  49. }