Skip to content

Commit

Permalink
windows: AttachConsole
Browse files Browse the repository at this point in the history
  • Loading branch information
kiron1 committed Jan 19, 2025
1 parent 432567c commit 0d0127f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions doc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mdbook(
"service.md",
"transparent_proxy.md",
"usage.md",
"windows.md",
":proxydetox_help",
],
book = "//:book.toml",
Expand Down
1 change: 1 addition & 0 deletions doc/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Installation](installation.md)
- [Configuration](configuration.md)
- [Usage](usage.md)
- [Windows users](windows.md)

---

Expand Down
11 changes: 11 additions & 0 deletions doc/windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Windows

On Windows Proxydetox is _not_ a console application and therefor no console window is visible.
No console window is shown, such that Proxydetox can be launched as a background process without any disturbing windows.

The missing console windows also has the effect, that when Proxydetox is launched from the terminal no output is visible.
The help output as well as the log output is affected by this. An online version of the help output can be found in the
[command line reference](cliref.md) section.

Additionally there is the `--attach-console` options on Windows builds of Proxydetox to attach to the parrent console.
When running Proxydetox from the Windows command prompt, add the `--attach-console` optin to be able to see the output.
6 changes: 6 additions & 0 deletions proxydetox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ tracing-subscriber.workspace = true
tokio-rustls.workspace = true
rustls-pemfile.workspace = true
rustls.workspace = true

[target.'cfg(windows)'.dependencies]
windows = { version = "0.58", features = [
"Win32_System",
"Win32_System_Console",
] }
10 changes: 10 additions & 0 deletions proxydetox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ pub extern "C" fn main() {
fn main() {
let config = Options::load();

#[cfg(target_family = "windows")]
if config.attach_console {
unsafe {
windows::Win32::System::Console::AttachConsole(
windows::Win32::System::Console::ATTACH_PARENT_PROCESS,
)
.unwrap();
}
}

if let Err(error) = run(config) {
tracing::error!(%error, "fatal error");
write_error(&mut std::io::stderr(), error).ok();
Expand Down
12 changes: 12 additions & 0 deletions proxydetox/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub enum Authorization {

#[derive(Debug)]
pub struct Options {
#[cfg(target_family = "windows")]
pub attach_console: bool,
pub log_level: LevelFilter,
pub log_filepath: Option<PathBuf>,
pub pac_file: Option<PathOrUri>,
Expand Down Expand Up @@ -113,6 +115,14 @@ impl Options {
.about("A small proxy to relieve the pain of some corporate proxies")
.args_override_self(true);

#[cfg(target_family = "windows")]
let app = app.arg(
Arg::new("attach_console")
.long("attach-console")
.help("Attache to the console of the parent process")
.action(ArgAction::SetTrue),
);

#[cfg(feature = "negotiate")]
let app = app.arg(
Arg::new("negotiate")
Expand Down Expand Up @@ -354,6 +364,8 @@ impl From<ArgMatches> for Options {
.with_retries(m.get_one::<u32>("server_tcp_keepalive_retries").cloned());

Self {
#[cfg(target_family = "windows")]
attach_console: m.get_flag("attach_console"),
log_level,
log_filepath: m.get_one("log_filepath").cloned(),
pac_file: m
Expand Down

0 comments on commit 0d0127f

Please sign in to comment.