diff --git a/dialog-gtk3/src/main.rs b/dialog-gtk3/src/main.rs index e266113..2c83d60 100644 --- a/dialog-gtk3/src/main.rs +++ b/dialog-gtk3/src/main.rs @@ -4,7 +4,7 @@ use gethostname::gethostname; use glib::{GString, clone, SourceId}; use gtk::{prelude::*, Button, Entry, Label, Plug, Window}; use log::{debug, error, warn}; -use std::{io::{self, Write}, process::exit, rc::Rc, thread, time::Duration}; +use std::{io::{self, Write}, process::exit, thread, time::Duration}; use bscreensaver_util::{init_logging, settings::Configuration, desktop::NewLoginCommand}; @@ -296,36 +296,30 @@ fn main() -> anyhow::Result<()> { unlock_button.set_can_default(true); unlock_button.set_has_default(true); - let timer = Rc::new(gtk::ProgressBar::builder() + let timer = gtk::ProgressBar::builder() .orientation(gtk::Orientation::Horizontal) .fraction(1.0) .show_text(false) .can_focus(false) .margin(2) - .build()); - top_vbox.pack_end(&*timer, false, false, 0); + .build(); + top_vbox.pack_end(&timer, false, false, 0); - { - let timer = Rc::clone(&timer); - let delta = (DIALOG_UPDATE_INTERVAL.as_millis() as f64) / (DIALOG_TIMEOUT.as_millis() as f64); - glib::timeout_add_local(DIALOG_UPDATE_INTERVAL, move || { - let new_fraction = timer.fraction() - delta; - if new_fraction <= 0.0 { - exit(1); - } - timer.set_fraction(new_fraction); - Continue(true) - }); - } + let delta = (DIALOG_UPDATE_INTERVAL.as_millis() as f64) / (DIALOG_TIMEOUT.as_millis() as f64); + glib::timeout_add_local(DIALOG_UPDATE_INTERVAL, clone!(@strong timer => move || { + let new_fraction = timer.fraction() - delta; + if new_fraction <= 0.0 { + exit(1); + } + timer.set_fraction(new_fraction); + Continue(true) + })); - { - let timer = Rc::clone(&timer); - password_box.connect_key_press_event(move |_, _| { - let new_fraction = timer.fraction() + 0.05; - timer.set_fraction(if new_fraction >= 1.0 { 1.0 } else { new_fraction }); - Inhibit(false) - }); - } + password_box.connect_key_press_event(clone!(@strong timer => move |_, _| { + let new_fraction = timer.fraction() + 0.05; + timer.set_fraction(if new_fraction >= 1.0 { 1.0 } else { new_fraction }); + Inhibit(false) + })); dialog.show_all();