mirror of
https://github.com/Xevion/rust-sdl2-emscripten.git
synced 2025-12-06 01:16:14 -06:00
Add console window hiding for Windows
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,5 +2,7 @@
|
||||
/dist
|
||||
.idea
|
||||
*.dll
|
||||
*.lib
|
||||
*.exe
|
||||
node_modules
|
||||
assets/build.css
|
||||
22
Cargo.lock
generated
22
Cargo.lock
generated
@@ -11,6 +11,17 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
@@ -46,6 +57,15 @@ dependencies = [
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
@@ -105,6 +125,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
||||
name = "pacman"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"colors-transform",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
@@ -114,6 +135,7 @@ dependencies = [
|
||||
"tracing",
|
||||
"tracing-error",
|
||||
"tracing-subscriber",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -15,5 +15,9 @@ tracing = { version = "0.1.37", features = ["max_level_debug", "release_max_leve
|
||||
tracing-error = "0.2.0"
|
||||
tracing-subscriber = {version = "0.3.17", features = ["env-filter"]}
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
atty = "0.2"
|
||||
winapi = {version = "0.3", features = ["wincon", "winuser"]}
|
||||
|
||||
[target.'cfg(target_os = "emscripten")'.dependencies]
|
||||
libc = "0.2.16"
|
||||
28
src/main.rs
28
src/main.rs
@@ -1,3 +1,4 @@
|
||||
// #![windows_subsystem = "windows"]
|
||||
use std::process;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -55,21 +56,34 @@ fn ttf_context() -> &'static ttf::Sdl2TtfContext {
|
||||
Box::leak(Box::new(ttf::init().unwrap()))
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn hide_console_window() {}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn hide_console_window() {
|
||||
if !atty::is(atty::Stream::Stdout) {
|
||||
unsafe { winapi::um::wincon::FreeConsole() };
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
hide_console_window();
|
||||
|
||||
let ctx = sdl2::init().unwrap();
|
||||
let video_ctx = ctx.video().unwrap();
|
||||
|
||||
|
||||
let window = match video_ctx
|
||||
.window("rust-sdl2-emscripten", 640, 480)
|
||||
.position_centered()
|
||||
.resizable()
|
||||
.allow_highdpi()
|
||||
.opengl()
|
||||
.build()
|
||||
.window("rust-sdl2-emscripten", 640, 480)
|
||||
.position_centered()
|
||||
.resizable()
|
||||
.allow_highdpi()
|
||||
.opengl()
|
||||
.build()
|
||||
{
|
||||
Ok(window) => window,
|
||||
Err(err) => panic!("failed to create window: {}", err),
|
||||
};
|
||||
|
||||
|
||||
let mut canvas = match window.into_canvas().accelerated().build() {
|
||||
Ok(canvas) => canvas,
|
||||
|
||||
Reference in New Issue
Block a user