From 521678b5d967033920f393420a0675fd586c5940 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 1 Nov 2023 18:35:17 +0100 Subject: [PATCH] Simplify another function signature --- crates/eframe/src/native/epi_integration.rs | 16 +++++----------- crates/eframe/src/native/run.rs | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index ef6ba61eb06..8bfec2c5342 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -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}; @@ -563,21 +561,17 @@ impl EpiIntegration { pub fn maybe_autosave( &mut self, app: &mut dyn epi::App, - window: Arc>, + 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>>, - ) { + 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!(); @@ -588,7 +582,7 @@ impl EpiIntegration { epi::set_value( storage, STORAGE_WINDOW_KEY, - &WindowSettings::from_display(&window.read()), + &WindowSettings::from_display(window), ); } } diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index f27efca2851..3ab6dc9c9ca 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -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(); @@ -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: @@ -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")] @@ -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: