This commit is contained in:
2026-09-03 16:38:52 +07:00
parent 018395d0c5
commit 212f35d6bb
69 changed files with 2130 additions and 2373 deletions
-6
View File
@@ -1,9 +1,3 @@
//! Persisted application settings for Signed.
//!
//! The [`Settings`] model holds the user-configurable values that survive
//! restarts, and [`SettingsStore`] loads them from and saves them to a JSON
//! file on disk (see [`paths::settings_file`]).
mod settings;
mod store;
+16 -22
View File
@@ -2,8 +2,8 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize};
/// The default grasp servers offered when the user hasn't published a
/// grasp list (kind `10317`) yet.
/// The default grasp servers.
/// Offered while the user has not published a grasp list, kind `10317`.
pub const DEFAULT_GRASP_SERVERS: [&str; 3] = [
"wss://relay.ngit.dev",
"wss://gitnostr.com",
@@ -14,7 +14,7 @@ pub const DEFAULT_GRASP_SERVERS: [&str; 3] = [
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum AppearanceMode {
/// Follow the system appearance (light/dark) at runtime.
/// Follow the system appearance, light or dark, at runtime.
#[default]
System,
/// Always use the light theme.
@@ -24,11 +24,9 @@ pub enum AppearanceMode {
}
/// Theme configuration.
///
/// The fields mirror the gpui-component `Theme` surface the application
/// customizes at startup, so applying the settings is a plain field-for-field
/// copy. The theme names identify entries in the gpui-component theme
/// registry.
/// Fields mirror the gpui-component `Theme` surface customized at startup.
/// Applying the settings is then a field-for-field copy.
/// Theme names identify entries in the gpui-component theme registry.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct ThemeSettings {
@@ -42,7 +40,7 @@ pub struct ThemeSettings {
pub mono_font_size: f32,
/// Corner radius for general elements in pixels.
pub radius: f32,
/// Corner radius for large elements (dialogs, notifications) in pixels.
/// Corner radius for large elements, dialogs and notifications, in pixels.
pub radius_lg: f32,
/// Whether focused controls draw a ring outside their border.
pub focus_ring: bool,
@@ -69,8 +67,7 @@ impl Default for ThemeSettings {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct GraspServersSettings {
/// The servers offered when the user hasn't published a grasp list
/// (kind `10317`) yet.
/// Servers offered while the user has not published a grasp list, kind `10317`.
pub default_servers: Vec<String>,
}
@@ -90,7 +87,6 @@ impl Default for GraspServersSettings {
#[serde(default)]
pub struct LocalReposSettings {
/// The directories scanned for local git repositories.
///
/// Defaults to the user's Desktop and Documents folders.
pub scan_paths: Vec<PathBuf>,
}
@@ -107,16 +103,15 @@ impl Default for LocalReposSettings {
}
}
/// A remembered association between a local checkout folder and an
/// announced repository. Recorded when the user clones a repository from
/// the app or picks a folder in the New PR panel, so the panel can prefill
/// the folder later without asking again.
/// A remembered association between a local checkout folder and an announced repository.
/// Recorded when the user clones a repository or picks a folder in the New PR panel.
/// The panel can then prefill the folder later without asking again.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct CheckoutRecord {
/// Local folder of the checkout.
pub path: PathBuf,
/// Repository address (`30617:<pubkey>:<id>`) as a string.
/// Repository address as a string, `30617:<pubkey>:<id>`.
pub addr: String,
/// Unix seconds of the last use, for freshest-first ordering.
pub last_used: u64,
@@ -132,12 +127,12 @@ impl Default for CheckoutRecord {
}
}
/// Remembered local checkouts (see [`CheckoutRecord`]).
/// Remembered local checkouts, see [`CheckoutRecord`].
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct CheckoutsSettings {
/// The remembered records; the latest use of a path+repo pair replaces
/// the older record.
/// The remembered records.
/// The latest use of a path and repo pair replaces the older record.
pub records: Vec<CheckoutRecord>,
}
@@ -145,8 +140,7 @@ pub struct CheckoutsSettings {
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct CreateRepositorySettings {
/// The folder the create-repository dialog defaults to; the user's
/// Desktop when unset.
/// The folder the create-repository dialog defaults to, the user's Desktop when unset.
pub default_folder: Option<PathBuf>,
}
+8 -7
View File
@@ -9,7 +9,7 @@ struct GlobalSettingsStore(Entity<SettingsStore>);
impl Global for GlobalSettingsStore {}
/// The application settings, loaded from disk at startup and persisted whenever they change.
/// The application settings, loaded from disk at startup and saved whenever they change.
/// Installed as a global by the app so any part of the UI can read and edit them.
pub struct SettingsStore {
path: PathBuf,
@@ -17,7 +17,7 @@ pub struct SettingsStore {
}
impl SettingsStore {
/// Retrieve the global settings store (created at startup by the app).
/// Retrieve the global settings store, created at startup by the app.
pub fn global(cx: &App) -> Entity<Self> {
cx.global::<GlobalSettingsStore>().0.clone()
}
@@ -27,9 +27,10 @@ impl SettingsStore {
cx.set_global(GlobalSettingsStore(entity));
}
/// Load the settings from `path`, falling back to the defaults when the
/// file is missing or unreadable. Missing keys merge with the defaults,
/// so older settings files keep working as new settings are added.
/// Load the settings from `path`.
/// Falls back to defaults when the file is missing or unreadable.
/// Missing keys merge with the defaults.
/// Older settings files keep working as new settings are added.
pub fn new(path: impl AsRef<Path>, _cx: &mut Context<Self>) -> Self {
Self {
path: path.as_ref().to_path_buf(),
@@ -78,8 +79,8 @@ impl SettingsStore {
}
}
/// Write the settings to disk, replacing the file atomically
/// so a crash mid-write cannot corrupt the settings.
/// Write the settings to disk, replacing the file atomically.
/// A crash mid-write cannot corrupt the settings.
fn save(&self) -> Result<()> {
if let Some(parent) = self.path.parent() {
std::fs::create_dir_all(parent)?;