Browse Source

Reduce churn in window behavior

Jonathan Kelley 1 năm trước cách đây
mục cha
commit
4bb807a3ce

+ 2 - 2
examples/window_focus.rs

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

+ 4 - 4
packages/desktop/src/app.rs

@@ -1,5 +1,5 @@
 use crate::{
-    config::{Config, WindowCloseBehavior},
+    config::{Config, WindowCloseBehaviour},
     element::DesktopElement,
     event_handlers::WindowEventHandlers,
     file_upload::{DesktopFileDragEvent, DesktopFileUploadForm, FileDialogRequest},
@@ -33,7 +33,7 @@ pub(crate) struct App {
     // Stuff we need mutable access to
     pub(crate) control_flow: ControlFlow,
     pub(crate) is_visible_before_start: bool,
-    pub(crate) window_behavior: WindowCloseBehavior,
+    pub(crate) window_behavior: WindowCloseBehaviour,
     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
@@ -126,7 +126,7 @@ impl App {
     }
 
     pub fn handle_close_requested(&mut self, id: WindowId) {
-        use WindowCloseBehavior::*;
+        use WindowCloseBehaviour::*;
 
         match self.window_behavior {
             LastWindowExitsApp => {
@@ -154,7 +154,7 @@ impl App {
 
         if matches!(
             self.window_behavior,
-            WindowCloseBehavior::LastWindowExitsApp
+            WindowCloseBehaviour::LastWindowExitsApp
         ) && self.webviews.is_empty()
         {
             self.control_flow = ControlFlow::Exit

+ 4 - 4
packages/desktop/src/config.rs

@@ -7,7 +7,7 @@ use crate::menubar::{default_menu_bar, DioxusMenu};
 
 /// The behaviour of the application when the last window is closed.
 #[derive(Copy, Clone, Eq, PartialEq)]
-pub enum WindowCloseBehavior {
+pub enum WindowCloseBehaviour {
     /// Default behaviour, closing the last window exits the app
     LastWindowExitsApp,
     /// 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) root_name: String,
     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 = (
@@ -60,7 +60,7 @@ impl Config {
             custom_index: None,
             root_name: "main".to_string(),
             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.
-    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
     }

+ 1 - 1
packages/desktop/src/lib.rs

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