use anyhow::Result;
use derive_builder::Builder;
use enigo::{Enigo, Key, KeyboardControllable, MouseControllable};
use std::{thread, time::Duration};
mod sys;
#[derive(Builder, Debug)]
#[builder(public, name = "Builder", build_fn(private))]
#[allow(dead_code)] struct Options {
#[builder(default)]
display: bool,
#[builder(default)]
idle: bool,
#[builder(default)]
sleep: bool,
#[builder(setter(into), default = "\"User requested\".to_string()")]
reason: String,
#[builder(setter(into), default = "\"keep-active\".to_string()")]
app_name: String,
#[builder(
setter(into),
default = "\"io.github.omerbustun.keep-active\".to_string()"
)]
app_reverse_domain: String,
}
impl Builder {
pub fn create(&self) -> Result<KeepActive> {
Ok(KeepActive {
_imp: sys::KeepActive::new(self.build()?)?,
})
}
}
pub struct KeepActive {
_imp: sys::KeepActive,
}
pub fn simulate_activity() -> Result<(), Box<dyn std::error::Error>> {
let mut enigo = Enigo::new();
let step_count = 20; let radius = 1.0;
loop {
for i in 0..step_count {
let angle = 2.0 * std::f64::consts::PI * (i as f64) / (step_count as f64);
let x = (radius * angle.cos()).round() as i32;
let y = (radius * angle.sin()).round() as i32;
enigo.mouse_move_relative(x, y);
thread::sleep(Duration::from_millis(100));
}
enigo.key_down(Key::Shift);
enigo.key_up(Key::Shift);
thread::sleep(Duration::from_secs(60)); }
}