chore: Better organize preferences files, b=no-bug, c=compact-mode, folders, glance, kbs, media, mods, split-view, welcome, workspaces
This commit is contained in:
8
prefs/README.md
Normal file
8
prefs/README.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
# Browser Preferences
|
||||||
|
|
||||||
|
This directory contains configuration files for Zen. They are divided by folder according to the source / component they belong to and further divided by file according to their purpose.
|
||||||
|
|
||||||
|
- `firefox/`: Preferences to override Firefox defaults.
|
||||||
|
- `zen/`: Preferences to configure Zen-specific features.
|
||||||
|
- `privatefox/` & `fastfox/`: *Some* of the preferences got extracted from [Betterfox](https://github.com/yokoffing/Betterfox).
|
||||||
@@ -17,3 +17,6 @@
|
|||||||
|
|
||||||
- name: browser.ml.enable
|
- name: browser.ml.enable
|
||||||
value: false
|
value: false
|
||||||
|
|
||||||
|
- name: browser.ml.chat.menu
|
||||||
|
value: false
|
||||||
@@ -102,10 +102,10 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
const STATIC_PREFS: &str = "../engine/modules/libpref/init/zen-static-prefs.inc";
|
const STATIC_PREFS: &str = "../engine/modules/libpref/init/zen-static-prefs.inc";
|
||||||
const FIREFOX_PREFS: &str = "../engine/browser/app/profile/firefox.js";
|
const FIREFOX_PREFS: &str = "../engine/browser/app/profile/firefox.js";
|
||||||
@@ -136,25 +136,34 @@ fn ordered_prefs(mut prefs: Vec<Preference>) -> Vec<Preference> {
|
|||||||
prefs
|
prefs
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_preferences() -> Vec<Preference> {
|
fn get_prefs_files_recursively(dir: &PathBuf, files: &mut Vec<PathBuf>) {
|
||||||
let mut prefs = Vec::new();
|
if let Ok(entries) = fs::read_dir(dir) {
|
||||||
let config_path = get_config_path();
|
|
||||||
// Iterate each file in the prefs directory
|
|
||||||
if let Ok(entries) = fs::read_dir(&config_path) {
|
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
if let Ok(entry) = entry {
|
if let Ok(entry) = entry {
|
||||||
if let Some(ext) = entry.path().extension() {
|
let path = entry.path();
|
||||||
|
if path.is_dir() {
|
||||||
|
get_prefs_files_recursively(&path, files);
|
||||||
|
} else if let Some(ext) = path.extension() {
|
||||||
if ext == "yaml" || ext == "yml" {
|
if ext == "yaml" || ext == "yml" {
|
||||||
let file_path = entry.path();
|
files.push(path);
|
||||||
let content = fs::read_to_string(&file_path).expect("Failed to read file");
|
|
||||||
let mut parsed_prefs: Vec<Preference> =
|
|
||||||
serde_yaml::from_str(&content).expect("Failed to parse YAML");
|
|
||||||
prefs.append(&mut parsed_prefs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_preferences() -> Vec<Preference> {
|
||||||
|
let mut prefs = Vec::new();
|
||||||
|
let config_path = get_config_path();
|
||||||
|
let mut pref_files = Vec::new();
|
||||||
|
get_prefs_files_recursively(&config_path, &mut pref_files);
|
||||||
|
for file_path in pref_files {
|
||||||
|
let content = fs::read_to_string(&file_path).expect("Failed to read file");
|
||||||
|
let mut parsed_prefs: Vec<Preference> =
|
||||||
|
serde_yaml::from_str(&content).expect("Failed to parse YAML");
|
||||||
|
prefs.append(&mut parsed_prefs);
|
||||||
|
}
|
||||||
ordered_prefs(prefs)
|
ordered_prefs(prefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user