Skip to content

Commit

Permalink
expose resource assembly from neon bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Sep 26, 2019
1 parent de6bf7b commit 9a39e66
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ extern crate neon_serde;
extern crate adblock;

use neon::prelude::*;
use std::path::Path;
use adblock::engine::Engine;
use adblock::filter_lists;
use adblock::resources::Resource;
use adblock::resource_assembler::{assemble_web_accessible_resources, assemble_scriptlet_resources};


declare_types! {
pub class JsEngine for Engine {
Expand Down Expand Up @@ -111,7 +115,8 @@ declare_types! {
}

method updateResources(mut cx) {
let resources: String = cx.argument::<JsString>(0)?.value();
let resources_arg = cx.argument::<JsValue>(0)?;
let resources: Vec<Resource> = neon_serde::from_value(&mut cx, resources_arg)?;

let mut this = cx.this();
let guard = cx.lock();
Expand Down Expand Up @@ -200,9 +205,23 @@ fn lists(mut cx: FunctionContext) -> JsResult<JsValue> {
Ok(js_list)
}

fn ublock_resources(mut cx: FunctionContext) -> JsResult<JsValue> {
let web_accessible_resource_dir: String = cx.argument::<JsString>(0)?.value();
let redirect_engine_path: String = cx.argument::<JsString>(1)?.value();
let scriptlets_path: String = cx.argument::<JsString>(2)?.value();

let mut resources = assemble_web_accessible_resources(&Path::new(&web_accessible_resource_dir), &Path::new(&redirect_engine_path));
resources.append(&mut assemble_scriptlet_resources(&Path::new(&scriptlets_path)));

let js_resources = neon_serde::to_value(&mut cx, &resources)?;

Ok(js_resources)
}

register_module!(mut m, {
// Export the `JsEngine` class
m.export_class::<JsEngine>("Engine")?;
m.export_function("lists", lists)?;
m.export_function("uBlockResources", ublock_resources)?;
Ok(())
});

0 comments on commit 9a39e66

Please sign in to comment.