use napi::bindgen_prelude::*;
use napi_derive::napi;
use super::types::{ImeStateNapi, InputEventNapi};
use crate::input;
#[napi(js_name = "pollEvent")]
#[allow(clippy::disallowed_macros)]
pub fn poll_event(timeout_ms: u32) -> Result<Option<InputEventNapi>> {
let event = input::poll(timeout_ms as u64)
.map_err(|e| Error::new(Status::GenericFailure, format!("Poll error: {}", e)))?;
Ok(event.map(InputEventNapi::from))
}
#[napi(js_name = "pollEventNonBlocking")]
#[allow(clippy::disallowed_macros)]
pub fn poll_event_non_blocking() -> Result<Option<InputEventNapi>> {
let event = input::poll_nonblocking()
.map_err(|e| Error::new(Status::GenericFailure, format!("Poll error: {}", e)))?;
Ok(event.map(InputEventNapi::from))
}
#[napi(js_name = "readEvent")]
#[allow(clippy::disallowed_macros)]
pub fn read_event() -> Result<InputEventNapi> {
let event = input::read_event()
.map_err(|e| Error::new(Status::GenericFailure, format!("Read error: {}", e)))?;
Ok(InputEventNapi::from(event))
}
#[napi(js_name = "getImeState")]
pub fn get_ime_state() -> Result<ImeStateNapi> {
Ok(ImeStateNapi {
active: false,
mode: "direct".to_string(),
composing: false,
preedit: None,
preedit_cursor: None,
candidates: None,
selected: None,
})
}
#[napi(js_name = "enableIme")]
pub fn enable_ime() -> Result<bool> {
Ok(true)
}
#[napi(js_name = "disableIme")]
pub fn disable_ime() -> Result<bool> {
Ok(true)
}
#[napi(js_name = "setImeMode")]
pub fn set_ime_mode(mode: String) -> Result<()> {
let _ = mode;
Ok(())
}