Skip to content

Commit 92f652d

Browse files
authored
feat: simplify and change configuration (#279)
*breaking change* this changes the configuration syntax, allowing for an unlimited amount of configured clients. Also a first step towards enabling a "save config" feature.
1 parent 2f6a362 commit 92f652d

File tree

10 files changed

+224
-243
lines changed

10 files changed

+224
-243
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lan-mouse-cli/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub enum CliError {
1818
Ipc(#[from] IpcError),
1919
}
2020

21-
#[derive(Parser, Debug, PartialEq, Eq)]
21+
#[derive(Parser, Clone, Debug, PartialEq, Eq)]
2222
#[command(name = "lan-mouse-cli", about = "LanMouse CLI interface")]
2323
pub struct CliArgs {
2424
#[command(subcommand)]
@@ -37,7 +37,7 @@ struct Client {
3737
enter_hook: Option<String>,
3838
}
3939

40-
#[derive(Subcommand, Debug, PartialEq, Eq)]
40+
#[derive(Clone, Subcommand, Debug, PartialEq, Eq)]
4141
enum CliSubcommand {
4242
/// add a new client
4343
AddClient(Client),

lan-mouse-gtk/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ async-channel = { version = "2.1.1" }
1313
hostname = "0.4.0"
1414
log = "0.4.20"
1515
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.2.0" }
16+
thiserror = "2.0.0"
1617

1718
[build-dependencies]
1819
glib-build-tools = { version = "0.20.0" }

lan-mouse-gtk/src/lib.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ use gtk::{gio, glib, prelude::ApplicationExt};
1818
use self::client_object::ClientObject;
1919
use self::key_object::KeyObject;
2020

21-
pub fn run() -> glib::ExitCode {
21+
use thiserror::Error;
22+
23+
#[derive(Error, Debug)]
24+
pub enum GtkError {
25+
#[error("gtk frontend exited with non zero exit code: {0}")]
26+
NonZeroExitCode(i32),
27+
}
28+
29+
pub fn run() -> Result<(), GtkError> {
2230
log::debug!("running gtk frontend");
2331
#[cfg(windows)]
2432
let ret = std::thread::Builder::new()
@@ -31,13 +39,10 @@ pub fn run() -> glib::ExitCode {
3139
#[cfg(not(windows))]
3240
let ret = gtk_main();
3341

34-
if ret == glib::ExitCode::FAILURE {
35-
log::error!("frontend exited with failure");
36-
} else {
37-
log::info!("frontend exited successfully");
42+
match ret {
43+
glib::ExitCode::SUCCESS => Ok(()),
44+
e => Err(GtkError::NonZeroExitCode(e.value())),
3845
}
39-
40-
ret
4146
}
4247

4348
fn gtk_main() -> glib::ExitCode {

lan-mouse-gtk/src/window.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Window {
126126
#[strong]
127127
window,
128128
move |row: ClientRow, hostname: String| {
129-
log::info!("request-hostname-change");
129+
log::debug!("request-hostname-change");
130130
if let Some(client) = window.client_by_idx(row.index() as u32) {
131131
let hostname = Some(hostname).filter(|s| !s.is_empty());
132132
/* changed in response to FrontendEvent
@@ -163,7 +163,7 @@ impl Window {
163163
window,
164164
move |row: ClientRow, active: bool| {
165165
if let Some(client) = window.client_by_idx(row.index() as u32) {
166-
log::info!(
166+
log::debug!(
167167
"request: {} client",
168168
if active { "activating" } else { "deactivating" }
169169
);

src/capture_test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use futures::StreamExt;
44
use input_capture::{self, CaptureError, CaptureEvent, InputCapture, InputCaptureError, Position};
55
use input_event::{Event, KeyboardEvent};
66

7-
#[derive(Args, Debug, Eq, PartialEq)]
7+
#[derive(Args, Clone, Debug, Eq, PartialEq)]
88
pub struct TestCaptureArgs {}
99

1010
pub async fn run(config: Config, _args: TestCaptureArgs) -> Result<(), InputCaptureError> {
1111
log::info!("running input capture test");
1212
log::info!("creating input capture");
13-
let backend = config.capture_backend.map(|b| b.into());
13+
let backend = config.capture_backend().map(|b| b.into());
1414
loop {
1515
let mut input_capture = InputCapture::new(backend).await?;
1616
log::info!("creating clients");

0 commit comments

Comments
 (0)