Reduce churn in window behavior

This commit is contained in:
Jonathan Kelley 2024-03-18 22:38:33 -07:00
parent d442dac168
commit 4bb807a3ce
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
4 changed files with 11 additions and 11 deletions

View file

@ -8,12 +8,12 @@
use dioxus::desktop::tao::event::Event as WryEvent; use dioxus::desktop::tao::event::Event as WryEvent;
use dioxus::desktop::tao::event::WindowEvent; use dioxus::desktop::tao::event::WindowEvent;
use dioxus::desktop::use_wry_event_handler; use dioxus::desktop::use_wry_event_handler;
use dioxus::desktop::{Config, WindowCloseBehavior}; use dioxus::desktop::{Config, WindowCloseBehaviour};
use dioxus::prelude::*; use dioxus::prelude::*;
fn main() { fn main() {
LaunchBuilder::desktop() LaunchBuilder::desktop()
.with_cfg(Config::new().with_close_behaviour(WindowCloseBehavior::CloseWindow)) .with_cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::CloseWindow))
.launch(app) .launch(app)
} }

View file

@ -1,5 +1,5 @@
use crate::{ use crate::{
config::{Config, WindowCloseBehavior}, config::{Config, WindowCloseBehaviour},
element::DesktopElement, element::DesktopElement,
event_handlers::WindowEventHandlers, event_handlers::WindowEventHandlers,
file_upload::{DesktopFileDragEvent, DesktopFileUploadForm, FileDialogRequest}, file_upload::{DesktopFileDragEvent, DesktopFileUploadForm, FileDialogRequest},
@ -33,7 +33,7 @@ pub(crate) struct App {
// Stuff we need mutable access to // Stuff we need mutable access to
pub(crate) control_flow: ControlFlow, pub(crate) control_flow: ControlFlow,
pub(crate) is_visible_before_start: bool, pub(crate) is_visible_before_start: bool,
pub(crate) window_behavior: WindowCloseBehavior, pub(crate) window_behavior: WindowCloseBehaviour,
pub(crate) webviews: HashMap<WindowId, WebviewInstance>, pub(crate) webviews: HashMap<WindowId, WebviewInstance>,
/// This single blob of state is shared between all the windows so they have access to the runtime state /// This single blob of state is shared between all the windows so they have access to the runtime state
@ -126,7 +126,7 @@ impl App {
} }
pub fn handle_close_requested(&mut self, id: WindowId) { pub fn handle_close_requested(&mut self, id: WindowId) {
use WindowCloseBehavior::*; use WindowCloseBehaviour::*;
match self.window_behavior { match self.window_behavior {
LastWindowExitsApp => { LastWindowExitsApp => {
@ -154,7 +154,7 @@ impl App {
if matches!( if matches!(
self.window_behavior, self.window_behavior,
WindowCloseBehavior::LastWindowExitsApp WindowCloseBehaviour::LastWindowExitsApp
) && self.webviews.is_empty() ) && self.webviews.is_empty()
{ {
self.control_flow = ControlFlow::Exit self.control_flow = ControlFlow::Exit

View file

@ -7,7 +7,7 @@ use crate::menubar::{default_menu_bar, DioxusMenu};
/// The behaviour of the application when the last window is closed. /// The behaviour of the application when the last window is closed.
#[derive(Copy, Clone, Eq, PartialEq)] #[derive(Copy, Clone, Eq, PartialEq)]
pub enum WindowCloseBehavior { pub enum WindowCloseBehaviour {
/// Default behaviour, closing the last window exits the app /// Default behaviour, closing the last window exits the app
LastWindowExitsApp, LastWindowExitsApp,
/// Closing the last window will not actually close it, just hide it /// Closing the last window will not actually close it, just hide it
@ -29,7 +29,7 @@ pub struct Config {
pub(crate) custom_index: Option<String>, pub(crate) custom_index: Option<String>,
pub(crate) root_name: String, pub(crate) root_name: String,
pub(crate) background_color: Option<(u8, u8, u8, u8)>, pub(crate) background_color: Option<(u8, u8, u8, u8)>,
pub(crate) last_window_close_behavior: WindowCloseBehavior, pub(crate) last_window_close_behavior: WindowCloseBehaviour,
} }
pub(crate) type WryProtocol = ( pub(crate) type WryProtocol = (
@ -60,7 +60,7 @@ impl Config {
custom_index: None, custom_index: None,
root_name: "main".to_string(), root_name: "main".to_string(),
background_color: None, background_color: None,
last_window_close_behavior: WindowCloseBehavior::LastWindowExitsApp, last_window_close_behavior: WindowCloseBehaviour::LastWindowExitsApp,
} }
} }
@ -99,7 +99,7 @@ impl Config {
} }
/// Sets the behaviour of the application when the last window is closed. /// Sets the behaviour of the application when the last window is closed.
pub fn with_close_behaviour(mut self, behaviour: WindowCloseBehavior) -> Self { pub fn with_close_behaviour(mut self, behaviour: WindowCloseBehaviour) -> Self {
self.last_window_close_behavior = behaviour; self.last_window_close_behavior = behaviour;
self self
} }

View file

@ -41,7 +41,7 @@ pub use muda;
// Public exports // Public exports
pub use assets::AssetRequest; pub use assets::AssetRequest;
pub use config::{Config, WindowCloseBehavior}; pub use config::{Config, WindowCloseBehaviour};
pub use desktop_context::{window, DesktopContext, DesktopService}; pub use desktop_context::{window, DesktopContext, DesktopService};
pub use event_handlers::WryEventHandler; pub use event_handlers::WryEventHandler;
pub use hooks::{use_asset_handler, use_global_shortcut, use_window, use_wry_event_handler}; pub use hooks::{use_asset_handler, use_global_shortcut, use_window, use_wry_event_handler};