Skip to content

Commit

Permalink
rename is_active state to is_minimized
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Feb 2, 2024
1 parent fddab17 commit de175f4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions v2/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub trait Renderer {
fn window_appearance(&self) -> WindowAppearance;
fn show_menu_at(&self, position: Option<(f64, f64)>);
fn toggle_menu(&mut self) -> Result<()>;
fn set_active(&mut self, is_active: bool);
fn set_minimized(&mut self, minimized: bool);
}

/// Context to execute rendering.
Expand All @@ -199,7 +199,7 @@ pub trait Rendering: Sized {
pub trait EventHandler {
fn handle_user_event(&mut self, event: UserEvent) -> Result<RenderingFlow>;
fn handle_menu_event(&mut self, item: MenuItem) -> Result<RenderingFlow>;
fn handle_active_state(&mut self, is_active: bool);
fn handle_minimized(&mut self, is_active: bool);
fn handle_exit(&mut self) -> Result<()>;
fn handle_error(&mut self, err: Error) -> RenderingFlow;
}
Expand Down
4 changes: 2 additions & 2 deletions v2/src/shiba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ where
Ok(RenderingFlow::Continue)
}

fn handle_active_state(&mut self, is_active: bool) {
self.renderer.set_active(is_active);
fn handle_minimized(&mut self, minimized: bool) {
self.renderer.set_minimized(minimized);
}

fn handle_exit(&mut self) -> Result<()> {
Expand Down
12 changes: 6 additions & 6 deletions v2/src/wry/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Rendering for Wry {
where
H: EventHandler + 'static,
{
let mut is_active = true;
let mut is_minimized = false;
self.event_loop.run(move |event, _, control| {
let flow = match event {
Event::NewEvents(StartCause::Init) => {
Expand All @@ -88,11 +88,11 @@ impl Rendering for Wry {
handler.handle_error(err.context("Could not handle user event"))
}),
Event::WindowEvent { event: WindowEvent::Resized(size), .. } => {
let next_active = size.height > 0 && size.width > 0;
if next_active != is_active {
log::debug!("Application active state changed to {next_active}");
is_active = next_active;
handler.handle_active_state(is_active);
let next_minimized = size.height == 0 || size.width == 0;
if next_minimized != is_minimized {
is_minimized = next_minimized;
log::debug!("Minimized state changed: {is_minimized}");
handler.handle_minimized(is_minimized);
}
RenderingFlow::Continue
}
Expand Down
8 changes: 4 additions & 4 deletions v2/src/wry/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,11 @@ impl Renderer for WebViewRenderer {
}

#[cfg(target_os = "windows")]
fn set_active(&mut self, is_active: bool) {
let level = if is_active { MemoryUsageLevel::Normal } else { MemoryUsageLevel::Low };
log::debug!("Meory usage level is set to {level:?}");
fn set_minimized(&mut self, minimized: bool) {
let level = if minimized { MemoryUsageLevel::Low } else { MemoryUsageLevel::Normal };
log::debug!("Memory usage level is set to {level:?} due to minimized={minimized}");
self.webview.set_memory_usage_level(level);
}
#[cfg(not(target_os = "windows"))]
fn set_active(&mut self, _is_active: bool) {}
fn set_minimized(&mut self, _minimized: bool) {}
}

0 comments on commit de175f4

Please sign in to comment.