From 4e357af95981f11302c983ae99e55b4eb29fea92 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Fri, 10 Feb 2023 01:20:54 +0100 Subject: [PATCH] use windows subsystem attach console on release builds --- kubi/Cargo.toml | 3 +++ kubi/src/fly_controller.rs | 2 +- kubi/src/logging.rs | 6 ++---- kubi/src/main.rs | 16 ++++++++++++++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/kubi/Cargo.toml b/kubi/Cargo.toml index ace8bc5..536897f 100644 --- a/kubi/Cargo.toml +++ b/kubi/Cargo.toml @@ -19,3 +19,6 @@ nohash-hasher = "0.2.0" anyhow = "1.0" flume = "0.10" gilrs = { version = "0.10", default_features = false, features = ["xinput"] } + +[target.'cfg(target_os = "windows")'.dependencies] +winapi = { version = "0.3" } diff --git a/kubi/src/fly_controller.rs b/kubi/src/fly_controller.rs index 2822d2a..81b5ea8 100644 --- a/kubi/src/fly_controller.rs +++ b/kubi/src/fly_controller.rs @@ -13,7 +13,7 @@ pub fn update_controllers() -> Workload { ).into_workload() } -const MAX_PITCH: f32 = PI/2. - 0.025; +const MAX_PITCH: f32 = PI/2. - 0.05; fn update_look( controllers: View, diff --git a/kubi/src/logging.rs b/kubi/src/logging.rs index c3b8be7..14d12ce 100644 --- a/kubi/src/logging.rs +++ b/kubi/src/logging.rs @@ -5,10 +5,8 @@ use log::Level; use std::io::Write; pub fn init() { - let mut env = Env::default(); - if cfg!(debug_assertions) { - env = env.filter_or("RUST_LOG", "trace,gilrs=warn,rusty_xinput=warn"); - } + let env = Env::default() + .filter_or("RUST_LOG", "trace,gilrs=warn,rusty_xinput=warn"); Builder::from_env(env) .format(|buf, record| { let mut level_style = buf.style(); diff --git a/kubi/src/main.rs b/kubi/src/main.rs index 0edfc40..e19e65d 100644 --- a/kubi/src/main.rs +++ b/kubi/src/main.rs @@ -1,5 +1,8 @@ -// allowed because systems often need a lot of arguments -#![allow(clippy::too_many_arguments)] +#![cfg_attr( + all(windows, not(debug_assertions)), + windows_subsystem = "windows" +)] +#![allow(clippy::too_many_arguments)] // allowed because systems often need a lot of arguments use shipyard::{ World, Workload, IntoWorkload, @@ -127,7 +130,16 @@ fn after_frame_end() -> Workload { ).into_workload() } +#[cfg(all(windows, not(debug_assertions)))] +fn attach_console() { + use winapi::um::wincon::{AttachConsole, ATTACH_PARENT_PROCESS}; + unsafe { AttachConsole(ATTACH_PARENT_PROCESS); } +} + fn main() { + //Attach console on release builds on windows + #[cfg(all(windows, not(debug_assertions)))] attach_console(); + //Init env_logger logging::init();