use std::{fs, path::PathBuf};
use embedder_traits::resources::{self, Resource, ResourceReaderMethods};
use servo_config::opts::{default_opts, set_options, Opts};
#[derive(Clone, Debug)]
pub struct Config {
pub opts: Opts,
pub resource_dir: PathBuf,
}
impl Config {
pub fn new(resource_dir: PathBuf) -> Self {
let opts = default_opts();
Self { opts, resource_dir }
}
pub fn init(self) {
resources::set(Box::new(ResourceReader(self.resource_dir)));
set_options(self.opts);
}
}
struct ResourceReader(PathBuf);
impl ResourceReaderMethods for ResourceReader {
fn read(&self, file: Resource) -> Vec<u8> {
let path = self.0.join(file.filename());
fs::read(path).expect("Can't read file")
}
fn sandbox_access_files(&self) -> Vec<PathBuf> {
vec![]
}
fn sandbox_access_files_dirs(&self) -> Vec<PathBuf> {
vec![]
}
}