hyprshell_core_lib/config/
check.rs1use crate::config::Config;
2use anyhow::bail;
3
4pub fn check(config: &Config) -> anyhow::Result<()> {
5 if config
6 .windows
7 .as_ref()
8 .map(|w| w.scale >= 15f64 || w.scale <= 0f64)
9 .unwrap_or(false)
10 {
11 bail!("Scale factor must be less than 15 and greater than 0");
12 }
13
14 if config
15 .windows
16 .as_ref()
17 .and_then(|w| w.overview.as_ref())
18 .map(|o| o.launcher.launch_modifier == o.modifier)
19 .unwrap_or(false)
20 {
21 bail!(
22 "Launcher modifier cannot be the same as overview open modifier. (pressing the modifier will just close the overview instead of launching an app)"
23 );
24 }
25
26 if config
27 .windows
28 .as_ref()
29 .and_then(|w| w.overview.as_ref())
30 .map(|o| matches!(&*o.key, "super" | "alt" | "shift" | "control" | "ctrl"))
31 .unwrap_or(false)
32 {
33 bail!(
34 "If a modifier key is used to open it must include _l or _r at the end. (e.g. super_l, alt_r, etc)\nctrl_l / _r is NOT a valid modifier key, only control_l / _r is"
35 );
36 }
37
38 if let Some(l) = &config
39 .windows
40 .as_ref()
41 .and_then(|w| w.overview.as_ref().map(|o| &o.launcher))
42 {
43 let mut used: Vec<char> = vec![];
44 for engine in l
45 .plugins
46 .websearch
47 .as_ref()
48 .map(|ws| &ws.engines)
49 .unwrap_or(&vec![])
50 {
51 if engine.url.is_empty() {
52 bail!("Search engine url cannot be empty");
53 }
54 if engine.name.is_empty() {
55 bail!("Search engine name cannot be empty");
56 }
57 if used.contains(&engine.key) {
58 bail!("Duplicate search engine key: {}", engine.key);
59 } else {
60 used.push(engine.key);
61 }
62 }
63 if l.plugins.calc.is_some() {
64 #[cfg(not(feature = "calc"))]
65 {
66 bail!("Calc Plugin enabled but not compiled in, please enable the calc feature");
67 }
68 }
69 };
70
71 Ok(())
72}