2022-09-28 11:44:44 +08:00
|
|
|
use std::collections::HashMap;
|
2023-07-14 13:37:13 +08:00
|
|
|
use std::convert::TryFrom;
|
|
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
|
|
|
use flowy_error::FlowyError;
|
2023-07-29 09:46:24 +08:00
|
|
|
use flowy_server_config::supabase_config::SupabaseConfiguration;
|
2022-01-28 10:56:55 +08:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Debug, Clone)]
|
2022-07-19 14:40:56 +08:00
|
|
|
pub struct UserPreferencesPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
user_id: String,
|
2022-01-28 10:56:55 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 2)]
|
|
|
|
appearance_setting: AppearanceSettingsPB,
|
2022-01-28 10:56:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
|
2022-07-19 14:40:56 +08:00
|
|
|
pub struct AppearanceSettingsPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub theme: String,
|
2022-01-28 10:56:55 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 2)]
|
|
|
|
#[serde(default)]
|
|
|
|
pub theme_mode: ThemeModePB,
|
2022-11-16 14:40:30 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 3)]
|
|
|
|
pub font: String,
|
2022-11-16 14:40:30 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 4)]
|
|
|
|
pub monospace_font: String,
|
2022-12-08 14:21:11 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 5)]
|
|
|
|
#[serde(default)]
|
|
|
|
pub locale: LocaleSettingsPB,
|
2022-02-01 12:15:11 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 6)]
|
|
|
|
#[serde(default = "DEFAULT_RESET_VALUE")]
|
|
|
|
pub reset_to_default: bool,
|
2022-09-28 11:44:44 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 7)]
|
|
|
|
#[serde(default)]
|
|
|
|
pub setting_key_value: HashMap<String, String>,
|
2023-01-18 07:30:39 +01:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 8)]
|
|
|
|
#[serde(default)]
|
|
|
|
pub is_menu_collapsed: bool,
|
2023-01-18 07:30:39 +01:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 9)]
|
|
|
|
#[serde(default)]
|
|
|
|
pub menu_offset: f64,
|
2022-02-01 12:15:11 +08:00
|
|
|
}
|
|
|
|
|
2022-06-27 20:53:47 +08:00
|
|
|
const DEFAULT_RESET_VALUE: fn() -> bool = || APPEARANCE_RESET_AS_DEFAULT;
|
|
|
|
|
2023-06-09 22:23:07 +08:00
|
|
|
#[derive(ProtoBuf_Enum, Serialize, Deserialize, Clone, Debug, Default)]
|
2022-12-08 14:21:11 +08:00
|
|
|
pub enum ThemeModePB {
|
2023-02-13 09:29:49 +08:00
|
|
|
Light = 0,
|
|
|
|
Dark = 1,
|
2023-06-09 22:23:07 +08:00
|
|
|
#[default]
|
2023-02-13 09:29:49 +08:00
|
|
|
System = 2,
|
2022-12-08 14:21:11 +08:00
|
|
|
}
|
|
|
|
|
2022-02-04 15:45:06 -05:00
|
|
|
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
|
2022-07-19 14:40:56 +08:00
|
|
|
pub struct LocaleSettingsPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub language_code: String,
|
2022-02-04 15:45:06 -05:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
#[pb(index = 2)]
|
|
|
|
pub country_code: String,
|
2022-02-04 15:45:06 -05:00
|
|
|
}
|
|
|
|
|
2022-07-19 14:40:56 +08:00
|
|
|
impl std::default::Default for LocaleSettingsPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
language_code: "en".to_owned(),
|
|
|
|
country_code: "".to_owned(),
|
2022-02-04 15:45:06 -05:00
|
|
|
}
|
2023-02-13 09:29:49 +08:00
|
|
|
}
|
2022-02-04 15:45:06 -05:00
|
|
|
}
|
|
|
|
|
2022-01-29 22:56:20 +08:00
|
|
|
pub const APPEARANCE_DEFAULT_THEME: &str = "light";
|
2022-11-16 14:40:30 +08:00
|
|
|
pub const APPEARANCE_DEFAULT_FONT: &str = "Poppins";
|
|
|
|
pub const APPEARANCE_DEFAULT_MONOSPACE_FONT: &str = "SF Mono";
|
2022-06-27 20:53:47 +08:00
|
|
|
const APPEARANCE_RESET_AS_DEFAULT: bool = true;
|
2023-01-18 07:30:39 +01:00
|
|
|
const APPEARANCE_DEFAULT_IS_MENU_COLLAPSED: bool = false;
|
|
|
|
const APPEARANCE_DEFAULT_MENU_OFFSET: f64 = 0.0;
|
2022-01-28 10:56:55 +08:00
|
|
|
|
2022-07-19 14:40:56 +08:00
|
|
|
impl std::default::Default for AppearanceSettingsPB {
|
2023-02-13 09:29:49 +08:00
|
|
|
fn default() -> Self {
|
|
|
|
AppearanceSettingsPB {
|
|
|
|
theme: APPEARANCE_DEFAULT_THEME.to_owned(),
|
|
|
|
theme_mode: ThemeModePB::default(),
|
|
|
|
font: APPEARANCE_DEFAULT_FONT.to_owned(),
|
|
|
|
monospace_font: APPEARANCE_DEFAULT_MONOSPACE_FONT.to_owned(),
|
|
|
|
locale: LocaleSettingsPB::default(),
|
|
|
|
reset_to_default: APPEARANCE_RESET_AS_DEFAULT,
|
|
|
|
setting_key_value: HashMap::default(),
|
|
|
|
is_menu_collapsed: APPEARANCE_DEFAULT_IS_MENU_COLLAPSED,
|
|
|
|
menu_offset: APPEARANCE_DEFAULT_MENU_OFFSET,
|
2022-01-28 10:56:55 +08:00
|
|
|
}
|
2023-02-13 09:29:49 +08:00
|
|
|
}
|
2022-01-28 10:56:55 +08:00
|
|
|
}
|
2023-07-14 13:37:13 +08:00
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct SupabaseConfigPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
supabase_url: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
key: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
jwt_secret: String,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
enable_sync: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<SupabaseConfigPB> for SupabaseConfiguration {
|
|
|
|
type Error = FlowyError;
|
|
|
|
|
|
|
|
fn try_from(config: SupabaseConfigPB) -> Result<Self, Self::Error> {
|
|
|
|
Ok(SupabaseConfiguration {
|
|
|
|
url: config.supabase_url,
|
2023-07-29 09:46:24 +08:00
|
|
|
anon_key: config.key,
|
2023-07-14 13:37:13 +08:00
|
|
|
jwt_secret: config.jwt_secret,
|
|
|
|
enable_sync: config.enable_sync,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SupabaseConfiguration> for SupabaseConfigPB {
|
|
|
|
fn from(value: SupabaseConfiguration) -> Self {
|
|
|
|
Self {
|
|
|
|
supabase_url: value.url,
|
2023-07-29 09:46:24 +08:00
|
|
|
key: value.anon_key,
|
2023-07-14 13:37:13 +08:00
|
|
|
jwt_secret: value.jwt_secret,
|
|
|
|
enable_sync: value.enable_sync,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-29 09:46:24 +08:00
|
|
|
#[derive(ProtoBuf_Enum, Debug, Clone, Eq, PartialEq, Default)]
|
|
|
|
pub enum NetworkTypePB {
|
|
|
|
#[default]
|
|
|
|
NetworkUnknown = 0,
|
|
|
|
Wifi = 1,
|
|
|
|
Cell = 2,
|
|
|
|
Ethernet = 3,
|
|
|
|
Bluetooth = 4,
|
|
|
|
VPN = 5,
|
2023-07-14 13:37:13 +08:00
|
|
|
}
|
|
|
|
|
2023-07-29 09:46:24 +08:00
|
|
|
impl NetworkTypePB {
|
|
|
|
pub fn is_reachable(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
NetworkTypePB::NetworkUnknown | NetworkTypePB::Bluetooth => false,
|
|
|
|
NetworkTypePB::Wifi | NetworkTypePB::Cell | NetworkTypePB::Ethernet | NetworkTypePB::VPN => {
|
|
|
|
true
|
|
|
|
},
|
|
|
|
}
|
2023-07-14 13:37:13 +08:00
|
|
|
}
|
|
|
|
}
|
2023-07-29 09:46:24 +08:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Debug, Default, Clone)]
|
|
|
|
pub struct NetworkStatePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub ty: NetworkTypePB,
|
|
|
|
}
|