Generalized frontend model store (#193)

This commit is contained in:
Gregory Schier
2025-03-31 11:56:17 -07:00
committed by GitHub
parent ce885c3551
commit f1757ae427
201 changed files with 2185 additions and 2865 deletions

View File

@@ -1,24 +1,35 @@
use crate::db_context::DbContext;
use crate::error::Result;
use crate::models::{Settings, SettingsIden};
use crate::models::{EditorKeymap, Settings, SettingsIden};
use crate::util::UpdateSource;
impl<'a> DbContext<'a> {
pub fn get_or_create_settings(&self, source: &UpdateSource) -> Settings {
pub fn get_settings(&self) -> Settings {
let id = "default".to_string();
if let Some(s) = self.find_optional::<Settings>(SettingsIden::Id, &id) {
return s;
};
self.upsert(
&Settings {
id,
..Default::default()
},
source,
)
.expect("Failed to upsert settings")
let settings = Settings {
model: "settings".to_string(),
id,
created_at: Default::default(),
updated_at: Default::default(),
appearance: "system".to_string(),
editor_font_size: 13,
editor_keymap: EditorKeymap::Default,
editor_soft_wrap: true,
interface_font_size: 15,
interface_scale: 1.0,
open_workspace_new_window: None,
proxy: None,
theme_dark: "yaak-dark".to_string(),
theme_light: "yaak-light".to_string(),
update_channel: "stable".to_string(),
};
self.upsert(&settings, &UpdateSource::Background).expect("Failed to upsert settings")
}
pub fn upsert_settings(&self, settings: &Settings, source: &UpdateSource) -> Result<Settings> {