user_setting.rs 1.4 KB

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