Skip to content

Commit dc8c568

Browse files
authored
refactor(config): inline validate.rs into settings.rs and remove settings/ folder (#123)
Refs #122
1 parent 44c6ee6 commit dc8c568

2 files changed

Lines changed: 22 additions & 37 deletions

File tree

src/config/settings.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![cfg_attr(test, allow(clippy::expect_used, clippy::unwrap_used))]
2-
use std::{cfg_select, path::PathBuf};
2+
use std::{cfg_select, path::PathBuf, str::FromStr};
33

44
use gpui::{App, Global, ReadGlobal, SharedString};
55
use serde::{Deserialize, Serialize};
@@ -10,8 +10,6 @@ use crate::{
1010
i18n::{I18n, Language},
1111
};
1212

13-
mod validate;
14-
1513
const DEFAULT_MAX_HISTORY_RECORDS: usize = 100;
1614
const DEFAULT_MAX_STORAGE_RECORDS: usize = 200;
1715
/// 40% is the lowest opacity that still keeps text legible during testing;
@@ -130,6 +128,27 @@ impl Settings {
130128
self.validate_storage();
131129
self
132130
}
131+
132+
/// Validate hotkey and reset to default if invalid.
133+
fn validate_hotkey(&mut self) {
134+
if self.hotkey.activation_key.is_empty()
135+
|| global_hotkey::hotkey::HotKey::from_str(&self.hotkey.activation_key).is_err()
136+
{
137+
self.hotkey.activation_key = Self::default().hotkey.activation_key;
138+
}
139+
}
140+
141+
fn validate_window_opacity(&mut self) {
142+
self.window.normalize_opacity();
143+
}
144+
145+
fn validate_storage(&mut self) {
146+
self.storage.max_history_records = self.storage.max_history_records.clamp(1, 10_000);
147+
self.storage.max_storage_records = self.storage.max_storage_records.clamp(1, 100_000);
148+
if self.storage.max_storage_records < self.storage.max_history_records {
149+
self.storage.max_storage_records = self.storage.max_history_records;
150+
}
151+
}
133152
}
134153

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

299318
#[cfg(test)]
300319
mod tests {
301-
use std::str::FromStr;
302-
303320
use tempfile::TempDir;
304321

305322
use super::*;

src/config/settings/validate.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)