tweaks to the LastWindowClose to make it more imperative
This commit is contained in:
1 parent
9573af115a
commit
ff762cec84
11 files changed
+74
-214
No files matched your search
@@ -10,6 +10,7 @@ use crate::{
|
||||
};
|
||||
use dioxus_core::{prelude::Callback, VirtualDom};
|
||||
use std::{
|
||||
cell::Cell,
|
||||
future::{Future, IntoFuture},
|
||||
pin::Pin,
|
||||
rc::{Rc, Weak},
|
||||
@@ -66,6 +67,7 @@ pub struct DesktopService {
|
||||
pub(super) query: QueryEngine,
|
||||
pub(crate) asset_handlers: AssetHandlerRegistry,
|
||||
pub(crate) file_hover: NativeFileHover,
|
||||
pub(crate) close_behaviour: Rc<Cell<WindowCloseBehaviour>>,
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
pub(crate) views: Rc<std::cell::RefCell<Vec<*mut objc::runtime::Object>>>,
|
||||
@@ -87,6 +89,7 @@ impl DesktopService {
|
||||
shared: Rc<SharedContext>,
|
||||
asset_handlers: AssetHandlerRegistry,
|
||||
file_hover: NativeFileHover,
|
||||
close_behaviour: WindowCloseBehaviour,
|
||||
) -> Self {
|
||||
Self {
|
||||
window,
|
||||
@@ -94,6 +97,7 @@ impl DesktopService {
|
||||
shared,
|
||||
asset_handlers,
|
||||
file_hover,
|
||||
close_behaviour: Rc::new(Cell::new(close_behaviour)),
|
||||
query: Default::default(),
|
||||
#[cfg(target_os = "ios")]
|
||||
views: Default::default(),
|
||||
@@ -165,6 +169,14 @@ impl DesktopService {
|
||||
self.window.set_maximized(!self.window.is_maximized())
|
||||
}
|
||||
|
||||
/// Set the close behavior of this window
|
||||
///
|
||||
/// By default, windows close when the user clicks the close button.
|
||||
/// If this is set to `WindowCloseBehaviour::WindowHides`, the window will hide instead of closing.
|
||||
pub fn set_close_behavior(&self, behaviour: WindowCloseBehaviour) {
|
||||
self.close_behaviour.set(behaviour);
|
||||
}
|
||||
|
||||
/// Close this window
|
||||
pub fn close(&self) {
|
||||
let _ = self
|
||||
@@ -181,26 +193,6 @@ impl DesktopService {
|
||||
.send_event(UserWindowEvent::CloseWindow(id));
|
||||
}
|
||||
|
||||
/// Change close behaviour of this window
|
||||
pub fn change_close_behaviour(&self, behaviour: Option<WindowCloseBehaviour>) {
|
||||
let _ = self
|
||||
.shared
|
||||
.proxy
|
||||
.send_event(UserWindowEvent::CloseBehaviour(self.id(), behaviour));
|
||||
}
|
||||
|
||||
/// Change close behaviour of a specific window, given its ID
|
||||
pub fn change_window_close_behaviour(
|
||||
&self,
|
||||
id: WindowId,
|
||||
behaviour: Option<WindowCloseBehaviour>,
|
||||
) {
|
||||
let _ = self
|
||||
.shared
|
||||
.proxy
|
||||
.send_event(UserWindowEvent::CloseBehaviour(id, behaviour));
|
||||
}
|
||||
|
||||
/// change window to fullscreen
|
||||
pub fn set_fullscreen(&self, fullscreen: bool) {
|
||||
if let Some(handle) = &self.window.current_monitor() {
|
||||
|
||||
Reference in new issue
Block a user