@@ -10,6 +10,7 @@ use std::sync::{Arc, Mutex};
1010
1111use std:: thread:: sleep;
1212use std:: time:: Duration ;
13+ use std:: io:: Write ;
1314
1415use 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+
141175fn 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 }
0 commit comments