Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dont unwrap as much in desktop #3609

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/cli/src/serve/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
55 changes: 35 additions & 20 deletions packages/desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
Loading