Skip to content

Commit 4cd9a84

Browse files
committed
fix: dont unwrap as much in desktop
1 parent 4342ca9 commit 4cd9a84

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

packages/cli/src/serve/handle.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ impl AppHandle {
176176
///
177177
/// Also wipes away the entropy executables if they exist.
178178
pub(crate) async fn cleanup(&mut self) {
179-
tracing::debug!("Cleaning up process");
180-
181179
// Soft-kill the process by sending a sigkill, allowing the process to clean up
182180
self.soft_kill().await;
183181

packages/desktop/src/app.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -233,23 +233,25 @@ impl App {
233233
if let Some(webview) = self.webviews.get(&id) {
234234
use wry::Rect;
235235

236-
webview
237-
.desktop_context
238-
.webview
239-
.set_bounds(Rect {
240-
position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)),
241-
size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new(
242-
size.width,
243-
size.height,
244-
)),
245-
})
246-
.unwrap();
236+
_ = webview.desktop_context.webview.set_bounds(Rect {
237+
position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)),
238+
size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new(
239+
size.width,
240+
size.height,
241+
)),
242+
});
247243
}
248244
}
249245

250246
pub fn handle_start_cause_init(&mut self) {
251-
let virtual_dom = self.unmounted_dom.take().unwrap();
252-
let mut cfg = self.cfg.take().unwrap();
247+
let virtual_dom = self
248+
.unmounted_dom
249+
.take()
250+
.expect("Virtualdom should be set before initialization");
251+
let mut cfg = self
252+
.cfg
253+
.take()
254+
.expect("Config should be set before initialization");
253255

254256
self.is_visible_before_start = cfg.window.window.visible;
255257
cfg.window = cfg.window.with_visible(false);
@@ -268,9 +270,10 @@ impl App {
268270
pub fn handle_browser_open(&mut self, msg: IpcMessage) {
269271
if let Some(temp) = msg.params().as_object() {
270272
if temp.contains_key("href") {
271-
let open = webbrowser::open(temp["href"].as_str().unwrap());
272-
if let Err(e) = open {
273-
tracing::error!("Open Browser error: {:?}", e);
273+
if let Some(href) = temp.get("href").and_then(|v| v.as_str()) {
274+
if let Err(e) = webbrowser::open(href) {
275+
tracing::error!("Open Browser error: {:?}", e);
276+
}
274277
}
275278
}
276279
}
@@ -362,7 +365,9 @@ impl App {
362365

363366
let data = Rc::new(PlatformEventData::new(as_any));
364367

365-
let view = self.webviews.get_mut(&window).unwrap();
368+
let Some(view) = self.webviews.get_mut(&window) else {
369+
return;
370+
};
366371

367372
let event = dioxus_core::Event::new(data as Rc<dyn Any>, event_bubbles);
368373

@@ -452,8 +457,14 @@ impl App {
452457
if let Some(webview) = self.webviews.values().next() {
453458
let window = &webview.desktop_context.window;
454459

455-
let monitor = window.current_monitor().unwrap();
456-
let position = window.outer_position().unwrap();
460+
let Some(monitor) = window.current_monitor() else {
461+
return;
462+
};
463+
464+
let Ok(position) = window.outer_position() else {
465+
return;
466+
};
467+
457468
let size = window.outer_size();
458469

459470
let x = position.x;
@@ -468,12 +479,16 @@ impl App {
468479
_ => 0,
469480
};
470481

482+
let Some(monitor_name) = monitor.name() else {
483+
return;
484+
};
485+
471486
let state = PreservedWindowState {
472487
x,
473488
y,
474489
width: size.width.max(200),
475490
height: size.height.saturating_sub(adjustment).max(200),
476-
monitor: monitor.name().unwrap().to_string(),
491+
monitor: monitor_name.to_string(),
477492
};
478493

479494
// Yes... I know... we're loading a file that might not be ours... but it's a debug feature

0 commit comments

Comments
 (0)