diff --git a/src/app.rs b/src/app.rs index 2523a5be..37cb7b3e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -10,12 +10,12 @@ use gtk::{ prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt}, }; use sqlite::Transaction; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; const APPLICATION_ID: &str = "io.github.yggverse.Yoda"; pub struct App { - profile: Arc, + profile: Rc, application: Application, } @@ -30,7 +30,7 @@ impl App { .build(); // Init components - let profile = Arc::new(profile); + let profile = Rc::new(profile); let browser = Rc::new(Browser::build(&profile)); // Prevent startup warning @TODO diff --git a/src/app/browser.rs b/src/app/browser.rs index 0103bfea..85f56bbe 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -18,7 +18,7 @@ use gtk::{ prelude::GtkWindowExt, }; use sqlite::Transaction; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; pub struct Browser { pub action: Rc, @@ -30,7 +30,7 @@ impl Browser { // Constructors /// Build new `Self` - pub fn build(profile: &Arc) -> Browser { + pub fn build(profile: &Rc) -> Browser { // Init components let action = Rc::new(Action::new()); let window = Rc::new(Window::build(profile, &action)); diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 5f6f7bca..f143b1b8 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -11,7 +11,7 @@ use anyhow::Result; use gtk::{Box, Orientation, prelude::BoxExt}; use header::Header; use sqlite::Transaction; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; use tab::Tab; pub struct Window { @@ -24,7 +24,7 @@ impl Window { // Constructors /// Build new `Self` - pub fn build(profile: &Arc, browser_action: &Rc) -> Self { + pub fn build(profile: &Rc, browser_action: &Rc) -> Self { // Init local actions let action = Rc::new(Action::new()); diff --git a/src/app/browser/window/header.rs b/src/app/browser/window/header.rs index d495ef9f..24e33a2b 100644 --- a/src/app/browser/window/header.rs +++ b/src/app/browser/window/header.rs @@ -4,12 +4,12 @@ use super::{Action as WindowAction, BrowserAction, Profile}; use adw::{TabView, ToolbarView}; use bar::Bar; use gtk::Box; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; pub trait Header { fn header( action: (&Rc, &Rc), - profile: &Arc, + profile: &Rc, tab_view: &TabView, ) -> Self; } @@ -20,7 +20,7 @@ impl Header for ToolbarView { /// Build new `Self` fn header( (browser_action, window_action): (&Rc, &Rc), - profile: &Arc, + profile: &Rc, tab_view: &TabView, ) -> Self { let toolbar_view = ToolbarView::builder().build(); diff --git a/src/app/browser/window/header/bar.rs b/src/app/browser/window/header/bar.rs index 927cc6cb..16b998d8 100644 --- a/src/app/browser/window/header/bar.rs +++ b/src/app/browser/window/header/bar.rs @@ -9,12 +9,12 @@ use tab::Tab; use super::{BrowserAction, Profile, WindowAction}; use adw::{TabBar, TabView}; use gtk::{Box, MenuButton, Orientation, prelude::BoxExt}; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; pub trait Bar { fn bar( action: (&Rc, &Rc), - profile: &Arc, + profile: &Rc, view: &TabView, ) -> Self; } @@ -25,7 +25,7 @@ impl Bar for Box { /// Build new `Self` fn bar( (browser_action, window_action): (&Rc, &Rc), - profile: &Arc, + profile: &Rc, view: &TabView, ) -> Self { let g_box = Box::builder() diff --git a/src/app/browser/window/header/bar/menu.rs b/src/app/browser/window/header/bar/menu.rs index f19574a0..0dc63f3a 100644 --- a/src/app/browser/window/header/bar/menu.rs +++ b/src/app/browser/window/header/bar/menu.rs @@ -6,13 +6,13 @@ use gtk::{ prelude::{ActionExt, ToVariant}, }; use indexmap::IndexMap; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; // Config options const LABEL_MAX_LENGTH: usize = 28; pub trait Menu { - fn menu(action: (&Rc, &Rc), profile: &Arc) -> Self; + fn menu(action: (&Rc, &Rc), profile: &Rc) -> Self; } #[rustfmt::skip] // @TODO template builder? @@ -22,7 +22,7 @@ impl Menu for MenuButton { /// Build new `Self` fn menu( (browser_action, window_action): (&Rc, &Rc), - profile: &Arc, + profile: &Rc, ) -> Self { // Main let main = gio::Menu::new(); diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 40c91b0f..b85081de 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -13,12 +13,12 @@ pub use item::Item; use menu::Menu; use sourceview::prelude::IsA; use sqlite::Transaction; -use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc}; +use std::{cell::RefCell, collections::HashMap, rc::Rc}; // Main pub struct Tab { window_action: Rc, - profile: Arc, + profile: Rc, index: Rc>>>, pub action: Rc, pub tab_view: TabView, @@ -28,7 +28,7 @@ impl Tab { // Constructors /// Build new `Self` - pub fn build(profile: &Arc, window_action: &Rc) -> Self { + pub fn build(profile: &Rc, window_action: &Rc) -> Self { let action = Rc::new(Action::new()); // Init empty HashMap index diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index bafd0ff2..2d8daff7 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -15,7 +15,7 @@ use gtk::{ }; use page::Page; use sqlite::Transaction; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; pub struct Item { // Multi-protocol handler @@ -32,7 +32,7 @@ impl Item { /// Build new `Self` pub fn build( (tab_page, target_child): (&TabPage, &Box), - profile: &Arc, + profile: &Rc, (window_action, tab_action): (&Rc, &Rc), request: Option<&str>, is_load: bool, diff --git a/src/app/browser/window/tab/item/client.rs b/src/app/browser/window/tab/item/client.rs index eb102627..bf00e7a1 100644 --- a/src/app/browser/window/tab/item/client.rs +++ b/src/app/browser/window/tab/item/client.rs @@ -9,21 +9,21 @@ use gtk::{ glib::{Uri, UriFlags}, prelude::CancellableExt, }; -use std::{cell::Cell, rc::Rc, sync::Arc}; +use std::{cell::Cell, rc::Rc}; /// Multi-protocol client API for tab `Item` pub struct Client { cancellable: Cell, driver: Rc, page: Rc, - profile: Arc, + profile: Rc, } impl Client { // Constructors /// Create new `Self` - pub fn init(profile: &Arc, page: &Rc) -> Self { + pub fn init(profile: &Rc, page: &Rc) -> Self { Self { cancellable: Cell::new(Cancellable::new()), driver: Rc::new(Driver::build(page)), @@ -118,7 +118,7 @@ impl Client { /// Create request using async DNS resolver (slow method) /// * return suggestion [Uri](https://docs.gtk.org/glib/struct.Uri.html) on failure (to handle as redirect) fn lookup( - profile: &Arc, + profile: &Rc, query: &str, cancellable: Cancellable, callback: impl FnOnce(Rc, Cancellable, Result) + 'static, diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index f48c440d..35b0aafc 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -13,10 +13,10 @@ use input::Input; use navigation::Navigation; use search::Search; use sqlite::Transaction; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; pub struct Page { - pub profile: Arc, + pub profile: Rc, // Actions pub item_action: Rc, pub window_action: Rc, @@ -38,7 +38,7 @@ impl Page { // Constructors pub fn build( - profile: &Arc, + profile: &Rc, (window_action, tab_action, item_action): ( &Rc, &Rc, diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 8a3736c8..1ff26907 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -18,7 +18,7 @@ use home::Home; use reload::Reload; use request::Request; use sqlite::Transaction; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; const MARGIN: i32 = 6; const SPACING: i32 = 6; @@ -31,7 +31,7 @@ pub struct Navigation { impl Navigation { pub fn build( - profile: &Arc, + profile: &Rc, (window_action, tab_action, item_action): ( &Rc, &Rc, diff --git a/src/app/browser/window/tab/item/page/navigation/bookmark.rs b/src/app/browser/window/tab/item/page/navigation/bookmark.rs index e0d3cdaf..04be9f7f 100644 --- a/src/app/browser/window/tab/item/page/navigation/bookmark.rs +++ b/src/app/browser/window/tab/item/page/navigation/bookmark.rs @@ -3,19 +3,19 @@ use gtk::{ Button, Entry, prelude::{ActionExt, ButtonExt, EditableExt, WidgetExt}, }; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; const ICON_NAME: (&str, &str) = ("non-starred-symbolic", "starred-symbolic"); const TOOLTIP_TEXT: (&str, &str) = ("Add Bookmark", "Remove Bookmark"); pub struct Bookmark { - profile: Arc, + profile: Rc, request: Entry, pub button: Button, } impl Bookmark { - pub fn build(action: &Rc, profile: &Arc, request: &Entry) -> Self { + pub fn build(action: &Rc, profile: &Rc, request: &Entry) -> Self { let button = Button::builder() .action_name(format!( "{}.{}", @@ -65,7 +65,7 @@ fn icon_name(has_bookmark: bool) -> &'static str { } } -fn update(profile: &Arc, button: &Button, request: gtk::glib::GString) { +fn update(profile: &Rc, button: &Button, request: gtk::glib::GString) { let profile = profile.clone(); let button = button.clone(); gtk::glib::spawn_future_local(async move { diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index 6719aa13..6a660eee 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -19,7 +19,6 @@ use sqlite::Transaction; use std::{ cell::{Cell, RefCell}, rc::Rc, - sync::Arc, }; use suggestion::Suggestion; @@ -30,14 +29,14 @@ pub struct Request { pub entry: Entry, pub info: Rc>, suggestion: Rc, - profile: Arc, + profile: Rc, } impl Request { // Constructors /// Build new `Self` - pub fn build(item_action: &Rc, profile: &Arc) -> Self { + pub fn build(item_action: &Rc, profile: &Rc) -> Self { // Init components let info = Rc::new(RefCell::new(Info::new())); @@ -364,7 +363,7 @@ fn is_focused(entry: &Entry) -> bool { } /// Present Identity [AlertDialog](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AlertDialog.html) for `Self` -fn show_identity_dialog(entry: &Entry, profile: &Arc) { +fn show_identity_dialog(entry: &Entry, profile: &Rc) { // connect identity traits use identity::{Common, Unsupported}; if let Some(uri) = uri(entry) { @@ -390,7 +389,7 @@ fn show_identity_dialog(entry: &Entry, profile: &Arc) { } /// Present Search providers [AlertDialog](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AlertDialog.html) for `Self` -fn show_search_dialog(entry: &Entry, profile: &Arc) { +fn show_search_dialog(entry: &Entry, profile: &Rc) { use search::Search; AlertDialog::search(profile).present(Some(entry)) } diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs index 4b7fee1c..d4358269 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs @@ -5,16 +5,13 @@ use crate::Profile; use action::Action as WidgetAction; use adw::AlertDialog; use gtk::{glib::Uri, prelude::EditableExt}; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; // Select options pub trait Common { - fn common( - profile: &Arc, - request: &Uri, - callback: &Rc, - ) -> Self; + fn common(profile: &Rc, request: &Uri, callback: &Rc) + -> Self; } impl Common for AlertDialog { @@ -22,7 +19,7 @@ impl Common for AlertDialog { /// Create new `Self` fn common( - profile: &Arc, + profile: &Rc, request: &Uri, callback: &Rc, ) -> Self { diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form.rs index b7b7b52c..36747d4d 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form.rs @@ -19,7 +19,7 @@ use gtk::{ glib::Uri, prelude::{BoxExt, WidgetExt}, }; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; pub struct Form { // pub action_widget: Rc, @@ -30,14 +30,14 @@ pub struct Form { pub name: Entry, pub save: Rc, pub g_box: Box, - profile: Arc, + profile: Rc, } impl Form { // Constructors /// Create new `Self` - pub fn build(widget_action: &Rc, profile: &Arc, request: &Uri) -> Self { + pub fn build(widget_action: &Rc, profile: &Rc, request: &Uri) -> Self { // Init components let list = Rc::new(List::build(widget_action, profile, request)); let file = Rc::new(File::build(widget_action)); diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/drop.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/drop.rs index 043838ac..e94e64ee 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/drop.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/drop.rs @@ -9,7 +9,7 @@ use gtk::{ glib::timeout_add_seconds_local_once, prelude::{ButtonExt, WidgetExt}, }; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; // Defaults @@ -30,7 +30,7 @@ impl Drop { // Constructors /// Create new `Self` - pub fn build(profile: &Arc, list: &Rc) -> Self { + pub fn build(profile: &Rc, list: &Rc) -> Self { // Init main widget let button = Button::builder() .label(LABEL) diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/exit.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/exit.rs index 59e05a7a..d259fd72 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/exit.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/exit.rs @@ -8,12 +8,12 @@ use gtk::{ glib::{Uri, timeout_add_seconds_local_once}, prelude::{ButtonExt, WidgetExt}, }; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; pub trait Exit { fn exit( widget_action: &Rc, - profile: &Arc, + profile: &Rc, list: &Rc, request: &Uri, ) -> Self; @@ -25,7 +25,7 @@ impl Exit for Button { /// Create new `Self` fn exit( widget_action: &Rc, - profile: &Arc, + profile: &Rc, list: &Rc, request: &Uri, ) -> Self { diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list.rs index 8393970b..6cc6b65c 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list.rs @@ -1,5 +1,5 @@ pub mod item; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; use item::Item; @@ -25,7 +25,7 @@ impl List { // Constructors /// Create new `Self` - pub fn build(widget_action: &Rc, profile: &Arc, request: &Uri) -> Self { + pub fn build(widget_action: &Rc, profile: &Rc, request: &Uri) -> Self { // Init dropdown items let guest_session = Item::new_guest_session(); let generate_pem = Item::new_generate_pem(); diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list/item.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list/item.rs index 4b314b8d..de6e40b9 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list/item.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list/item.rs @@ -14,7 +14,7 @@ use gtk::{ gio::TlsCertificate, glib::{self, Object}, }; -use std::sync::Arc; +use std::rc::Rc; glib::wrapper! { pub struct Item(ObjectSubclass); @@ -54,7 +54,7 @@ impl Item { } pub fn new_profile_identity_id( - profile: &Arc, + profile: &Rc, profile_identity_id: i64, auth_url: &str, ) -> Result { @@ -96,7 +96,7 @@ impl Item { // Actions /// Update properties for `Self` for given `Profile` and `auth_url` - pub fn update(&self, profile: &Arc, auth_url: &str) -> Result<(), Error> { + pub fn update(&self, profile: &Rc, auth_url: &str) -> Result<(), Error> { // Update item depending on value type match self.value_enum() { Value::ProfileIdentityId(profile_identity_id) => { diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list/item/is_active.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list/item/is_active.rs index a3901463..8a4a6bea 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list/item/is_active.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/list/item/is_active.rs @@ -1,8 +1,8 @@ use crate::profile::Profile; -use std::sync::Arc; +use std::rc::Rc; pub fn new_for_profile_identity_id( - profile: &Arc, + profile: &Rc, profile_identity_id: i64, auth_url: &str, ) -> bool { diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/save.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/save.rs index 909df98c..82ce15ab 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/save.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/save.rs @@ -9,7 +9,7 @@ use gtk::{ glib::{Priority, timeout_add_seconds_local_once}, prelude::{ButtonExt, FileExt, OutputStreamExtManual, WidgetExt}, }; -use std::{path::MAIN_SEPARATOR, rc::Rc, sync::Arc}; +use std::{path::MAIN_SEPARATOR, rc::Rc}; const LABEL: &str = "Export"; const TOOLTIP_TEXT: &str = "Export selected identity to file"; @@ -24,7 +24,7 @@ impl Save { // Constructors /// Create new `Self` - pub fn build(profile: &Arc, list: &Rc) -> Self { + pub fn build(profile: &Rc, list: &Rc) -> Self { // Init main widget let button = Button::builder() .label(LABEL) diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/save/certificate.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/save/certificate.rs index 31c4fff0..7d4d0b16 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/save/certificate.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/save/certificate.rs @@ -2,7 +2,7 @@ use anyhow::{Result, bail}; use crate::profile::Profile; use gtk::{gio::TlsCertificate, prelude::TlsCertificateExt}; -use std::sync::Arc; +use std::rc::Rc; /// Certificate details holder for export to file action pub struct Certificate { @@ -14,7 +14,7 @@ impl Certificate { // Constructors /// Create new `Self` - pub fn build(profile: &Arc, profile_identity_id: i64) -> Result { + pub fn build(profile: &Rc, profile_identity_id: i64) -> Result { let record = profile.identity.database.record(profile_identity_id)?; match record { Some(identity) => Ok(Self { diff --git a/src/app/browser/window/tab/item/page/navigation/request/search.rs b/src/app/browser/window/tab/item/page/navigation/request/search.rs index 57c0c35e..dea6c8c1 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/search.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/search.rs @@ -10,7 +10,6 @@ use form::{Form, Query, list::Item, list::item::Value}; use gtk::prelude::{EditableExt, WidgetExt}; use sourceview::prelude::CastNone; use std::rc::Rc; -use std::sync::Arc; // Response variants const RESPONSE_APPLY: (&str, &str) = ("apply", "Apply"); @@ -18,14 +17,14 @@ const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel"); // const RESPONSE_MANAGE: (&str, &str) = ("manage", "Manage"); pub trait Search { - fn search(profile: &Arc) -> Self; + fn search(profile: &Rc) -> Self; } impl Search for AlertDialog { // Constructors /// Create new `Self` - fn search(profile: &Arc) -> Self { + fn search(profile: &Rc) -> Self { // Init child container let form = Rc::new(Form::build(profile)); diff --git a/src/app/browser/window/tab/item/page/navigation/request/search/form.rs b/src/app/browser/window/tab/item/page/navigation/request/search/form.rs index 82ab85b3..a22ae11d 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/search/form.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/search/form.rs @@ -7,7 +7,7 @@ use drop::Drop; use gtk::{Box, Button, Entry, Orientation, prelude::BoxExt}; use list::List; pub use query::Query; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; pub struct Form { pub drop: Button, @@ -20,7 +20,7 @@ impl Form { // Constructors /// Create new `Self` - pub fn build(profile: &Arc) -> Self { + pub fn build(profile: &Rc) -> Self { // Init components let list = Rc::new(List::build(profile)); let query = Entry::query(); diff --git a/src/app/browser/window/tab/item/page/navigation/request/search/form/drop.rs b/src/app/browser/window/tab/item/page/navigation/request/search/form/drop.rs index 0b9c33b0..d9114463 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/search/form/drop.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/search/form/drop.rs @@ -9,17 +9,17 @@ use gtk::{ glib::timeout_add_seconds_local_once, prelude::{ButtonExt, WidgetExt}, }; -use std::{rc::Rc, sync::Arc}; +use std::rc::Rc; pub trait Drop { - fn drop(profile: &Arc, list: &Rc) -> Self; + fn drop(profile: &Rc, list: &Rc) -> Self; } impl Drop for Button { // Constructors /// Create new `Self` - fn drop(profile: &Arc, list: &Rc) -> Self { + fn drop(profile: &Rc, list: &Rc) -> Self { // Defaults const LABEL: &str = "Delete"; diff --git a/src/app/browser/window/tab/item/page/navigation/request/search/form/list.rs b/src/app/browser/window/tab/item/page/navigation/request/search/form/list.rs index 79b6d64c..0595d4ca 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/search/form/list.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/search/form/list.rs @@ -10,7 +10,7 @@ use gtk::{ prelude::{BoxExt, ListItemExt, ObjectExt, WidgetExt}, }; pub use item::Item; -use std::sync::Arc; +use std::rc::Rc; pub struct List { pub dropdown: DropDown, @@ -21,7 +21,7 @@ impl List { // Constructors /// Create new `Self` - pub fn build(profile: &Arc) -> Self { + pub fn build(profile: &Rc) -> Self { // Init dropdown items let new_search_provider = Item::add(); diff --git a/src/app/browser/window/tab/item/page/navigation/request/suggestion.rs b/src/app/browser/window/tab/item/page/navigation/request/suggestion.rs index 2695aae8..563b6af7 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/suggestion.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/suggestion.rs @@ -17,14 +17,14 @@ use gtk::{ }; pub use item::Item; use sourceview::prelude::ListModelExt; -use std::{cell::RefCell, rc::Rc, sync::Arc}; +use std::{cell::RefCell, rc::Rc}; pub struct Suggestion { list_store: ListStore, list_view: ListView, single_selection: SingleSelection, entry: Entry, - profile: Arc, + profile: Rc, popover: Popover, pub signal_handler_id: Rc>>, } @@ -33,7 +33,7 @@ impl Suggestion { // Constructors /// Create new `Self` - pub fn build(profile: &Arc, entry: &Entry) -> Self { + pub fn build(profile: &Rc, entry: &Entry) -> Self { let signal_handler_id = Rc::new(RefCell::new(None)); let list_store = ListStore::new::(); let single_selection = { diff --git a/src/profile/bookmark.rs b/src/profile/bookmark.rs index 3f0ce0b2..509b5647 100644 --- a/src/profile/bookmark.rs +++ b/src/profile/bookmark.rs @@ -10,11 +10,11 @@ use memory::Memory; use r2d2::Pool; use r2d2_sqlite::SqliteConnectionManager; use sqlite::Transaction; -use std::sync::RwLock; +use std::cell::RefCell; pub struct Bookmark { - database: Database, // permanent storage - memory: RwLock, // fast search index + database: Database, // permanent storage + memory: RefCell, // fast search index } impl Bookmark { @@ -24,11 +24,11 @@ impl Bookmark { pub fn build(database_pool: &Pool, profile_id: i64) -> Result { // Init children components let database = Database::new(database_pool, profile_id); - let memory = RwLock::new(Memory::new()); + let memory = RefCell::new(Memory::new()); // Build initial index { - let mut memory = memory.write().unwrap(); + let mut memory = memory.borrow_mut(); for item in database.records(None, None)? { memory.add(item); } @@ -43,7 +43,7 @@ impl Bookmark { /// Toggle bookmark in `database` and `memory` index /// * return `true` on bookmark create, `false` on delete pub fn toggle(&self, request: &str, title: Option<&str>) -> Result { - let mut memory = self.memory.write().unwrap(); + let mut memory = self.memory.borrow_mut(); Ok(match memory.delete_by_request(request) { Some(item) => { self.database.delete(item.id)?; @@ -64,20 +64,17 @@ impl Bookmark { /// Check `request` exists in the memory index pub fn is_match_request(&self, request: &str) -> bool { - self.memory.write().unwrap().is_match_request(request) + self.memory.borrow_mut().is_match_request(request) } /// Find Items match `request` pub fn contains_request(&self, request: &str, limit: Option) -> Vec { - self.memory - .write() - .unwrap() - .contains_request(request, limit) + self.memory.borrow_mut().contains_request(request, limit) } /// Get recent Items vector from `memory`, sorted by `ID` DESC pub fn recent(&self, limit: Option) -> Vec { - self.memory.read().unwrap().recent(limit) + self.memory.borrow().recent(limit) } } diff --git a/src/profile/history.rs b/src/profile/history.rs index 6ff01056..f4031c71 100644 --- a/src/profile/history.rs +++ b/src/profile/history.rs @@ -10,11 +10,11 @@ use memory::Memory; use r2d2::Pool; use r2d2_sqlite::SqliteConnectionManager; use sqlite::Transaction; -use std::sync::RwLock; +use std::cell::RefCell; pub struct History { - database: Database, // permanent storage - memory: RwLock, // fast search index + database: Database, // permanent storage + memory: RefCell, // fast search index } impl History { @@ -24,10 +24,10 @@ impl History { pub fn build(database_pool: &Pool, profile_id: i64) -> Result { // Init children components let database = Database::build(database_pool, profile_id); - let memory = RwLock::new(Memory::new()); + let memory = RefCell::new(Memory::new()); for item in database.records(None, None)? { - memory.write().unwrap().add(item) + memory.borrow_mut().add(item) } // Return new `Self` @@ -37,7 +37,7 @@ impl History { // Actions pub fn save(&self) -> Result<()> { - for item in self.memory.read().unwrap().items() { + for item in self.memory.borrow().items() { if !item.is_saved { match item.id { Some(_) => { @@ -56,7 +56,7 @@ impl History { /// Create new history record pub fn open(&self, request: GString, title: Option) { - let mut memory = self.memory.write().unwrap(); + let mut memory = self.memory.borrow_mut(); if !memory.open(&request) { memory.add(Item { id: None, @@ -71,24 +71,24 @@ impl History { /// Close existing history record pub fn close(&self, request: &str) { - self.memory.write().unwrap().close(request) + self.memory.borrow_mut().close(request) } // Getters /// Get recently `opened` Items vector from the memory index, sorted by ASC pub fn recently_opened(&self, limit: Option) -> Vec { - self.memory.read().unwrap().recently_opened(limit) + self.memory.borrow().recently_opened(limit) } /// Get recently `closed` Items vector from the memory index, sorted by ASC pub fn recently_closed(&self, limit: Option) -> Vec { - self.memory.read().unwrap().recently_closed(limit) + self.memory.borrow().recently_closed(limit) } /// Get unordered Items vector that contains given `request` pub fn contains_request(&self, request: &str, limit: Option) -> Vec { - self.memory.read().unwrap().contains_request(request, limit) + self.memory.borrow().contains_request(request, limit) } // @TODO close memory member } diff --git a/src/profile/identity/auth/memory.rs b/src/profile/identity/auth/memory.rs index 57361232..2920a824 100644 --- a/src/profile/identity/auth/memory.rs +++ b/src/profile/identity/auth/memory.rs @@ -2,11 +2,11 @@ pub mod auth; use anyhow::{Result, bail}; pub use auth::Auth; -use std::{collections::HashMap, sync::RwLock}; +use std::{cell::RefCell, collections::HashMap}; /// Reduce disk usage by cache Auth index in memory pub struct Memory { - index: RwLock>, + index: RefCell>, } impl Default for Memory { @@ -21,7 +21,7 @@ impl Memory { /// Create new `Self` pub fn new() -> Self { Self { - index: RwLock::new(HashMap::new()), + index: RefCell::new(HashMap::new()), } } @@ -31,7 +31,7 @@ impl Memory { /// * validate record with same key does not exist yet pub fn add(&self, scope: String, profile_identity_id: i64) -> Result<()> { // Borrow shared index access - let mut index = self.index.write().unwrap(); + let mut index = self.index.borrow_mut(); // Prevent existing key overwrite if index.contains_key(&scope) { @@ -47,7 +47,7 @@ impl Memory { /// Cleanup index pub fn clear(&self) -> Result<()> { - let mut index = self.index.write().unwrap(); + let mut index = self.index.borrow_mut(); index.clear(); if index.is_empty() { Ok(()) @@ -62,7 +62,7 @@ impl Memory { pub fn match_scope(&self, scope: &str) -> Option { let mut result = Vec::new(); - for (value, &profile_identity_id) in self.index.read().unwrap().iter() { + for (value, &profile_identity_id) in self.index.borrow().iter() { if scope.starts_with(value) { result.push(Auth { profile_identity_id, @@ -83,7 +83,7 @@ impl Memory { /// * see also parent `is_match_request` pub fn total(&self, profile_identity_id: i64) -> usize { let mut total = 0; - for (_, _profile_identity_id) in self.index.read().unwrap().iter() { + for (_, _profile_identity_id) in self.index.borrow().iter() { if *_profile_identity_id == profile_identity_id { total += 1 } diff --git a/src/profile/identity/memory.rs b/src/profile/identity/memory.rs index 25fbfbf2..ecc3a8b2 100644 --- a/src/profile/identity/memory.rs +++ b/src/profile/identity/memory.rs @@ -1,9 +1,9 @@ use anyhow::{Result, bail}; -use std::{collections::HashMap, sync::RwLock}; +use std::{cell::RefCell, collections::HashMap}; /// Reduce disk usage by cache index in memory pub struct Memory { - index: RwLock>, + index: RefCell>, } impl Default for Memory { @@ -18,7 +18,7 @@ impl Memory { /// Create new `Self` pub fn new() -> Self { Self { - index: RwLock::new(HashMap::new()), + index: RefCell::new(HashMap::new()), } } @@ -28,7 +28,7 @@ impl Memory { /// * validate record with same key does not exist yet pub fn add(&self, profile_identity_id: i64, pem: String) -> Result<()> { // Borrow shared index access - let mut index = self.index.write().unwrap(); + let mut index = self.index.borrow_mut(); // Prevent existing key overwrite if index.contains_key(&profile_identity_id) { @@ -44,7 +44,7 @@ impl Memory { /// Get `pem` clone by `id` from memory index pub fn get(&self, id: i64) -> Result { - match self.index.read().unwrap().get(&id) { + match self.index.borrow().get(&id) { Some(pem) => Ok(pem.clone()), None => bail!("Record `{id}` not found in memory index"), } @@ -52,7 +52,7 @@ impl Memory { /// Cleanup index pub fn clear(&self) -> Result<()> { - let mut index = self.index.write().unwrap(); + let mut index = self.index.borrow_mut(); index.clear(); if index.is_empty() { Ok(()) diff --git a/src/profile/search/memory.rs b/src/profile/search/memory.rs index 66d7af53..71da28ac 100644 --- a/src/profile/search/memory.rs +++ b/src/profile/search/memory.rs @@ -1,9 +1,9 @@ use super::database::Row; -use std::sync::RwLock; +use std::cell::RefCell; /// Reduce disk usage by cache Bookmarks index in memory pub struct Memory { - index: RwLock>, + index: RefCell>, } impl Memory { @@ -12,7 +12,7 @@ impl Memory { /// Create new `Self` pub fn init() -> Self { Self { - index: RwLock::new(Vec::new()), + index: RefCell::new(Vec::new()), } } @@ -20,7 +20,7 @@ impl Memory { /// Add new record pub fn push(&self, id: i64, query: String, is_default: bool) { - self.index.write().unwrap().push(Row { + self.index.borrow_mut().push(Row { id, query, is_default, @@ -29,19 +29,19 @@ impl Memory { /// Clear all records pub fn clear(&self) { - self.index.write().unwrap().clear() + self.index.borrow_mut().clear() } // Getters /// Get all records pub fn records(&self) -> Vec { - self.index.read().unwrap().clone() + self.index.borrow().clone() } /// Get all records pub fn default(&self) -> Option { - for record in self.index.read().unwrap().iter() { + for record in self.index.borrow().iter() { if record.is_default { return Some(record.clone()); } diff --git a/src/profile/tofu.rs b/src/profile/tofu.rs index e90dd140..65208f02 100644 --- a/src/profile/tofu.rs +++ b/src/profile/tofu.rs @@ -9,14 +9,14 @@ use r2d2::Pool; use r2d2_sqlite::SqliteConnectionManager; use sourceview::prelude::TlsCertificateExt; use sqlite::Transaction; -use std::sync::RwLock; +use std::cell::RefCell; /// TOFU wrapper for the Gemini protocol /// /// https://geminiprotocol.net/docs/protocol-specification.gmi#tls-server-certificate-validation pub struct Tofu { database: Database, - memory: RwLock>, + memory: RefCell>, } impl Tofu { @@ -26,11 +26,11 @@ impl Tofu { let database = Database::init(database_pool, profile_id); let records = database.records()?; - let memory = RwLock::new(Vec::with_capacity(records.len())); + let memory = RefCell::new(Vec::with_capacity(records.len())); { // build in-memory index... - let mut m = memory.write().unwrap(); + let mut m = memory.borrow_mut(); for r in records { m.push(Certificate::from_db(Some(r.id), &r.pem, r.time)?) } @@ -43,8 +43,7 @@ impl Tofu { pub fn add(&self, tls_certificate: TlsCertificate) -> Result<()> { self.memory - .write() - .unwrap() + .borrow_mut() .push(Certificate::from_tls_certificate(tls_certificate)?); Ok(()) } @@ -59,7 +58,7 @@ impl Tofu { } if let Some(h) = uri.host() { let k = f(&h); - let m = self.memory.read().unwrap(); + let m = self.memory.borrow(); let b: Vec = m .iter() .filter_map(|certificate| { @@ -80,7 +79,7 @@ impl Tofu { /// Save in-memory index to the permanent database (on app close) pub fn save(&self) -> Result<()> { - for c in self.memory.read().unwrap().iter() { + for c in self.memory.borrow().iter() { if c.id().is_none() { self.database.add(c.time(), &c.pem())?; }