diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 33fb8fd0..fe9a8b27 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -28,8 +28,8 @@ impl Window { let action = Rc::new(Action::new()); // Init components - let tab = Rc::new(Tab::new(profile, (browser_action.clone(), action.clone()))); - let header = Header::new(browser_action, action.clone(), &tab.widget.tab_view); + let tab = Rc::new(Tab::new(&profile, (&browser_action, &action))); + let header = Header::new((&browser_action, &action), &profile, &tab.widget.tab_view); let widget = Rc::new(Widget::new(&header.widget.gobject, &tab.widget.tab_view)); // Init events diff --git a/src/app/browser/window/header.rs b/src/app/browser/window/header.rs index be83e548..80126303 100644 --- a/src/app/browser/window/header.rs +++ b/src/app/browser/window/header.rs @@ -4,7 +4,7 @@ mod widget; use bar::Bar; use widget::Widget; -use super::{Action as WindowAction, BrowserAction}; +use super::{Action as WindowAction, BrowserAction, Profile}; use adw::TabView; use std::rc::Rc; @@ -15,14 +15,12 @@ pub struct Header { impl Header { // Construct pub fn new( - // Actions - browser_action: Rc, - window_action: Rc, - // Widgets + (browser_action, window_action): (&Rc, &Rc), + profile: &Rc, tab_view: &TabView, ) -> Self { // Init components - let bar = Bar::new(browser_action, window_action, tab_view); + let bar = Bar::new((browser_action, window_action), profile, tab_view); // Return new struct Self { diff --git a/src/app/browser/window/header/bar.rs b/src/app/browser/window/header/bar.rs index cd4cc92e..c410cc8f 100644 --- a/src/app/browser/window/header/bar.rs +++ b/src/app/browser/window/header/bar.rs @@ -8,8 +8,7 @@ use menu::Menu; use tab::Tab; use widget::Widget; -use crate::app::browser::action::Action as BrowserAction; -use crate::app::browser::window::action::Action as WindowAction; +use super::{BrowserAction, Profile, WindowAction}; use adw::TabView; use std::rc::Rc; @@ -21,13 +20,13 @@ impl Bar { // Constructors pub fn new( - browser_action: Rc, - window_action: Rc, + (browser_action, window_action): (&Rc, &Rc), + profile: &Rc, view: &TabView, ) -> Self { let control = Control::new(); - let tab = Tab::new(window_action.clone(), view); - let menu = Menu::new(browser_action, window_action); + let tab = Tab::new(window_action, view); + let menu = Menu::new((browser_action, window_action), profile); Self { widget: Rc::new(Widget::new( &control.widget.gobject, diff --git a/src/app/browser/window/header/bar/menu.rs b/src/app/browser/window/header/bar/menu.rs index d3836be1..a9820df5 100644 --- a/src/app/browser/window/header/bar/menu.rs +++ b/src/app/browser/window/header/bar/menu.rs @@ -2,8 +2,7 @@ mod widget; use widget::Widget; -use crate::app::browser::action::Action as BrowserAction; -use crate::app::browser::window::action::Action as WindowAction; +use super::{BrowserAction, Profile, WindowAction}; use gtk::{ gio::{self}, prelude::ActionExt, @@ -16,8 +15,8 @@ pub struct Menu { #[rustfmt::skip] // @TODO template builder? impl Menu { pub fn new( - browser_action: Rc, - window_action: Rc, + (browser_action, window_action): (&Rc, &Rc), + _profile: &Rc, ) -> Self { // Main let main = gio::Menu::new(); diff --git a/src/app/browser/window/header/bar/tab.rs b/src/app/browser/window/header/bar/tab.rs index a1443af7..ef5381ed 100644 --- a/src/app/browser/window/header/bar/tab.rs +++ b/src/app/browser/window/header/bar/tab.rs @@ -14,7 +14,7 @@ pub struct Tab { impl Tab { // Construct - pub fn new(window_action: Rc, view: &TabView) -> Self { + pub fn new(window_action: &Rc, view: &TabView) -> Self { Self { widget: Rc::new(Widget::new( view, diff --git a/src/app/browser/window/header/bar/tab/append.rs b/src/app/browser/window/header/bar/tab/append.rs index 8a5be285..16c958c7 100644 --- a/src/app/browser/window/header/bar/tab/append.rs +++ b/src/app/browser/window/header/bar/tab/append.rs @@ -11,9 +11,9 @@ pub struct Append { impl Append { // Construct - pub fn new(window_action: Rc) -> Self { + pub fn new(window_action: &Rc) -> Self { Self { - widget: Rc::new(Widget::new(window_action)), + widget: Rc::new(Widget::new(window_action.clone())), } } } diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 204ed971..a9f2beb7 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -23,28 +23,32 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc}; // Main pub struct Tab { + browser_action: Rc, + window_action: Rc, profile: Rc, - actions: (Rc, Rc), index: Rc, Rc>>>, pub widget: Rc, } impl Tab { // Construct - pub fn new(profile: Rc, action: (Rc, Rc)) -> Self { + pub fn new( + profile: &Rc, + (browser_action, window_action): (&Rc, &Rc), + ) -> Self { // Init empty HashMap index let index: Rc, Rc>>> = Rc::new(RefCell::new(HashMap::new())); // Init context menu - let menu = Menu::new(action.1.clone()); + let menu = Menu::new(window_action); // Init widget let widget = Rc::new(Widget::new(&menu.main)); // Init events widget.tab_view.connect_setup_menu({ - let action = action.1.clone(); + let action = window_action.clone(); let index = index.clone(); let widget = widget.clone(); move |tab_view, tab_page| { @@ -122,8 +126,9 @@ impl Tab { // Return activated `Self` Self { - profile, - actions: (action.0, action.1), + profile: profile.clone(), + browser_action: browser_action.clone(), + window_action: window_action.clone(), index, widget, } @@ -142,9 +147,9 @@ impl Tab { // Init new tab item let item = Rc::new(Item::new( &self.widget.tab_view, - self.profile.clone(), + &self.profile, // Actions - (self.actions.0.clone(), self.actions.1.clone()), + (&self.browser_action, &self.window_action), // Options ( position, @@ -329,8 +334,8 @@ impl Tab { &self.widget.tab_view, transaction, &record.id, - self.profile.clone(), - (self.actions.0.clone(), self.actions.1.clone()), + &self.profile, + (&self.browser_action, &self.window_action), ) { Ok(items) => { for item in items { diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index 0dc3ed0e..906965bc 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -34,13 +34,17 @@ impl Item { // Construct pub fn new( tab_view: &TabView, - profile: Rc, - actions: (Rc, Rc), - options: (Position, Option, bool, bool, bool, bool), + profile: &Rc, + (browser_action, window_action): (&Rc, &Rc), + (position, request, is_pinned, is_selected, is_attention, is_load): ( + Position, + Option, + bool, + bool, + bool, + bool, + ), ) -> Self { - // Get item options from tuple - let (position, request, is_pinned, is_selected, is_attention, is_load) = options; - // Generate unique ID for new page components let id = Rc::new(uuid_string_random()); @@ -49,9 +53,9 @@ impl Item { let action = Rc::new(Action::new()); let page = Rc::new(Page::new( - id.clone(), - profile.clone(), - (actions.0.clone(), actions.1.clone(), action.clone()), + &id, + profile, + (browser_action, window_action, &action), )); let widget = Rc::new(Widget::new( @@ -75,19 +79,20 @@ impl Item { // Show identity selection for item action.ident.connect_activate({ - let browser_action = actions.0.clone(); - let window_action = actions.1.clone(); + let browser_action = browser_action.clone(); let page = page.clone(); let parent = tab_view.clone().upcast::(); + let profile = profile.clone(); + let window_action = window_action.clone(); move || { // Request should match valid URI for all drivers supported if let Some(uri) = page.navigation.request.uri() { // Rout by scheme if uri.scheme().to_lowercase() == "gemini" { return identity::new_gemini( - (browser_action.clone(), window_action.clone()), - profile.clone(), - uri, + (&browser_action, &window_action), + &profile, + &uri, ) .present(Some(&parent)); } @@ -151,9 +156,9 @@ impl Item { tab_view: &TabView, transaction: &Transaction, app_browser_window_tab_id: &i64, - profile: Rc, + profile: &Rc, // Actions - action: (Rc, Rc), + (browser_action, window_action): (&Rc, &Rc), ) -> Result>, String> { let mut items = Vec::new(); @@ -163,9 +168,9 @@ impl Item { // Construct new item object let item = Rc::new(Item::new( tab_view, - profile.clone(), + profile, // Actions - (action.0.clone(), action.1.clone()), + (browser_action, window_action), // Options tuple ( Position::End, diff --git a/src/app/browser/window/tab/item/identity.rs b/src/app/browser/window/tab/item/identity.rs index d1029165..e02cf858 100644 --- a/src/app/browser/window/tab/item/identity.rs +++ b/src/app/browser/window/tab/item/identity.rs @@ -4,17 +4,15 @@ mod unsupported; use gemini::Gemini; use unsupported::Unsupported; -use crate::app::browser::action::Action as BrowserAction; -use crate::app::browser::window::action::Action as WindowAction; -use crate::profile::Profile; +use super::{BrowserAction, Profile, WindowAction}; use gtk::glib::Uri; use std::rc::Rc; /// Create new identity widget for Gemini protocol match given URI pub fn new_gemini( - action: (Rc, Rc), - profile: Rc, - auth_uri: Uri, + action: (&Rc, &Rc), + profile: &Rc, + auth_uri: &Uri, ) -> Gemini { Gemini::new(action, profile, auth_uri) } diff --git a/src/app/browser/window/tab/item/identity/gemini.rs b/src/app/browser/window/tab/item/identity/gemini.rs index cba9138b..c154f291 100644 --- a/src/app/browser/window/tab/item/identity/gemini.rs +++ b/src/app/browser/window/tab/item/identity/gemini.rs @@ -1,9 +1,7 @@ mod widget; use widget::{form::list::item::value::Value, Widget}; -use crate::app::browser::action::Action as BrowserAction; -use crate::app::browser::window::action::Action as WindowAction; -use crate::profile::Profile; +use super::{BrowserAction, Profile, WindowAction}; use gtk::{glib::Uri, prelude::IsA}; use std::rc::Rc; @@ -17,25 +15,30 @@ impl Gemini { /// Create new `Self` for given `Profile` pub fn new( - action: (Rc, Rc), - profile: Rc, - auth_uri: Uri, + (browser_action, window_action): (&Rc, &Rc), + profile: &Rc, + auth_uri: &Uri, ) -> Self { // Init shared URL string from URI let auth_url = auth_uri.to_string(); // Init widget let widget = Rc::new(Widget::new( - (action.0.clone(), action.1.clone()), - profile.clone(), - auth_uri.clone(), + (browser_action, window_action), + profile, + auth_uri, )); // Init events - widget.on_cancel(move || action.0.update.activate(None)); + widget.on_cancel({ + let browser_action = browser_action.clone(); + move || browser_action.update.activate(None) + }); widget.on_apply({ + let profile = profile.clone(); let widget = widget.clone(); + let window_action = window_action.clone(); move |response| { // Get option match user choice let option = match response { @@ -85,7 +88,7 @@ impl Gemini { } // Reload page to apply changes - action.1.reload.activate(); + window_action.reload.activate(); } }); diff --git a/src/app/browser/window/tab/item/identity/gemini/widget.rs b/src/app/browser/window/tab/item/identity/gemini/widget.rs index fb5912f1..b6ecc566 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget.rs @@ -37,16 +37,16 @@ impl Widget { /// Create new `Self` pub fn new( - action: (Rc, Rc), - profile: Rc, - auth_uri: Uri, + (browser_action, window_action): (&Rc, &Rc), + profile: &Rc, + auth_uri: &Uri, ) -> Self { // Init actions let widget_action = Rc::new(WidgetAction::new()); // Init child container let form = Rc::new(Form::new( - (action.0.clone(), action.1.clone(), widget_action.clone()), + (browser_action, window_action, &widget_action), profile, auth_uri, )); diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form.rs index 103ea5b9..b0926bb8 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form.rs @@ -38,25 +38,25 @@ impl Form { /// Create new `Self` pub fn new( - action: (Rc, Rc, Rc), - profile: Rc, - auth_uri: Uri, + (browser_action, _window_action, widget_action): ( + &Rc, + &Rc, + &Rc, + ), + profile: &Rc, + auth_uri: &Uri, ) -> Self { // Init components - let list = Rc::new(List::new( - action.2.clone(), - profile.clone(), - auth_uri.clone(), - )); - let file = Rc::new(File::new(action.2.clone())); - let name = Rc::new(Name::new(action.2.clone())); - let save = Rc::new(Save::new(profile.clone(), list.clone())); - let drop = Rc::new(Drop::new(profile.clone(), list.clone())); + let list = Rc::new(List::new(widget_action, profile, auth_uri)); + let file = Rc::new(File::new(widget_action)); + let name = Rc::new(Name::new(widget_action)); + let save = Rc::new(Save::new(profile, &list)); + let drop = Rc::new(Drop::new(profile, &list)); let exit = Rc::new(Exit::new( - (action.0.clone(), action.2.clone()), - profile.clone(), - list.clone(), - auth_uri.clone(), + (browser_action, widget_action), + profile, + &list, + auth_uri, )); // Init main container @@ -79,8 +79,8 @@ impl Form { name, save, g_box, - auth_uri, - profile, + auth_uri: auth_uri.clone(), + profile: profile.clone(), } } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/drop.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/drop.rs index 96c07338..3e729ecc 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/drop.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/drop.rs @@ -29,7 +29,7 @@ impl Drop { // Constructors /// Create new `Self` - pub fn new(profile: Rc, list: Rc) -> Self { + pub fn new(profile: &Rc, list: &Rc) -> Self { // Init main widget let button = Button::builder() .label(LABEL) @@ -42,6 +42,7 @@ impl Drop { button.connect_clicked({ let button = button.clone(); let list = list.clone(); + let profile = profile.clone(); move |_| { match list.selected().value_enum() { Value::ProfileIdentityGeminiId(profile_identity_gemini_id) => { diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/exit.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/exit.rs index 61bfff21..89226377 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/exit.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/exit.rs @@ -34,10 +34,10 @@ impl Exit { /// Create new `Self` pub fn new( - action: (Rc, Rc), - profile: Rc, - list: Rc, - auth_uri: Uri, + (browser_action, widget_action): (&Rc, &Rc), + profile: &Rc, + list: &Rc, + auth_uri: &Uri, ) -> Self { // Init main widget let button = Button::builder() @@ -50,7 +50,11 @@ impl Exit { // Init events button.connect_clicked({ let auth_uri = auth_uri.clone(); + let browser_action = browser_action.clone(); let button = button.clone(); + let list = list.clone(); + let profile = profile.clone(); + let widget_action = widget_action.clone(); move |_| { // Get selected identity from holder match list.selected().value_enum() { @@ -84,8 +88,8 @@ impl Exit { let button = button.clone(); let list = list.clone(); let profile = profile.clone(); - let browser_action = action.0.clone(); - let widget_action = action.1.clone(); + let browser_action = browser_action.clone(); + let widget_action = widget_action.clone(); move |_, _| { match profile .identity diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs index ed27fb52..2db475bd 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs @@ -21,7 +21,7 @@ impl File { // Constructors /// Create new `Self` - pub fn new(widget_action: Rc) -> Self { + pub fn new(widget_action: &Rc) -> Self { // Init PEM let pem = Rc::new(RefCell::new(None)); diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs index 913a49bb..e850026e 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs @@ -25,7 +25,7 @@ impl List { // Constructors /// Create new `Self` - pub fn new(widget_action: Rc, profile: Rc, auth_uri: Uri) -> Self { + pub fn new(widget_action: &Rc, profile: &Rc, auth_uri: &Uri) -> Self { // Init dropdown items let guest_session = Item::new_guest_session(); let generate_pem = Item::new_generate_pem(); @@ -43,7 +43,7 @@ impl List { let mut is_guest_session = true; for identity in identities { match Item::new_profile_identity_gemini_id( - &profile, + profile, identity.id, &auth_uri.to_string(), ) { @@ -164,7 +164,10 @@ impl List { .build(); // Connect events - dropdown.connect_selected_notify(move |_| widget_action.update.activate()); + dropdown.connect_selected_notify({ + let widget_action = widget_action.clone(); + move |_| widget_action.update.activate() + }); // Return activated `Self` Self { diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs index b88928cf..6b84d0b3 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs @@ -19,7 +19,7 @@ impl Name { // Constructors /// Create new `Self` - pub fn new(widget_action: Rc) -> Self { + pub fn new(widget_action: &Rc) -> Self { // Init main gobject let entry = Entry::builder() .margin_top(MARGIN) @@ -29,7 +29,10 @@ impl Name { .build(); // Init events - entry.connect_changed(move |_| widget_action.update.activate()); + entry.connect_changed({ + let widget_action = widget_action.clone(); + move |_| widget_action.update.activate() + }); // Return activated `Self` Self { entry } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/save.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/save.rs index 838fc18a..d8fb45d0 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/save.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/save.rs @@ -23,7 +23,7 @@ impl Save { // Constructors /// Create new `Self` - pub fn new(profile: Rc, list: Rc) -> Self { + pub fn new(profile: &Rc, list: &Rc) -> Self { // Init main widget let button = Button::builder() .label(LABEL) @@ -35,6 +35,8 @@ impl Save { // Init events button.connect_clicked({ let button = button.clone(); + let list = list.clone(); + let profile = profile.clone(); move |_| { // Get selected identity from holder match list.selected().value_enum() { diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index d92fad13..516c9d87 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -55,12 +55,12 @@ impl Page { // Constructors pub fn new( - id: Rc, - profile: Rc, + id: &Rc, + profile: &Rc, (browser_action, window_action, tab_action): ( - Rc, - Rc, - Rc, + &Rc, + &Rc, + &Rc, ), ) -> Self { // Init components @@ -80,7 +80,7 @@ impl Page { let input = Rc::new(Input::new()); let widget = Rc::new(Widget::new( - &id, + id, &navigation.widget.g_box, &content.g_box, &search.g_box, @@ -91,12 +91,12 @@ impl Page { // Done Self { - id, - profile, + id: id.clone(), + profile: profile.clone(), // Actions - browser_action, - tab_action, - window_action, + browser_action: browser_action.clone(), + tab_action: tab_action.clone(), + window_action: window_action.clone(), // Components client: Rc::new(Client::new()), content, diff --git a/src/app/browser/window/tab/menu.rs b/src/app/browser/window/tab/menu.rs index f1238499..294224dc 100644 --- a/src/app/browser/window/tab/menu.rs +++ b/src/app/browser/window/tab/menu.rs @@ -13,7 +13,7 @@ impl Menu { // Constructors /// Create new `Self` - pub fn new(window_action: Rc) -> Self { + pub fn new(window_action: &Rc) -> Self { let main = gtk::gio::Menu::new(); main.append(