Skip to content

Commit b81e3f8

Browse files
committed
fix: process command line arguments passed to daemon BEFORE clap
1 parent ce22525 commit b81e3f8

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

src/clipboard.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn set_image(
6464
.arg(clipboard_buffer_path.path())
6565
.stdin(process::Stdio::null())
6666
.stdout(process::Stdio::null())
67-
.stderr(process::Stdio::null())
67+
.stderr(process::Stdio::inherit())
6868
.current_dir("/")
6969
.spawn()?;
7070
}

src/main.rs

+33-17
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,49 @@ use miette::IntoDiagnostic;
1111
const LOGO: &[u8; 64 * 64 * 4] = include_bytes!(concat!(env!("OUT_DIR"), "/logo.bin"));
1212

1313
fn main() -> miette::Result<()> {
14+
// On linux, a daemon is required to provide clipboard access even when
15+
// the process dies.
16+
//
17+
// More info: <https://docs.rs/arboard/3.5.0/arboard/trait.SetExtLinux.html#tymethod.wait>
18+
#[cfg(target_os = "linux")]
19+
{
20+
if std::env::args()
21+
.nth(1)
22+
.as_deref()
23+
.is_some_and(|arg| arg == ferrishot::CLIPBOARD_DAEMON_ID)
24+
{
25+
ferrishot::run_clipboard_daemon().expect("Failed to run clipboard daemon");
26+
return Ok(());
27+
}
28+
}
29+
1430
// This will parse the command line arguments.
1531
//
1632
// Needs to come before the logging initialization because there
1733
// is an argument to change the verbosity
1834
LazyLock::force(&CLI);
1935

36+
// env_logger::Builder::new()
37+
// .format(|buf, record| {
38+
// writeln!(
39+
// buf,
40+
// "{}:{} {} [{}] - {}",
41+
// record.file().unwrap_or("unknown"),
42+
// record.line().unwrap_or(0),
43+
// chrono::Local::now().format("%Y-%m-%dT%H:%M:%S%.3f"),
44+
// record.level(),
45+
// record.args()
46+
// )
47+
// })
48+
// .target(env_logger::Target::Pipe(target))
49+
// .filter(None, log::LevelFilter::Error)
50+
// .init();
51+
2052
// Initialize logging
2153
// TODO:
2254
// - log to file.
2355
// - add ways to increase logging with command line arguments. Currently you must use `RUST_LOG=info`
24-
env_logger::builder().init();
56+
// env_logger::builder().init();
2557

2658
LazyLock::force(&ferrishot::CONFIG);
2759

@@ -38,22 +70,6 @@ fn main() -> miette::Result<()> {
3870
return Ok(());
3971
}
4072

41-
// On linux, a daemon is required to provide clipboard access even when
42-
// the process dies.
43-
//
44-
// More info: <https://docs.rs/arboard/3.5.0/arboard/trait.SetExtLinux.html#tymethod.wait>
45-
#[cfg(target_os = "linux")]
46-
{
47-
if std::env::args()
48-
.nth(1)
49-
.as_deref()
50-
.is_some_and(|arg| arg == ferrishot::CLIPBOARD_DAEMON_ID)
51-
{
52-
ferrishot::run_clipboard_daemon().expect("Failed to run clipboard daemon");
53-
return Ok(());
54-
}
55-
}
56-
5773
iced::application(App::default, App::update, App::view)
5874
.window(iced::window::Settings {
5975
level: iced::window::Level::Normal,

0 commit comments

Comments
 (0)