Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): exclude windows terminal attach #414

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ fn main() -> iced::Result {
gui::UadGui::start()
}

/// Sets up logging to a new file in CACHE_DIR/UAD_{time}.log
/// Also attaches the terminal on Windows machines
/// '''
/// match setup_logger().expect("Error setting up logger")
/// '''
pub fn setup_logger() -> Result<(), fern::InitError> {
attach_windows_console();
/// Attach Windows terminal, only on windows
Frigyes06 marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(target_os = "windows")]
{
attach_windows_console();
}

let colors = ColoredLevelConfig::new().info(Color::Green);

Expand Down Expand Up @@ -80,13 +89,23 @@ pub fn setup_logger() -> Result<(), fern::InitError> {
/// (Windows) Allow the application to display logs to the terminal
/// regardless if it was compiled with `windows_subsystem = "windows"`.
///
/// This is a no-op when compiled to non-windows targets.
/// This is excluded on non-windows targets.
Frigyes06 marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(target_os = "windows")]
fn attach_windows_console() {
#[cfg(target_os = "windows")]
{
use win32console::console::WinConsole;
use win32console::console::WinConsole;

const ATTACH_PARENT_PROCESS: u32 = 0xFFFFFFFF;
let _ = WinConsole::attach_console(ATTACH_PARENT_PROCESS);
}

const ATTACH_PARENT_PROCESS: u32 = 0xFFFFFFFF;
let _ = WinConsole::attach_console(ATTACH_PARENT_PROCESS);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn init_logger() {
match setup_logger() {
Ok(_) => (),
Err(error) => panic!("Error: {}", error),
}
}
}