Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg_attr(test, allow(clippy::expect_used, clippy::unwrap_used))]
use std::{cfg_select, path::PathBuf};
use std::{cfg_select, path::PathBuf, str::FromStr};

use gpui::{App, Global, ReadGlobal, SharedString};
use serde::{Deserialize, Serialize};
Expand All @@ -10,8 +10,6 @@ use crate::{
i18n::{I18n, Language},
};

mod validate;

const DEFAULT_MAX_HISTORY_RECORDS: usize = 100;
const DEFAULT_MAX_STORAGE_RECORDS: usize = 200;
/// 40% is the lowest opacity that still keeps text legible during testing;
Expand Down Expand Up @@ -130,6 +128,27 @@ impl Settings {
self.validate_storage();
self
}

/// Validate hotkey and reset to default if invalid.
fn validate_hotkey(&mut self) {
if self.hotkey.activation_key.is_empty()
|| global_hotkey::hotkey::HotKey::from_str(&self.hotkey.activation_key).is_err()
{
self.hotkey.activation_key = Self::default().hotkey.activation_key;
}
}

fn validate_window_opacity(&mut self) {
self.window.normalize_opacity();
}

fn validate_storage(&mut self) {
self.storage.max_history_records = self.storage.max_history_records.clamp(1, 10_000);
self.storage.max_storage_records = self.storage.max_storage_records.clamp(1, 100_000);
if self.storage.max_storage_records < self.storage.max_history_records {
self.storage.max_storage_records = self.storage.max_history_records;
}
}
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
Expand Down Expand Up @@ -298,8 +317,6 @@ impl Settings {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use tempfile::TempDir;

use super::*;
Expand Down
32 changes: 0 additions & 32 deletions src/config/settings/validate.rs

This file was deleted.

Loading