Skip to content

Commit c8feef8

Browse files
committed
Embed uinput module for rmpp
1 parent ba884d0 commit c8feef8

10 files changed

Lines changed: 172 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 135 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ evdev = "0.12.0"
1717
resvg = "0.44.0"
1818
dotenv = "0.15"
1919
imageproc = "0.25.0"
20-
rust-embed="8.5.0"
20+
rust-embed = { version = "8.5.0", features = ["include-exclude", "compression"] }
2121
env_logger = "0.11.6"
2222
log = "0.4.22"
2323

src/main.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::sync::{Arc, Mutex};
1010

1111
use std::thread::sleep;
1212
use std::time::Duration;
13+
use std::io::Write;
1314

1415
use ghostwriter::{
1516
keyboard::Keyboard,
@@ -27,7 +28,12 @@ const REMARKABLE_HEIGHT: u32 = 1024;
2728

2829
#[derive(Embed)]
2930
#[folder = "prompts/"]
30-
struct Asset;
31+
struct AssetPrompts;
32+
33+
#[derive(Embed)]
34+
#[folder = "utils/"]
35+
#[include = "rmpp/uinput-3.17.ko"]
36+
struct AssetUtils;
3137

3238
#[derive(Parser)]
3339
#[command(author, version)]
@@ -123,6 +129,8 @@ fn main() -> Result<()> {
123129
.format_timestamp_millis()
124130
.init();
125131

132+
setup_uinput()?;
133+
126134
ghostwriter(&args)
127135
}
128136

@@ -138,6 +146,32 @@ macro_rules! lock {
138146
};
139147
}
140148

149+
fn setup_uinput() -> Result<()> {
150+
debug!("Checking for uinput module");
151+
// Check if uinput module is loaded by looking at the lsmod output
152+
let output = std::process::Command::new("lsmod")
153+
.output()
154+
.expect("Failed to execute lsmod");
155+
let output_str = std::str::from_utf8(&output.stdout).unwrap();
156+
if!output_str.contains("uinput") {
157+
info!("uinput module not found, installing bundled version");
158+
let uinput_module_asset = AssetUtils::get("rmpp/uinput-3.17.ko").unwrap();
159+
let raw_uinput_module_data = uinput_module_asset.data.as_ref();
160+
let mut uinput_module_file = std::fs::File::create("/tmp/uinput.ko")?;
161+
uinput_module_file.write_all(raw_uinput_module_data)?;
162+
uinput_module_file.flush()?;
163+
drop(uinput_module_file);
164+
let output = std::process::Command::new("insmod")
165+
.arg("/tmp/uinput.ko")
166+
.output()?;
167+
let output_str = std::str::from_utf8(&output.stderr).unwrap();
168+
info!("insmod output: {}", output_str);
169+
}
170+
171+
Ok(())
172+
}
173+
174+
141175
fn draw_text(text: &str, keyboard: &mut Keyboard) -> Result<()> {
142176
info!("Drawing text to the screen.");
143177
// keyboard.progress(".")?;
@@ -173,7 +207,7 @@ fn load_config(filename: &str) -> String {
173207
if std::path::Path::new(filename).exists() {
174208
std::fs::read_to_string(filename).unwrap()
175209
} else {
176-
std::str::from_utf8(Asset::get(filename).unwrap().data.as_ref())
210+
std::str::from_utf8(AssetPrompts::get(filename).unwrap().data.as_ref())
177211
.unwrap()
178212
.to_string()
179213
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)