Winit update: fix suspend on Android (#11403)

# Objective

- Android still plays audio when suspended

## Solution

- When status is `WillSuspend`, trigger an update without requesting a
redraw
This commit is contained in:
François 2024-01-19 07:26:34 +01:00 committed by GitHub
parent a00c71ee5b
commit f795656d65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -407,11 +407,16 @@ pub fn winit_runner(mut app: App) {
should_update = true; should_update = true;
} }
// Trigger one last update to enter suspended state
if runner_state.active == ActiveState::WillSuspend {
should_update = true;
}
if should_update { if should_update {
let visible = windows.iter().any(|window| window.visible); let visible = windows.iter().any(|window| window.visible);
let (_, winit_windows, _, _) = let (_, winit_windows, _, _) =
event_writer_system_state.get_mut(&mut app.world); event_writer_system_state.get_mut(&mut app.world);
if visible { if visible && runner_state.active != ActiveState::WillSuspend {
for window in winit_windows.windows.values() { for window in winit_windows.windows.values() {
window.request_redraw(); window.request_redraw();
} }
@ -427,10 +432,12 @@ pub fn winit_runner(mut app: App) {
&mut app_exit_event_reader, &mut app_exit_event_reader,
&mut redraw_event_reader, &mut redraw_event_reader,
); );
if runner_state.active != ActiveState::Suspended {
event_loop.set_control_flow(ControlFlow::Poll); event_loop.set_control_flow(ControlFlow::Poll);
} }
} }
} }
}
Event::NewEvents(_) => { Event::NewEvents(_) => {
if let Some(t) = runner_state.scheduled_update { if let Some(t) = runner_state.scheduled_update {
let now = Instant::now(); let now = Instant::now();