From 49599913f6a8da2ecba6ee8a24ea4f14f1461ba6 Mon Sep 17 00:00:00 2001 From: Dukantic Date: Wed, 23 Jul 2025 19:00:21 +0200 Subject: [PATCH] app name and no terminal --- .cargo/config.toml | 3 +++ Cargo.lock | 1 + Cargo.toml | 13 +++++++++---- build.rs | 6 ++++++ src/gui.rs | 6 +++--- src/main.rs | 26 +++++++++++++++++++++----- 6 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..70d66eb --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,3 @@ +[target.x86_64-pc-windows-gnu] +rustflags = ["-C", "link-args=-mwindows"] + diff --git a/Cargo.lock b/Cargo.lock index 48e2c39..1005201 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2845,6 +2845,7 @@ dependencies = [ "serde_json", "smol_str 0.3.2", "tokio", + "winapi", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 1d9f333..bcaa113 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,13 @@ regex = "1.11.1" iced_aw = {version = "0.12.2", default-features = true} iced_fonts = "0.2.1" smol_str = "0.3.2" +winapi = {version = "0.3", features = ["wincon", "winuser"]} + [profile.release] -opt-level = 3 # optimisation maximale (0 à 3) -lto = true # Link Time Optimization, optimise le binaire final -codegen-units = 1 # pour meilleure optimisation (par défaut c'est plus pour vitesse de compilation) -panic = 'abort' # pour binaire plus petit et rapide, abandonne unwind +opt-level = 3 +lto = true +codegen-units = 1 +panic = 'abort' + + + diff --git a/build.rs b/build.rs index 2269bf5..3b27d68 100644 --- a/build.rs +++ b/build.rs @@ -22,6 +22,12 @@ fn main() { let _ = fs::remove_dir_all(target_dir.join("fonts")); fs::create_dir_all(target_dir.join("fonts")).unwrap(); copy_dir("fonts", target_dir.join("fonts")); + #[cfg(windows)] + { + let mut res = winres::WindowsResource::new(); + res.set("SubSystem", "Windows"); + res.compile().unwrap(); + } } fn copy_dir(src: impl AsRef, dst: impl AsRef) { diff --git a/src/gui.rs b/src/gui.rs index f0d9c03..ca3286b 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -15,9 +15,9 @@ use iced_aw::widget::menu::Menu; use std::f32::consts::PI; -use crate::MyApp; +use crate::Polymusic; -pub fn music_view(app: &MyApp) -> iced::Element { +pub fn music_view(app: &Polymusic) -> iced::Element { let mut i = 0; let entries = app.all_sounds.clone(); //Create all polygon options @@ -203,7 +203,7 @@ pub fn music_view(app: &MyApp) -> iced::Element { .into() } -pub fn load_file_view(app: &MyApp) -> iced::Element { +pub fn load_file_view(app: &Polymusic) -> iced::Element { Container::new( column![ text("Polymusic").size(42), diff --git a/src/main.rs b/src/main.rs index 70ae8bd..84020b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,17 +54,19 @@ fn main() -> iced::Result { }, ) }; - iced::application("My App", MyApp::update, MyApp::view) + #[cfg(windows)] + hide_console_window(); + iced::application("Polymusic", Polymusic::update, Polymusic::view) .theme(move |_| polytheme.clone()) .font(iced_fonts::REQUIRED_FONT_BYTES) .font(FONT_BYTES) .default_font(FONT) .antialiasing(true) - .subscription(MyApp::subscription) - .run_with(MyApp::new) + .subscription(Polymusic::subscription) + .run_with(Polymusic::new) } -struct MyApp { +struct Polymusic { music: Music, time_last_frame: Instant, paused: bool, @@ -82,7 +84,7 @@ struct MyApp { historic: Historic, } -impl MyApp { +impl Polymusic { fn new() -> (Self, Task) { let manager = AudioManager::::new(AudioManagerSettings::default()) .expect("Error to load AudioManager"); @@ -474,3 +476,17 @@ fn load_path_saves() -> Vec { saves.sort(); saves } +#[cfg(windows)] +fn hide_console_window() { + use std::ptr; + use winapi::um::wincon::GetConsoleWindow; + use winapi::um::winuser::{SW_HIDE, ShowWindow}; + + let window = unsafe { GetConsoleWindow() }; + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow + if window != ptr::null_mut() { + unsafe { + ShowWindow(window, SW_HIDE); + } + } +}