emit update action on identity logout

This commit is contained in:
yggverse 2024-12-07 23:44:34 +02:00
parent 483be18b17
commit e8638a8f24
7 changed files with 64 additions and 39 deletions

View File

@ -25,7 +25,11 @@ impl Gemini {
let auth_url = auth_uri.to_string(); let auth_url = auth_uri.to_string();
// Init widget // Init widget
let widget = Rc::new(Widget::new(profile.clone(), &auth_url)); let widget = Rc::new(Widget::new(
(action.0.clone(), action.1.clone()),
profile.clone(),
&auth_url,
));
// Init events // Init events
widget.on_cancel({ widget.on_cancel({

View File

@ -1,10 +1,12 @@
mod action; mod action;
pub mod form; pub mod form;
use action::Action;
use form::{list::item::value::Value, Form}; use form::{list::item::value::Value, Form};
use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::window::action::Action as WindowAction;
use crate::profile::Profile; use crate::profile::Profile;
use action::Action as WidgetAction;
use adw::{ use adw::{
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
AlertDialog, ResponseAppearance, AlertDialog, ResponseAppearance,
@ -33,12 +35,20 @@ impl Widget {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(profile: Rc<Profile>, auth_url: &str) -> Self { pub fn new(
action: (Rc<BrowserAction>, Rc<WindowAction>),
profile: Rc<Profile>,
auth_url: &str,
) -> Self {
// Init actions // Init actions
let action = Rc::new(Action::new()); let widget_action = Rc::new(WidgetAction::new());
// Init child container // Init child container
let form = Rc::new(Form::new(profile, action.clone(), auth_url)); let form = Rc::new(Form::new(
(action.0.clone(), action.1.clone(), widget_action.clone()),
profile,
auth_url,
));
// Init main widget // Init main widget
let alert_dialog = AlertDialog::builder() let alert_dialog = AlertDialog::builder()
@ -64,7 +74,7 @@ impl Widget {
alert_dialog.set_response_appearance(RESPONSE_CANCEL.0, ResponseAppearance::Destructive); alert_dialog.set_response_appearance(RESPONSE_CANCEL.0, ResponseAppearance::Destructive);
// Init events // Init events
action.update.connect_activate({ widget_action.update.connect_activate({
let form = form.clone(); let form = form.clone();
let alert_dialog = alert_dialog.clone(); let alert_dialog = alert_dialog.clone();
move || { move || {

View File

@ -12,7 +12,9 @@ use list::{item::value::Value, List};
use name::Name; use name::Name;
use save::Save; use save::Save;
use super::Action; use super::WidgetAction;
use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::window::action::Action as WindowAction;
use crate::profile::Profile; use crate::profile::Profile;
use gtk::{prelude::BoxExt, Box, Orientation}; use gtk::{prelude::BoxExt, Box, Orientation};
use std::rc::Rc; use std::rc::Rc;
@ -32,14 +34,18 @@ impl Form {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(profile: Rc<Profile>, action_widget: Rc<Action>, auth_url: &str) -> Self { pub fn new(
action: (Rc<BrowserAction>, Rc<WindowAction>, Rc<WidgetAction>),
profile: Rc<Profile>,
auth_url: &str,
) -> Self {
// Init components // Init components
let list = Rc::new(List::new(action_widget.clone(), profile.clone(), auth_url)); let list = Rc::new(List::new(action.2.clone(), profile.clone(), auth_url));
let file = Rc::new(File::new(action_widget.clone())); let file = Rc::new(File::new(action.2.clone()));
let name = Rc::new(Name::new(action_widget.clone())); let name = Rc::new(Name::new(action.2.clone()));
let save = Rc::new(Save::new(profile.clone(), list.clone())); let save = Rc::new(Save::new(profile.clone(), list.clone()));
let drop = Rc::new(Drop::new(profile.clone(), list.clone())); let drop = Rc::new(Drop::new(profile.clone(), list.clone()));
let exit = Rc::new(Exit::new(profile.clone(), list.clone())); let exit = Rc::new(Exit::new(action.0.clone(), profile.clone(), list.clone()));
// Init main container // Init main container
let g_box = Box::builder().orientation(Orientation::Vertical).build(); let g_box = Box::builder().orientation(Orientation::Vertical).build();

View File

@ -1,4 +1,5 @@
use super::list::{item::Value, List}; use super::list::{item::Value, List};
use crate::app::browser::action::Action as BrowserAction;
use crate::profile::Profile; use crate::profile::Profile;
use adw::{ use adw::{
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
@ -29,7 +30,7 @@ impl Exit {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(profile: Rc<Profile>, list: Rc<List>) -> Self { pub fn new(browser_action: Rc<BrowserAction>, profile: Rc<Profile>, list: Rc<List>) -> Self {
// Init main widget // Init main widget
let button = Button::builder() let button = Button::builder()
.label(LABEL) .label(LABEL)
@ -69,29 +70,33 @@ impl Exit {
// Connect confirmation event // Connect confirmation event
alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), { alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), {
let browser_action = browser_action.clone();
let button = button.clone(); let button = button.clone();
let list = list.clone(); let list = list.clone();
let profile = profile.clone(); let profile = profile.clone();
move |_, _| match profile move |_, _| {
.identity match profile
.gemini .identity
.auth .gemini
.remove_ref(profile_identity_gemini_id) .auth
{ .remove_ref(profile_identity_gemini_id)
Ok(_) => match list.selected().update(&profile, "") { {
Ok(_) => { Ok(_) => match list.selected().update(&profile, "") {
button.set_css_classes(&["success"]); Ok(_) => {
button.set_label("Identity successfully disconnected") button.set_css_classes(&["success"]);
} button.set_label("Identity successfully disconnected")
}
Err(e) => {
button.set_css_classes(&["error"]);
button.set_label(&e.to_string())
}
},
Err(e) => { Err(e) => {
button.set_css_classes(&["error"]); button.set_css_classes(&["error"]);
button.set_label(&e.to_string()) button.set_label(&e.to_string())
} }
},
Err(e) => {
button.set_css_classes(&["error"]);
button.set_label(&e.to_string())
} }
browser_action.update.activate(None)
} }
}); });

View File

@ -1,4 +1,4 @@
use super::Action; use super::WidgetAction;
use gtk::{ use gtk::{
gio::{Cancellable, ListStore, TlsCertificate}, gio::{Cancellable, ListStore, TlsCertificate},
glib::{gformat, GString}, glib::{gformat, GString},
@ -21,7 +21,7 @@ impl File {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(action_widget: Rc<Action>) -> Self { pub fn new(widget_action: Rc<WidgetAction>) -> Self {
// Init PEM // Init PEM
let pem = Rc::new(RefCell::new(None)); let pem = Rc::new(RefCell::new(None));
@ -35,7 +35,7 @@ impl File {
// Init events // Init events
button.connect_clicked({ button.connect_clicked({
let action_widget = action_widget.clone(); let widget_action = widget_action.clone();
let button = button.clone(); let button = button.clone();
let pem = pem.clone(); let pem = pem.clone();
move |_| { move |_| {
@ -61,7 +61,7 @@ impl File {
.default_filter(&filter_pem) .default_filter(&filter_pem)
.build() .build()
.open(None::<&Window>, None::<&Cancellable>, { .open(None::<&Window>, None::<&Cancellable>, {
let action_widget = action_widget.clone(); let widget_action = widget_action.clone();
let button = button.clone(); let button = button.clone();
let pem = pem.clone(); let pem = pem.clone();
move |result| { move |result| {
@ -89,7 +89,7 @@ impl File {
} }
} }
button.set_sensitive(true); // unlock button.set_sensitive(true); // unlock
action_widget.update.activate() widget_action.update.activate()
} }
}); });
} }

View File

@ -3,7 +3,7 @@ use std::rc::Rc;
use item::Item; use item::Item;
use super::Action; use super::WidgetAction;
use crate::profile::Profile; use crate::profile::Profile;
use gtk::{ use gtk::{
gdk::Cursor, gdk::Cursor,
@ -24,7 +24,7 @@ impl List {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(action_widget: Rc<Action>, profile: Rc<Profile>, auth_url: &str) -> Self { pub fn new(widget_action: Rc<WidgetAction>, profile: Rc<Profile>, auth_url: &str) -> Self {
// Init model // Init model
let list_store = ListStore::new::<Item>(); let list_store = ListStore::new::<Item>();
@ -133,7 +133,7 @@ impl List {
.build(); .build();
// Connect events // Connect events
dropdown.connect_selected_notify(move |_| action_widget.update.activate()); dropdown.connect_selected_notify(move |_| widget_action.update.activate());
// Return activated `Self` // Return activated `Self`
Self { Self {

View File

@ -1,4 +1,4 @@
use super::Action; use super::WidgetAction;
use gtk::{ use gtk::{
glib::GString, glib::GString,
prelude::{EditableExt, EntryExt, WidgetExt}, prelude::{EditableExt, EntryExt, WidgetExt},
@ -19,7 +19,7 @@ impl Name {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn new(action_widget: Rc<Action>) -> Self { pub fn new(widget_action: Rc<WidgetAction>) -> Self {
// Init main gobject // Init main gobject
let entry = Entry::builder() let entry = Entry::builder()
.margin_top(MARGIN) .margin_top(MARGIN)
@ -29,7 +29,7 @@ impl Name {
.build(); .build();
// Init events // Init events
entry.connect_changed(move |_| action_widget.update.activate()); entry.connect_changed(move |_| widget_action.update.activate());
// Return activated `Self` // Return activated `Self`
Self { entry } Self { entry }