Implemeeeeeent
This commit is contained in:
@@ -11,19 +11,22 @@ impl Finalize for Metronome {}
|
||||
|
||||
pub fn get_beat_tracker(mut cx: FunctionContext) -> JsResult<JsObject> {
|
||||
let obj = cx.empty_object();
|
||||
let value_obj = cx.empty_object();
|
||||
|
||||
let boxed_tracker = cx.boxed(RefCell::new(Metronome::new(Duration::from_secs(2))));
|
||||
value_obj.set(&mut cx, "_rust_ptr", boxed_tracker)?;
|
||||
|
||||
let tap_function = JsFunction::new(&mut cx, tap)?;
|
||||
value_obj.set(&mut cx, "tap", tap_function)?;
|
||||
|
||||
let get_progress_function = JsFunction::new(&mut cx, get_progress)?;
|
||||
value_obj.set(&mut cx, "getProgress", get_progress_function)?;
|
||||
|
||||
obj.set(&mut cx, "value", value_obj)?;
|
||||
|
||||
let success_string = cx.string("success".to_string());
|
||||
obj.set(&mut cx, "type", success_string)?;
|
||||
|
||||
let boxed_tracker = cx.boxed(RefCell::new(Metronome::new(Duration::from_secs(2))));
|
||||
obj.set(&mut cx, "_rust_ptr", boxed_tracker)?;
|
||||
|
||||
let tap_function = JsFunction::new(&mut cx, tap)?;
|
||||
obj.set(&mut cx, "tap", tap_function)?;
|
||||
|
||||
let get_progress_function = JsFunction::new(&mut cx, get_progress)?;
|
||||
obj.set(&mut cx, "getProgress", get_progress_function)?;
|
||||
|
||||
Ok(obj)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,31 +29,33 @@ pub fn open_output(mut cx: FunctionContext) -> JsResult<JsObject> {
|
||||
let path = path.value(&mut cx);
|
||||
|
||||
let obj = cx.empty_object();
|
||||
let success_string;
|
||||
let value_obj = cx.empty_object();
|
||||
|
||||
match Controller::new(path) {
|
||||
Ok(controller) => {
|
||||
success_string = cx.string("success");
|
||||
let success_string = cx.string("success");
|
||||
obj.set(&mut cx, "type", success_string)?;
|
||||
|
||||
let boxed_controller = cx.boxed(RefCell::new(controller));
|
||||
obj.set(&mut cx, "_rust_ptr", boxed_controller)?;
|
||||
value_obj.set(&mut cx, "_rust_ptr", boxed_controller)?;
|
||||
|
||||
let set_output_function = JsFunction::new(&mut cx, set_output)?;
|
||||
obj.set(&mut cx, "set", set_output_function)?;
|
||||
value_obj.set(&mut cx, "set", set_output_function)?;
|
||||
|
||||
let close_function = JsFunction::new(&mut cx, close_output)?;
|
||||
obj.set(&mut cx, "close", close_function)?;
|
||||
value_obj.set(&mut cx, "close", close_function)?;
|
||||
|
||||
obj.set(&mut cx, "value", value_obj)?;
|
||||
}
|
||||
Err(e) => {
|
||||
success_string = cx.string("error");
|
||||
let success_string = cx.string("error");
|
||||
obj.set(&mut cx, "type", success_string)?;
|
||||
|
||||
let error_message = cx.string(e.to_string());
|
||||
obj.set(&mut cx, "message", error_message)?;
|
||||
}
|
||||
}
|
||||
|
||||
obj.set(&mut cx, "type", success_string)?;
|
||||
|
||||
Ok(obj)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user