Skip to content

Commit

Permalink
Revert window::close producing a window::Id
Browse files Browse the repository at this point in the history
Instead, subscribing to `window::close_events` is
preferable; since most use cases will want to react
to the user closing a window as well.
  • Loading branch information
hecrj committed Aug 12, 2024
1 parent 22fc5ce commit 8b45d62
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
6 changes: 2 additions & 4 deletions examples/events/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Events {
}
Message::EventOccurred(event) => {
if let Event::Window(window::Event::CloseRequested) = event {
window::get_latest().and_then(window::close).discard()
window::get_latest().and_then(window::close)
} else {
Task::none()
}
Expand All @@ -47,9 +47,7 @@ impl Events {

Task::none()
}
Message::Exit => {
window::get_latest().and_then(window::close).discard()
}
Message::Exit => window::get_latest().and_then(window::close),
}
}

Expand Down
4 changes: 1 addition & 3 deletions examples/exit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ enum Message {
impl Exit {
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Confirm => {
window::get_latest().and_then(window::close).discard()
}
Message::Confirm => window::get_latest().and_then(window::close),
Message::Exit => {
self.show_confirm = true;

Expand Down
6 changes: 3 additions & 3 deletions runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum Action {
Open(Id, Settings, oneshot::Sender<Id>),

/// Close the window and exits the application.
Close(Id, oneshot::Sender<Id>),
Close(Id),

/// Gets the [`Id`] of the oldest window.
GetOldest(oneshot::Sender<Option<Id>>),
Expand Down Expand Up @@ -230,8 +230,8 @@ pub fn open(settings: Settings) -> (Id, Task<Id>) {
}

/// Closes the window with `id`.
pub fn close(id: Id) -> Task<Id> {
task::oneshot(|channel| crate::Action::Window(Action::Close(id, channel)))
pub fn close<T>(id: Id) -> Task<T> {
task::effect(crate::Action::Window(Action::Close(id)))
}

/// Gets the window [`Id`] of the oldest window.
Expand Down
3 changes: 1 addition & 2 deletions winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,10 +1211,9 @@ fn run_action<P, C>(

*is_window_opening = true;
}
window::Action::Close(id, channel) => {
window::Action::Close(id) => {
let _ = window_manager.remove(id);
let _ = ui_caches.remove(&id);
let _ = channel.send(id);

events.push((
id,
Expand Down

0 comments on commit 8b45d62

Please sign in to comment.