Skip to content

Commit

Permalink
Simplify another function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 1, 2023
1 parent f6c5e71 commit 521678b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
16 changes: 5 additions & 11 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use winit::event_loop::EventLoopWindowTarget;

use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _};

use egui::{
mutex::RwLock, NumExt as _, ViewportBuilder, ViewportId, ViewportIdPair, ViewportRender,
};
use egui::{NumExt as _, ViewportBuilder, ViewportId, ViewportIdPair, ViewportRender};
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;
use egui_winit::{native_pixels_per_point, EventResponse, WindowSettings};
Expand Down Expand Up @@ -563,21 +561,17 @@ impl EpiIntegration {
pub fn maybe_autosave(
&mut self,
app: &mut dyn epi::App,
window: Arc<RwLock<winit::window::Window>>,
window: Option<&winit::window::Window>,
) {
let now = std::time::Instant::now();
if now - self.last_auto_save > app.auto_save_interval() {
self.save(app, Some(window));
self.save(app, window);
self.last_auto_save = now;
}
}

#[allow(clippy::unused_self)]
pub fn save(
&mut self,
_app: &mut dyn epi::App,
_window: Option<Arc<RwLock<winit::window::Window>>>,
) {
pub fn save(&mut self, _app: &mut dyn epi::App, _window: Option<&winit::window::Window>) {
#[cfg(feature = "persistence")]
if let Some(storage) = self.frame.storage_mut() {
crate::profile_function!();
Expand All @@ -588,7 +582,7 @@ impl EpiIntegration {
epi::set_value(
storage,
STORAGE_WINDOW_KEY,
&WindowSettings::from_display(&window.read()),
&WindowSettings::from_display(window),
);
}
}
Expand Down
20 changes: 12 additions & 8 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,9 @@ mod glow_integration {
.window(ViewportId::MAIN)
.read()
.window
.clone(),
.as_ref()
.map(|w| w.read())
.as_deref(),
);
running.app.write().on_exit(Some(&running.gl));
running.painter.write().destroy();
Expand Down Expand Up @@ -1566,8 +1568,10 @@ mod glow_integration {
EventResult::Wait
};

integration
.maybe_autosave(app.write().as_mut(), win.read().window.clone().unwrap());
integration.maybe_autosave(
app.write().as_mut(),
win.read().window.as_ref().map(|w| w.read()).as_deref(),
);

if win.read().window.as_ref().unwrap().read().is_minimized() == Some(true) {
// On Mac, a minimized Window uses up all CPU:
Expand Down Expand Up @@ -2271,10 +2275,10 @@ mod wgpu_integration {
crate::profile_function!();
if let Some(Window { window, .. }) = running.viewports.read().get(&ViewportId::MAIN)
{
running
.integration
.write()
.save(running.app.as_mut(), window.clone());
running.integration.write().save(
running.app.as_mut(),
window.as_ref().map(|w| w.read()).as_deref(),
);
}

#[cfg(feature = "glow")]
Expand Down Expand Up @@ -2452,7 +2456,7 @@ mod wgpu_integration {
) else{return EventResult::Wait};
integration
.write()
.maybe_autosave(app.as_mut(), window.clone());
.maybe_autosave(app.as_mut(), Some(&*window.read()));

if window.read().is_minimized() == Some(true) {
// On Mac, a minimized Window uses up all CPU:
Expand Down

0 comments on commit 521678b

Please sign in to comment.