Repository: DioxusLabs/dioxus (language: rust)

Issue:
Panic in window resume unwrap assuming a monitor exists
https://github.com/DioxusLabs/dioxus/blob/95cde596068ffb4ee356f957fa2b1fea19e426b3/packages/desktop/src/app.rs#L451

This line unwraps a None for me with the generated code from `dx init`.
I do not get a windows showing anything, but I have to `Ctrl-C` me out of there and then I get the output. With `RUST_BACKTRACE=1` I get:

```
^Cthread 'main' panicked at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-desktop-0.6.0/src/app.rs:451:52:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:74:14
   2: core::panicking::panic
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:148:5
   3: core::option::unwrap_failed
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/option.rs:2012:5
   4: core::option::Option<T>::unwrap
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/option.rs:972:21
   5: dioxus_desktop::app::App::persist_window_state
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-desktop-0.6.0/src/app.rs:451:27
   6: dioxus_desktop::app::App::handle_loop_destroyed
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-desktop-0.6.0/src/app.rs:443:9
   7: dioxus_desktop::launch::launch_virtual_dom_blocking::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-desktop-0.6.0/src/launch.rs:29:37
   8: tao::platform_impl::platform::event_loop::EventLoop<T>::run_return::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tao-0.30.0/src/platform_impl/linux/event_loop.rs:1002:17
   9: glib::main_context::<impl glib::auto::main_context::MainContext>::with_thread_default
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/glib-0.18.5/src/main_context.rs:154:12
  10: tao::platform_impl::platform::event_loop::EventLoop<T>::run_return
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tao-0.30.0/src/platform_impl/linux/event_loop.rs:932:5
  11: tao::platform_impl::platform::event_loop::EventLoop<T>::run
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tao-0.30.0/src/platform_impl/linux/event_loop.rs:886:21
  12: tao::event_loop::EventLoop<T>::run
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tao-0.30.0/src/event_loop.rs:211:5
  13: dioxus_desktop::launch::launch_virtual_dom_blocking
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-desktop-0.6.0/src/launch.rs:19:5
  14: dioxus_desktop::launch::launch_virtual_dom::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-desktop-0.6.0/src/launch.rs:123:17
  15: <tokio::task::unconstrained::Unconstrained<F> as core::future::future::Future>::poll::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/task/unconstrained.rs:25:57
  16: tokio::runtime::coop::with_budget
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/coop.rs:107:5
  17: tokio::runtime::coop::with_unconstrained
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/coop.rs:80:5
  18: <tokio::task::unconstrained::Unconstrained<F> as core::future::future::Future>::poll
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/task/unconstrained.rs:25:13
  19: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/park.rs:281:63
  20: tokio::runtime::coop::with_budget
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/coop.rs:107:5
  21: tokio::runtime::coop::budget
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/coop.rs:73:5
  22: tokio::runtime::park::CachedParkThread::block_on
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/park.rs:281:31
  23: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/context/blocking.rs:66:9
  24: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  25: tokio::runtime::context::runtime::enter_runtime
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/context/runtime.rs:65:16
  26: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  27: tokio::runtime::runtime::Runtime::block_on_inner
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/runtime.rs:370:45
  28: tokio::runtime::runtime::Runtime::block_on
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/runtime.rs:342:13
  29: dioxus_desktop::launch::launch_virtual_dom
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-desktop-0.6.0/src/launch.rs:118:9
  30: dioxus_desktop::launch::launch
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-desktop-0.6.0/src/launch.rs:152:5
  31: dioxus::launch::LaunchBuilder::desktop::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-0.6.0/src/launch.rs:66:46
  32: core::ops::function::FnOnce::call_once
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/ops/function.rs:250:5
  33: dioxus::launch::LaunchBuilder::launch_inner
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-0.6.0/src/launch.rs:181:9
  34: dioxus::launch::LaunchBuilder::launch
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dioxus-0.6.0/src/launch.rs:186:9
  35: mailrs::main
             at ./src/main.rs:22:5
  36: core::ops::function::FnOnce::call_once
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```


Discussion / hints:

Fix patch:
diff --git a/packages/cli/src/serve/handle.rs b/packages/cli/src/serve/handle.rs
index fa3aa33dfe..84e670b503 100644
--- a/packages/cli/src/serve/handle.rs
+++ b/packages/cli/src/serve/handle.rs
@@ -176,8 +176,6 @@ impl AppHandle {
     ///
     /// Also wipes away the entropy executables if they exist.
     pub(crate) async fn cleanup(&mut self) {
-        tracing::debug!("Cleaning up process");
-
         // Soft-kill the process by sending a sigkill, allowing the process to clean up
         self.soft_kill().await;
 
diff --git a/packages/desktop/src/app.rs b/packages/desktop/src/app.rs
index a23672793d..442199a355 100644
--- a/packages/desktop/src/app.rs
+++ b/packages/desktop/src/app.rs
@@ -233,23 +233,25 @@ impl App {
         if let Some(webview) = self.webviews.get(&id) {
             use wry::Rect;
 
-            webview
-                .desktop_context
-                .webview
-                .set_bounds(Rect {
-                    position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)),
-                    size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new(
-                        size.width,
-                        size.height,
-                    )),
-                })
-                .unwrap();
+            _ = webview.desktop_context.webview.set_bounds(Rect {
+                position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)),
+                size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new(
+                    size.width,
+                    size.height,
+                )),
+            });
         }
     }
 
     pub fn handle_start_cause_init(&mut self) {
-        let virtual_dom = self.unmounted_dom.take().unwrap();
-        let mut cfg = self.cfg.take().unwrap();
+        let virtual_dom = self
+            .unmounted_dom
+            .take()
+            .expect("Virtualdom should be set before initialization");
+        let mut cfg = self
+            .cfg
+            .take()
+            .expect("Config should be set before initialization");
 
         self.is_visible_before_start = cfg.window.window.visible;
         cfg.window = cfg.window.with_visible(false);
@@ -268,9 +270,10 @@ impl App {
     pub fn handle_browser_open(&mut self, msg: IpcMessage) {
         if let Some(temp) = msg.params().as_object() {
             if temp.contains_key("href") {
-                let open = webbrowser::open(temp["href"].as_str().unwrap());
-                if let Err(e) = open {
-                    tracing::error!("Open Browser error: {:?}", e);
+                if let Some(href) = temp.get("href").and_then(|v| v.as_str()) {
+                    if let Err(e) = webbrowser::open(href) {
+                        tracing::error!("Open Browser error: {:?}", e);
+                    }
                 }
             }
         }
@@ -362,7 +365,9 @@ impl App {
 
         let data = Rc::new(PlatformEventData::new(as_any));
 
-        let view = self.webviews.get_mut(&window).unwrap();
+        let Some(view) = self.webviews.get_mut(&window) else {
+            return;
+        };
 
         let event = dioxus_core::Event::new(data as Rc<dyn Any>, event_bubbles);
 
@@ -452,8 +457,14 @@ impl App {
         if let Some(webview) = self.webviews.values().next() {
             let window = &webview.desktop_context.window;
 
-            let monitor = window.current_monitor().unwrap();
-            let position = window.outer_position().unwrap();
+            let Some(monitor) = window.current_monitor() else {
+                return;
+            };
+
+            let Ok(position) = window.outer_position() else {
+                return;
+            };
+
             let size = window.outer_size();
 
             let x = position.x;
@@ -468,12 +479,16 @@ impl App {
                 _ => 0,
             };
 
+            let Some(monitor_name) = monitor.name() else {
+                return;
+            };
+
             let state = PreservedWindowState {
                 x,
                 y,
                 width: size.width.max(200),
                 height: size.height.saturating_sub(adjustment).max(200),
-                monitor: monitor.name().unwrap().to_string(),
+                monitor: monitor_name.to_string(),
             };
 
             // Yes... I know... we're loading a file that might not be ours... but it's a debug feature


Test patch: