diff --git a/src/bin/layers_shell.rs b/src/bin/layers_shell.rs index 8c04c63..15c4184 100644 --- a/src/bin/layers_shell.rs +++ b/src/bin/layers_shell.rs @@ -16,13 +16,15 @@ const DEFAULT_LOGICAL_SIZE: (u32, u32) = (480, 640); const MIN_LOGICAL_SIZE: (u32, u32) = (380, 220); fn main() { - init_logging(); let plugin_root = discover_plugin_root(); - if let Some(root) = plugin_root.as_deref() { - layers::ui::colors::init(Some(root)); - } else { - layers::ui::colors::init(None); + if let Err(e) = layers::ffi::init_native_shell(plugin_root.as_deref()) { + eprintln!("layers: init_native_shell failed: {e}"); + std::process::exit(2); } + tracing::info!( + plugin_root = ?plugin_root, + "layers shell: starting native event loop", + ); if let Err(e) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(run)) { tracing::error!("layers shell panicked: {e:?}"); @@ -55,6 +57,7 @@ impl ApplicationHandler for ShellApp { if self.window.is_some() { return; } + tracing::info!("resumed: creating window"); let colors = layers::ui::colors::get(); let attrs = WindowAttributes::default() .with_title("Layers") @@ -83,14 +86,27 @@ impl ApplicationHandler for ShellApp { .expect("winit: display handle") .as_raw(); - let handle = ViewportHandle::new_from_raw( + tracing::info!( + "creating viewport handle: {}x{} @ {}", + inner.width, + inner.height, + scale + ); + let handle = match ViewportHandle::new_from_raw( raw_window, raw_display, (inner.width as f32 / scale).max(1.0), (inner.height as f32 / scale).max(1.0), scale, - ) - .expect("layers: create viewport handle"); + ) { + Some(h) => h, + None => { + tracing::error!("new_from_raw returned None — wgpu surface failed"); + event_loop.exit(); + return; + } + }; + tracing::info!("viewport handle ready"); self.window = Some(window); self.handle = Some(handle); @@ -239,15 +255,6 @@ fn encode_modifiers(mods: ModifiersState) -> u32 { bits } -fn init_logging() { - use tracing_subscriber::EnvFilter; - let _ = tracing_subscriber::fmt() - .with_env_filter( - EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info,layers=info")), - ) - .try_init(); -} - #[cfg(target_os = "windows")] fn apply_win11_chrome(raw_window: &raw_window_handle::RawWindowHandle) { use raw_window_handle::RawWindowHandle; diff --git a/src/ffi.rs b/src/ffi.rs index ae8ab31..6da16fc 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -663,6 +663,16 @@ fn dump_invocation_context() { } } +/// Native-shell setup used by non-FFI entry points (winit binary on Windows / Linux). +/// Creates log + state dirs, initialises file-based tracing, preloads colours. +pub fn init_native_shell(plugin_root: Option<&std::path::Path>) -> anyhow::Result<()> { + paths::create_dirs_if_missing()?; + let _ = init_logging(); + dump_invocation_context(); + crate::ui::colors::init(plugin_root); + Ok(()) +} + #[cfg(feature = "debug")] fn init_logging() -> anyhow::Result<()> { use tracing_subscriber::{fmt, prelude::*, EnvFilter};