mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-12-01 12:34:06 +01:00
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
62 lines
2.0 KiB
Rust
62 lines
2.0 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use crate::client_db::{ClientDb, WriteDb};
|
|
use crate::error::Result;
|
|
use crate::models::{EditorKeymap, Settings, SettingsIden};
|
|
use crate::util::UpdateSource;
|
|
|
|
impl<'a> ClientDb<'a> {
|
|
/// The settings row, or the defaults if it has not been written yet.
|
|
/// [`WriteDb::ensure_settings`] persists it at startup.
|
|
pub fn get_settings(&self) -> Settings {
|
|
self.find_optional::<Settings>(SettingsIden::Id, "default").unwrap_or_else(default_settings)
|
|
}
|
|
}
|
|
|
|
impl<'a> WriteDb<'a> {
|
|
/// Create the settings row if it does not exist.
|
|
pub fn ensure_settings(&self) -> Result<Settings> {
|
|
if let Some(s) = self.find_optional::<Settings>(SettingsIden::Id, "default") {
|
|
return Ok(s);
|
|
}
|
|
self.upsert(&default_settings(), &UpdateSource::Background)
|
|
}
|
|
|
|
pub fn upsert_settings(&self, settings: &Settings, source: &UpdateSource) -> Result<Settings> {
|
|
self.upsert(settings, source)
|
|
}
|
|
}
|
|
|
|
fn default_settings() -> Settings {
|
|
Settings {
|
|
model: "settings".to_string(),
|
|
id: "default".to_string(),
|
|
created_at: Default::default(),
|
|
updated_at: Default::default(),
|
|
|
|
appearance: "system".to_string(),
|
|
client_certificates: Vec::new(),
|
|
editor_font_size: 12,
|
|
editor_font: None,
|
|
editor_keymap: EditorKeymap::Default,
|
|
editor_soft_wrap: true,
|
|
interface_font_size: 14,
|
|
interface_scale: 1.0,
|
|
interface_font: None,
|
|
hide_window_controls: false,
|
|
use_native_titlebar: false,
|
|
open_workspace_new_window: None,
|
|
proxy: None,
|
|
theme_dark: "yaak-dark".to_string(),
|
|
theme_light: "yaak-light".to_string(),
|
|
update_channel: "stable".to_string(),
|
|
autoupdate: true,
|
|
colored_methods: false,
|
|
hide_license_badge: false,
|
|
prompt_feedback: true,
|
|
auto_download_updates: true,
|
|
check_notifications: true,
|
|
hotkeys: HashMap::new(),
|
|
}
|
|
}
|