fix: dont unwrap as much in desktop (#3609)

This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-01-21 00:13:05 -08:00
1 parent 4342ca92a3
commit 439e3e7723
2 files changed
+35 -22

No files matched your search

-2
View File
@@ -176,8 +176,6 @@ impl AppHandle {
/// ///
/// Also wipes away the entropy executables if they exist. /// Also wipes away the entropy executables if they exist.
pub(crate) async fn cleanup(&mut self) { 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 // Soft-kill the process by sending a sigkill, allowing the process to clean up
self.soft_kill().await; self.soft_kill().await;
+35 -20
View File
@@ -233,23 +233,25 @@ impl App {
if let Some(webview) = self.webviews.get(&id) { if let Some(webview) = self.webviews.get(&id) {
use wry::Rect; use wry::Rect;
webview _ = webview.desktop_context.webview.set_bounds(Rect {
.desktop_context position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)),
.webview size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new(
.set_bounds(Rect { size.width,
position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)), size.height,
size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new( )),
size.width, });
size.height,
)),
})
.unwrap();
} }
} }
pub fn handle_start_cause_init(&mut self) { pub fn handle_start_cause_init(&mut self) {
let virtual_dom = self.unmounted_dom.take().unwrap(); let virtual_dom = self
let mut cfg = self.cfg.take().unwrap(); .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; self.is_visible_before_start = cfg.window.window.visible;
cfg.window = cfg.window.with_visible(false); cfg.window = cfg.window.with_visible(false);
@@ -268,9 +270,10 @@ impl App {
pub fn handle_browser_open(&mut self, msg: IpcMessage) { pub fn handle_browser_open(&mut self, msg: IpcMessage) {
if let Some(temp) = msg.params().as_object() { if let Some(temp) = msg.params().as_object() {
if temp.contains_key("href") { if temp.contains_key("href") {
let open = webbrowser::open(temp["href"].as_str().unwrap()); if let Some(href) = temp.get("href").and_then(|v| v.as_str()) {
if let Err(e) = open { if let Err(e) = webbrowser::open(href) {
tracing::error!("Open Browser error: {:?}", e); tracing::error!("Open Browser error: {:?}", e);
}
} }
} }
} }
@@ -362,7 +365,9 @@ impl App {
let data = Rc::new(PlatformEventData::new(as_any)); 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); 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() { if let Some(webview) = self.webviews.values().next() {
let window = &webview.desktop_context.window; let window = &webview.desktop_context.window;
let monitor = window.current_monitor().unwrap(); let Some(monitor) = window.current_monitor() else {
let position = window.outer_position().unwrap(); return;
};
let Ok(position) = window.outer_position() else {
return;
};
let size = window.outer_size(); let size = window.outer_size();
let x = position.x; let x = position.x;
@@ -468,12 +479,16 @@ impl App {
_ => 0, _ => 0,
}; };
let Some(monitor_name) = monitor.name() else {
return;
};
let state = PreservedWindowState { let state = PreservedWindowState {
x, x,
y, y,
width: size.width.max(200), width: size.width.max(200),
height: size.height.saturating_sub(adjustment).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 // Yes... I know... we're loading a file that might not be ours... but it's a debug feature