mirror of
https://github.com/zen-browser/desktop.git
synced 2026-05-20 03:51:20 +00:00
no-bug: A few quality-of-life tweaks (build tooling) (gh-13565)
This commit is contained in:
committed by
GitHub
parent
dcf272f620
commit
b93c2054c4
@@ -27,7 +27,7 @@
|
||||
"surfer": "surfer",
|
||||
"test": "python3 scripts/run_tests.py",
|
||||
"test:dbg": "python3 scripts/run_tests.py --jsdebugger --debug-on-failure",
|
||||
"ffprefs": "cd tools/ffprefs && cargo run --bin ffprefs -- ../../",
|
||||
"ffprefs": "${CARGO:-cargo} run --manifest-path tools/ffprefs/Cargo.toml --bin ffprefs -- prefs engine",
|
||||
"lc": "surfer license-check",
|
||||
"lc:fix": "surfer license-check --fix",
|
||||
"use-moz-src": "cd engine && ./mach use-moz-src",
|
||||
|
||||
@@ -60,4 +60,7 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) == 3:
|
||||
_, DUMPS_FOLDER, ENGINE_DUMPS_FOLDER = sys.argv
|
||||
main()
|
||||
|
||||
@@ -107,9 +107,9 @@ use std::env;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const STATIC_PREFS: &str = "../engine/modules/libpref/init/zen-static-prefs.inc";
|
||||
const FIREFOX_PREFS: &str = "../engine/browser/app/profile/firefox.js";
|
||||
const DYNAMIC_PREFS: &str = "../engine/browser/app/profile/zen.js";
|
||||
const STATIC_PREFS: &str = "modules/libpref/init/zen-static-prefs.inc";
|
||||
const FIREFOX_PREFS: &str = "browser/app/profile/firefox.js";
|
||||
const DYNAMIC_PREFS: &str = "browser/app/profile/zen.js";
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||
struct Preference {
|
||||
@@ -124,12 +124,6 @@ struct Preference {
|
||||
sticky: Option<bool>,
|
||||
}
|
||||
|
||||
fn get_config_path() -> PathBuf {
|
||||
let mut path = env::current_dir().expect("Failed to get current directory");
|
||||
path.push("prefs");
|
||||
path
|
||||
}
|
||||
|
||||
fn ordered_prefs(mut prefs: Vec<Preference>) -> Vec<Preference> {
|
||||
// Sort preferences by name
|
||||
prefs.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
@@ -153,11 +147,10 @@ fn get_prefs_files_recursively(dir: &PathBuf, files: &mut Vec<PathBuf>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn load_preferences() -> Vec<Preference> {
|
||||
fn load_preferences(prefs_path: &PathBuf) -> 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);
|
||||
get_prefs_files_recursively(&prefs_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> =
|
||||
@@ -263,14 +256,9 @@ fn get_value(pref: &Preference) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_preferences(prefs: &[Preference]) {
|
||||
let config_path = get_config_path();
|
||||
if !config_path.exists() {
|
||||
fs::create_dir_all(&config_path).expect("Failed to create prefs directory");
|
||||
}
|
||||
|
||||
let static_prefs_path = config_path.join(STATIC_PREFS);
|
||||
let dynamic_prefs_path = config_path.join(DYNAMIC_PREFS);
|
||||
fn write_preferences(engine_path: &PathBuf, prefs: &[Preference]) {
|
||||
let static_prefs_path = engine_path.join(STATIC_PREFS);
|
||||
let dynamic_prefs_path = engine_path.join(DYNAMIC_PREFS);
|
||||
println!(
|
||||
"Writing preferences to:\n Static: {}\n Dynamic: {}",
|
||||
static_prefs_path.display(),
|
||||
@@ -300,10 +288,10 @@ fn write_preferences(prefs: &[Preference]) {
|
||||
fs::write(&dynamic_prefs_path, dynamic_content).expect("Failed to write dynamic prefs");
|
||||
}
|
||||
|
||||
fn prepare_zen_prefs() {
|
||||
fn prepare_zen_prefs(engine_path: &PathBuf) {
|
||||
// Add `#include zen.js` to the bottom of the firefox.js file if it doesn't exist
|
||||
let line = "#include zen.js";
|
||||
let firefox_prefs_path = get_config_path().join(FIREFOX_PREFS);
|
||||
let firefox_prefs_path = engine_path.join(FIREFOX_PREFS);
|
||||
if let Ok(mut content) = fs::read_to_string(&firefox_prefs_path) {
|
||||
if !content.contains(line) {
|
||||
content.push_str(format!("\n{}\n", line).as_str());
|
||||
@@ -351,15 +339,19 @@ fn expand_pref_values(prefs: &mut [Preference]) {
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let root_path = if args.len() > 1 {
|
||||
let prefs_path = if args.len() > 1 {
|
||||
PathBuf::from(&args[1])
|
||||
} else {
|
||||
env::current_dir().expect("Failed to get current directory")
|
||||
PathBuf::from("prefs")
|
||||
};
|
||||
let engine_path = if args.len() > 2 {
|
||||
PathBuf::from(&args[2])
|
||||
} else {
|
||||
PathBuf::from("engine")
|
||||
};
|
||||
env::set_current_dir(&root_path).expect("Failed to change directory");
|
||||
|
||||
prepare_zen_prefs();
|
||||
let mut preferences = load_preferences();
|
||||
prepare_zen_prefs(&engine_path);
|
||||
let mut preferences = load_preferences(&prefs_path);
|
||||
expand_pref_values(&mut preferences);
|
||||
write_preferences(&preferences);
|
||||
write_preferences(&engine_path, &preferences);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user