From 76ff6cac5bb921ea13f8fbc4cd8f10216e41194d Mon Sep 17 00:00:00 2001 From: Vladimir Borisov Date: Wed, 17 Nov 2021 11:24:25 +0200 Subject: [PATCH] Better way to hide the terminal --- src/main.rs | 11 +---------- src/stremio_app/stremio_server/server.rs | 4 ++++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index f52cc35..97655d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,8 @@ +#![windows_subsystem = "windows"] #[macro_use] extern crate bitflags; use native_windows_gui::{self as nwg, NativeUi}; use structopt::StructOpt; -use winapi::um::wincon::GetConsoleWindow; -use winapi::um::winuser::{ShowWindow, SW_HIDE}; mod stremio_app; use crate::stremio_app::{stremio_server::StremioServer, MainWindow}; @@ -24,14 +23,6 @@ struct Opt { } fn main() { - // Hide the terminal window - let window = unsafe { GetConsoleWindow() }; - if !window.is_null() { - unsafe { - ShowWindow(window, SW_HIDE); - } - } - // native-windows-gui has some basic high DPI support with the high-dpi // feature. It supports the "System DPI Awareness" mode, but not the more // advanced Per-Monitor (v2) DPI Awareness modes. diff --git a/src/stremio_app/stremio_server/server.rs b/src/stremio_app/stremio_server/server.rs index 37d30df..bb84d66 100644 --- a/src/stremio_app/stremio_server/server.rs +++ b/src/stremio_app/stremio_server/server.rs @@ -2,6 +2,9 @@ use std::process::Command; use std::thread; use std::time::Duration; use win32job::Job; +use std::os::windows::process::CommandExt; + +const CREATE_NO_WINDOW: u32 = 0x08000000; pub struct StremioServer {} @@ -16,6 +19,7 @@ impl StremioServer { loop { let mut child = Command::new("node") .arg("server.js") + .creation_flags(CREATE_NO_WINDOW) .spawn() .expect("Cannot run the server"); child.wait().expect("Cannot wait for the server");