Repository: versotile-org/verso
File: src/config.rs (Rust)

Code before:
        if let Some(devtools_port) = args.devtools_port {
            opts.devtools_server_enabled = true;
            opts.devtools_port = devtools_port;
        }

        let resource_dir = args.resource_dir.take().unwrap_or(resources_dir_path());

        Self {
            opts,
            args,
            resource_dir,
        }
    }

    /// Register URL scheme protocols
    pub fn create_protocols(&self) -> ProtocolRegistry {
        let handler = ResourceReader(self.resource_dir.clone());
        let mut protocols = ProtocolRegistry::with_internal_protocols();
        protocols.register("verso", handler);
        protocols
    }

    /// Init options and preferences.
    pub fn init(self) {
        // Set the resource files and preferences of Servo.
        resources::set(Box::new(ResourceReader(self.resource_dir.clone())));

        // Set the global options of Servo.
        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());
        // Rigppy image is the only one needs to be valid bytes.
        // Others can be empty and Servo will set to default.
        if let Resource::RippyPNG = file {
            fs::read(path).unwrap_or(include_bytes!("../resources/rippy.png").to_vec())
        } else {
            fs::read(path).unwrap_or_default()
        }
    }

    fn sandbox_access_files(&self) -> Vec<PathBuf> {
        vec![]
    }

    fn sandbox_access_files_dirs(&self) -> Vec<PathBuf> {

Review comment (suggestion):
```suggestion
        resources::set(Box::new(ResourceReader(self.resource_dir)));
```

Code after:
        if let Some(devtools_port) = args.devtools_port {
            opts.devtools_server_enabled = true;
            opts.devtools_port = devtools_port;
        }

        let resource_dir = args.resource_dir.clone().unwrap_or(resources_dir_path());

        Self {
            opts,
            args,
            resource_dir,
        }
    }

    /// Register URL scheme protocols
    pub fn create_protocols(&self) -> ProtocolRegistry {
        let handler = ResourceReader(self.resource_dir.clone());
        let mut protocols = ProtocolRegistry::with_internal_protocols();
        protocols.register("verso", handler);
        protocols
    }

    /// Init options and preferences.
    pub fn init(self) {
        // Set the resource files and preferences of Servo.
        resources::set(Box::new(ResourceReader(self.resource_dir)));

        // Set the global options of Servo.
        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());
        // Rigppy image is the only one needs to be valid bytes.
        // Others can be empty and Servo will set to default.
        if let Resource::RippyPNG = file {
            fs::read(path).unwrap_or(include_bytes!("../resources/rippy.png").to_vec())
        } else {
            fs::read(path).unwrap_or_default()
        }
    }

    fn sandbox_access_files(&self) -> Vec<PathBuf> {
        vec![]
    }

    fn sandbox_access_files_dirs(&self) -> Vec<PathBuf> {