feat(system): add locale detection

Swadhin Biswas committed 7 months ago
ced4ae4
1 parent 14b52a3
commit ced4ae4
1 file changed
+70 -0
Showing 1 changed file+70-0
▼src/system/mod.rs
+70-0
828
828
}
829
829
830
830
fn get_theme() -> String {
831
+ // GTK theme
832
+ let theme = run_cmd(
833
+ "gsettings",
834
+ &["get", "org.gnome.desktop.interface", "gtk-theme"],
835
+ );
836
+ let theme = theme.trim_matches('\'').trim().to_string();
837
+ if !theme.is_empty() && theme != "No such schema" && !theme.starts_with("Error") {
838
+ return theme;
839
+ }
840
+
841
+ // Check GTK3 settings file
842
+ let gtk3_settings = format!("{}/.config/gtk-3.0/settings.ini", crate::utils::home_dir());
843
+ if Path::new(&gtk3_settings).exists() {
844
+ let content = read_file(&gtk3_settings);
845
+ for line in content.lines() {
846
+ if let Some(val) = line.strip_prefix("gtk-theme-name=") {
847
+ return val.trim().to_string();
848
+ }
849
+ }
850
+ }
851
+
852
+ "Unknown".to_string()
853
+}
854
+
855
+fn get_icons() -> String {
856
+ let icons = run_cmd(
857
+ "gsettings",
858
+ &["get", "org.gnome.desktop.interface", "icon-theme"],
859
+ );
860
+ let icons = icons.trim_matches('\'').trim().to_string();
861
+ if !icons.is_empty() && icons != "No such schema" && !icons.starts_with("Error") {
862
+ return icons;
863
+ }
864
+
865
+ let gtk3_settings = format!("{}/.config/gtk-3.0/settings.ini", crate::utils::home_dir());
866
+ if Path::new(&gtk3_settings).exists() {
867
+ let content = read_file(&gtk3_settings);
868
+ for line in content.lines() {
869
+ if let Some(val) = line.strip_prefix("gtk-icon-theme-name=") {
870
+ return val.trim().to_string();
871
+ }
872
+ }
873
+ }
874
+
875
+ "Unknown".to_string()
876
+}
877
+
878
+fn get_terminal() -> String {
879
+ // Walk up the process tree to find the terminal emulator
880
+ // This mirrors neofetch's PPID walking approach
881
+ let mut pid = std::process::id();
882
+
883
+ for _ in 0..10 {
884
+ let stat_path = format!("/proc/{}/status", pid);
885
+ let content = read_file(&stat_path);
886
+ if content.is_empty() {
887
+ break;
888
+ }
889
+
890
+ let mut name = String::new();
891
+ let mut ppid = 0u32;
892
+
893
+ for line in content.lines() {
894
+ if let Some(val) = line.strip_prefix("Name:\t") {
895
+ name = val.trim().to_string();
896
+ } else if let Some(val) = line.strip_prefix("PPid:\t") {
897
+ ppid = val.trim().parse().unwrap_or(0);
898
+ }
899
+ }
900
+
831
901