stop abusing strong ref

This commit is contained in:
Bilal Elmoussaoui 2020-12-06 21:26:01 +01:00
parent 650148cff1
commit eba49f569b
5 changed files with 29 additions and 13 deletions

View file

@ -15,6 +15,12 @@
<property name="accelerator">&lt;Primary&gt;question</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Lock</property>
<property name="accelerator">&lt;Primary&gt;L</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Preferences</property>
@ -44,9 +50,18 @@
<property name="accelerator">&lt;Primary&gt;F</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes" context="shortcut window">Scan QR</property>
<property name="accelerator">T</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

View file

@ -118,12 +118,12 @@ impl ApplicationImpl for ApplicationPrivate {
theme.add_resource_path("/com/belmoussaoui/Authenticator/icons/");
}
action!(app, "quit", clone!(@strong app => move |_, _| app.quit()));
action!(app, "quit", clone!(@weak app => move |_, _| app.quit()));
action!(
app,
"preferences",
clone!(@strong app => move |_,_| {
clone!(@weak app => move |_,_| {
let window = app.get_active_window().unwrap();
let preferences = PreferencesWindow::new();
preferences.set_transient_for(Some(&window));
@ -135,7 +135,7 @@ impl ApplicationImpl for ApplicationPrivate {
action!(
app,
"about",
clone!(@strong app => move |_, _| {
clone!(@weak app => move |_, _| {
let window = app.get_active_window().unwrap();
let builder = gtk::Builder::from_resource("/com/belmoussaoui/Authenticator/about_dialog.ui");
@ -148,7 +148,7 @@ impl ApplicationImpl for ApplicationPrivate {
action!(
app,
"providers",
clone!(@strong app, @weak self.model as model => move |_, _| {
clone!(@weak app, @weak self.model as model => move |_, _| {
let window = app.get_active_window().unwrap();
let providers = ProvidersDialog::new(model);
providers.set_transient_for(Some(&window));
@ -159,7 +159,7 @@ impl ApplicationImpl for ApplicationPrivate {
action!(
app,
"lock",
clone!(@strong app => move |_, _| {
clone!(@weak app => move |_, _| {
app.set_locked(true);
})
);
@ -195,13 +195,14 @@ impl ApplicationImpl for ApplicationPrivate {
app.set_accels_for_action("win.show-help-overlay", &["<primary>question"]);
app.set_accels_for_action("win.search", &["<primary>f"]);
app.set_accels_for_action("win.add-account", &["<primary>n"]);
app.set_accels_for_action("add.scan-qr", &["<primary>t"]);
app.set_locked(has_set_password);
app.set_can_be_locked(has_set_password);
let receiver = self.receiver.borrow_mut().take().unwrap();
receiver.attach(
None,
clone!(@strong app => move |action| app.do_action(action)),
clone!(@weak app => move |action| app.do_action(action)),
);
}
}

View file

@ -163,7 +163,7 @@ impl AccountAddDialog {
let username_entry = self_.username_entry.get();
let token_entry = self_.token_entry.get();
let validate_entries = clone!(@weak username_entry, @weak token_entry, @strong self_.actions as actions => move |_: &gtk::Entry| {
let validate_entries = clone!(@weak username_entry, @weak token_entry, @weak self_.actions as actions => move |_: &gtk::Entry| {
let username = username_entry.get_text().unwrap();
let token = token_entry.get_text().unwrap();
@ -306,7 +306,7 @@ impl AccountAddDialog {
action!(
self_.actions,
"scan-qr",
clone!(@strong self as dialog => move |_, _| {
clone!(@weak self as dialog => move |_, _| {
dialog.scan_qr();
})
);
@ -327,7 +327,7 @@ impl AccountAddDialog {
.set_model(Some(&self_.model.get().unwrap().completion_model()));
self_.provider_completion.get().connect_match_selected(
clone!(@strong self as dialog, @strong self_.model as model => move |_, store, iter| {
clone!(@weak self as dialog, @strong self_.model as model => move |_, store, iter| {
let provider_id = store.get_value(iter, 0). get_some::<i32>().unwrap();
let provider = model.get().unwrap().find_by_id(provider_id).unwrap();
dialog.set_provider(provider);

View file

@ -136,7 +136,7 @@ impl AccountRow {
.build();
self_.name_entry.get().connect_changed(
clone!(@strong self_.actions as actions => move |entry| {
clone!(@weak self_.actions as actions => move |entry| {
let name = entry.get_text().unwrap();
get_action!(actions, @save).set_enabled(!name.is_empty());
}),

View file

@ -131,7 +131,7 @@ impl Window {
// load latest window state
window_state::load(&self, &self_.settings);
// save window state on delete event
self.connect_close_request(clone!(@strong self_.settings as settings => move |window| {
self.connect_close_request(clone!(@weak self_.settings as settings => move |window| {
if let Err(err) = window_state::save(&window, &settings) {
warn!("Failed to save window state {:#?}", err);
}
@ -199,7 +199,7 @@ impl Window {
action!(
self,
"unlock",
clone!(@strong sender, @weak password_entry, @strong app => move |_, _| {
clone!(@strong sender, @weak password_entry, @weak app => move |_, _| {
let password = password_entry.get_text().unwrap();
if Keyring::is_current_password(&password).unwrap() {
password_entry.set_text("");
@ -214,7 +214,7 @@ impl Window {
app.connect_local(
"notify::locked",
false,
clone!(@strong app => move |_| {
clone!(@weak app => move |_| {
if app.locked(){
send!(sender, Action::SetView(View::Login));
} else {