From 4890d75012f4a2169d146fd26af395103b18e03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 16 May 2024 13:47:02 +0200 Subject: [PATCH] Initialize `Application::name` in multi-window runtime --- debug/src/lib.rs | 2 ++ src/multi_window.rs | 9 +++++++++ src/program.rs | 4 +--- winit/src/multi_window.rs | 6 +++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/debug/src/lib.rs b/debug/src/lib.rs index f89d97e5..f33b23b6 100644 --- a/debug/src/lib.rs +++ b/debug/src/lib.rs @@ -78,6 +78,8 @@ mod internal { use std::sync::RwLock; pub fn init(name: &str) { + let name = name.split("::").next().unwrap_or(name); + name.clone_into(&mut NAME.write().expect("Write application name")); } diff --git a/src/multi_window.rs b/src/multi_window.rs index b81297dc..2320911e 100644 --- a/src/multi_window.rs +++ b/src/multi_window.rs @@ -84,6 +84,11 @@ where /// The data needed to initialize your [`Application`]. type Flags; + /// Returns the unique name of the [`Application`]. + fn name() -> &'static str { + std::any::type_name::() + } + /// Initializes the [`Application`] with the flags provided to /// [`run`] as part of the [`Settings`]. /// @@ -232,6 +237,10 @@ where (Instance(app), command) } + fn name() -> &'static str { + A::name() + } + fn title(&self, window: window::Id) -> String { self.0.title(window) } diff --git a/src/program.rs b/src/program.rs index 70d3bd51..7c7b0d37 100644 --- a/src/program.rs +++ b/src/program.rs @@ -107,9 +107,7 @@ where type Executor = executor::Default; fn name() -> &'static str { - let type_name = std::any::type_name::(); - - type_name.split("::").next().unwrap_or(type_name) + std::any::type_name::() } fn load(&self) -> Command { diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index d803a8d4..a05a94d9 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -51,6 +51,9 @@ where /// The data needed to initialize your [`Application`]. type Flags; + /// Returns the unique name of the [`Application`]. + fn name() -> &'static str; + /// Initializes the [`Application`] with the flags provided to /// [`run`] as part of the [`Settings`]. /// @@ -117,6 +120,7 @@ where { use winit::event_loop::EventLoop; + debug::init(A::name()); let boot_span = debug::boot(); let event_loop = EventLoop::with_user_event() @@ -989,7 +993,6 @@ fn update( for message in messages.drain(..) { let update_span = debug::update(&message); let command = runtime.enter(|| application.update(message)); - update_span.finish(); run_command( application, @@ -1002,6 +1005,7 @@ fn update( window_manager, ui_caches, ); + update_span.finish(); } let recipes = application.subscription().into_recipes();