remove direct memory access

This commit is contained in:
yggverse 2025-03-14 12:51:33 +02:00
parent 33369e31ea
commit 19a07cdf1d
32 changed files with 112 additions and 111 deletions

View File

@ -10,12 +10,12 @@ use gtk::{
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt}, prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt},
}; };
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
const APPLICATION_ID: &str = "io.github.yggverse.Yoda"; const APPLICATION_ID: &str = "io.github.yggverse.Yoda";
pub struct App { pub struct App {
profile: Rc<Profile>, profile: Arc<Profile>,
application: Application, application: Application,
} }
@ -30,7 +30,7 @@ impl App {
.build(); .build();
// Init components // Init components
let profile = Rc::new(profile); let profile = Arc::new(profile);
let browser = Rc::new(Browser::build(&profile)); let browser = Rc::new(Browser::build(&profile));
// Prevent startup warning @TODO // Prevent startup warning @TODO

View File

@ -18,7 +18,7 @@ use gtk::{
FileLauncher, FileLauncher,
}; };
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
pub struct Browser { pub struct Browser {
pub action: Rc<Action>, pub action: Rc<Action>,
@ -30,7 +30,7 @@ impl Browser {
// Constructors // Constructors
/// Build new `Self` /// Build new `Self`
pub fn build(profile: &Rc<Profile>) -> Browser { pub fn build(profile: &Arc<Profile>) -> Browser {
// Init components // Init components
let action = Rc::new(Action::new()); let action = Rc::new(Action::new());
let window = Rc::new(Window::build(profile, &action)); let window = Rc::new(Window::build(profile, &action));

View File

@ -11,7 +11,7 @@ use anyhow::Result;
use gtk::{prelude::BoxExt, Box, Orientation}; use gtk::{prelude::BoxExt, Box, Orientation};
use header::Header; use header::Header;
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
use tab::Tab; use tab::Tab;
pub struct Window { pub struct Window {
@ -24,7 +24,7 @@ impl Window {
// Constructors // Constructors
/// Build new `Self` /// Build new `Self`
pub fn build(profile: &Rc<Profile>, browser_action: &Rc<BrowserAction>) -> Self { pub fn build(profile: &Arc<Profile>, browser_action: &Rc<BrowserAction>) -> Self {
// Init local actions // Init local actions
let action = Rc::new(Action::new()); let action = Rc::new(Action::new());

View File

@ -4,12 +4,12 @@ use super::{Action as WindowAction, BrowserAction, Profile};
use adw::{TabView, ToolbarView}; use adw::{TabView, ToolbarView};
use bar::Bar; use bar::Bar;
use gtk::Box; use gtk::Box;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
pub trait Header { pub trait Header {
fn header( fn header(
action: (&Rc<BrowserAction>, &Rc<WindowAction>), action: (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>, profile: &Arc<Profile>,
tab_view: &TabView, tab_view: &TabView,
) -> Self; ) -> Self;
} }
@ -20,7 +20,7 @@ impl Header for ToolbarView {
/// Build new `Self` /// Build new `Self`
fn header( fn header(
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>), (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>, profile: &Arc<Profile>,
tab_view: &TabView, tab_view: &TabView,
) -> Self { ) -> Self {
let toolbar_view = ToolbarView::builder().build(); let toolbar_view = ToolbarView::builder().build();

View File

@ -9,12 +9,12 @@ use tab::Tab;
use super::{BrowserAction, Profile, WindowAction}; use super::{BrowserAction, Profile, WindowAction};
use adw::{TabBar, TabView}; use adw::{TabBar, TabView};
use gtk::{prelude::BoxExt, Box, MenuButton, Orientation}; use gtk::{prelude::BoxExt, Box, MenuButton, Orientation};
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
pub trait Bar { pub trait Bar {
fn bar( fn bar(
action: (&Rc<BrowserAction>, &Rc<WindowAction>), action: (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>, profile: &Arc<Profile>,
view: &TabView, view: &TabView,
) -> Self; ) -> Self;
} }
@ -25,7 +25,7 @@ impl Bar for Box {
/// Build new `Self` /// Build new `Self`
fn bar( fn bar(
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>), (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>, profile: &Arc<Profile>,
view: &TabView, view: &TabView,
) -> Self { ) -> Self {
let g_box = Box::builder() let g_box = Box::builder()

View File

@ -6,13 +6,13 @@ use gtk::{
Align, MenuButton, Align, MenuButton,
}; };
use indexmap::IndexMap; use indexmap::IndexMap;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
// Config options // Config options
const LABEL_MAX_LENGTH: usize = 28; const LABEL_MAX_LENGTH: usize = 28;
pub trait Menu { pub trait Menu {
fn menu(action: (&Rc<BrowserAction>, &Rc<WindowAction>), profile: &Rc<Profile>) -> Self; fn menu(action: (&Rc<BrowserAction>, &Rc<WindowAction>), profile: &Arc<Profile>) -> Self;
} }
#[rustfmt::skip] // @TODO template builder? #[rustfmt::skip] // @TODO template builder?
@ -22,7 +22,7 @@ impl Menu for MenuButton {
/// Build new `Self` /// Build new `Self`
fn menu( fn menu(
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>), (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
profile: &Rc<Profile>, profile: &Arc<Profile>,
) -> Self { ) -> Self {
// Main // Main
let main = gio::Menu::new(); let main = gio::Menu::new();

View File

@ -13,13 +13,13 @@ pub use item::Item;
use menu::Menu; use menu::Menu;
use sourceview::prelude::IsA; use sourceview::prelude::IsA;
use sqlite::Transaction; use sqlite::Transaction;
use std::{cell::RefCell, collections::HashMap, rc::Rc}; use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
// Main // Main
pub struct Tab { pub struct Tab {
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>, window_action: Rc<WindowAction>,
profile: Rc<Profile>, profile: Arc<Profile>,
index: Rc<RefCell<HashMap<TabPage, Rc<Item>>>>, index: Rc<RefCell<HashMap<TabPage, Rc<Item>>>>,
pub action: Rc<Action>, pub action: Rc<Action>,
pub tab_view: TabView, pub tab_view: TabView,
@ -30,7 +30,7 @@ impl Tab {
/// Build new `Self` /// Build new `Self`
pub fn build( pub fn build(
profile: &Rc<Profile>, profile: &Arc<Profile>,
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>), (browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
) -> Self { ) -> Self {
let action = Rc::new(Action::new()); let action = Rc::new(Action::new());

View File

@ -15,7 +15,7 @@ use gtk::{
}; };
use page::Page; use page::Page;
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
pub struct Item { pub struct Item {
// Multi-protocol handler // Multi-protocol handler
@ -32,7 +32,7 @@ impl Item {
/// Build new `Self` /// Build new `Self`
pub fn build( pub fn build(
(tab_page, target_child): (&TabPage, &Box), (tab_page, target_child): (&TabPage, &Box),
profile: &Rc<Profile>, profile: &Arc<Profile>,
(browser_action, window_action, tab_action): ( (browser_action, window_action, tab_action): (
&Rc<BrowserAction>, &Rc<BrowserAction>,
&Rc<WindowAction>, &Rc<WindowAction>,

View File

@ -9,21 +9,21 @@ use gtk::{
glib::{Uri, UriFlags}, glib::{Uri, UriFlags},
prelude::{ActionExt, CancellableExt}, prelude::{ActionExt, CancellableExt},
}; };
use std::{cell::Cell, rc::Rc}; use std::{cell::Cell, rc::Rc, sync::Arc};
/// Multi-protocol client API for tab `Item` /// Multi-protocol client API for tab `Item`
pub struct Client { pub struct Client {
cancellable: Cell<Cancellable>, cancellable: Cell<Cancellable>,
driver: Rc<Driver>, driver: Rc<Driver>,
page: Rc<Page>, page: Rc<Page>,
profile: Rc<Profile>, profile: Arc<Profile>,
} }
impl Client { impl Client {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn init(profile: &Rc<Profile>, page: &Rc<Page>) -> Self { pub fn init(profile: &Arc<Profile>, page: &Rc<Page>) -> Self {
Self { Self {
cancellable: Cell::new(Cancellable::new()), cancellable: Cell::new(Cancellable::new()),
driver: Rc::new(Driver::build(page)), driver: Rc::new(Driver::build(page)),
@ -108,7 +108,7 @@ impl Client {
/// Create request using async DNS resolver (slow method) /// 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) /// * return suggestion [Uri](https://docs.gtk.org/glib/struct.Uri.html) on failure (to handle as redirect)
fn lookup( fn lookup(
profile: &Rc<Profile>, profile: &Arc<Profile>,
query: &str, query: &str,
cancellable: Cancellable, cancellable: Cancellable,
callback: impl FnOnce(Rc<Feature>, Cancellable, Result<Uri, String>) + 'static, callback: impl FnOnce(Rc<Feature>, Cancellable, Result<Uri, String>) + 'static,

View File

@ -12,10 +12,10 @@ use input::Input;
use navigation::Navigation; use navigation::Navigation;
use search::Search; use search::Search;
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
pub struct Page { pub struct Page {
pub profile: Rc<Profile>, pub profile: Arc<Profile>,
// Actions // Actions
pub browser_action: Rc<BrowserAction>, pub browser_action: Rc<BrowserAction>,
pub item_action: Rc<ItemAction>, pub item_action: Rc<ItemAction>,
@ -38,7 +38,7 @@ impl Page {
// Constructors // Constructors
pub fn build( pub fn build(
profile: &Rc<Profile>, profile: &Arc<Profile>,
(browser_action, window_action, tab_action, item_action): ( (browser_action, window_action, tab_action, item_action): (
&Rc<BrowserAction>, &Rc<BrowserAction>,
&Rc<WindowAction>, &Rc<WindowAction>,

View File

@ -18,7 +18,7 @@ use home::Home;
use reload::Reload; use reload::Reload;
use request::Request; use request::Request;
use sqlite::Transaction; use sqlite::Transaction;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
const MARGIN: i32 = 6; const MARGIN: i32 = 6;
const SPACING: i32 = 6; const SPACING: i32 = 6;
@ -30,7 +30,7 @@ pub struct Navigation {
impl Navigation { impl Navigation {
pub fn build( pub fn build(
profile: &Rc<Profile>, profile: &Arc<Profile>,
(window_action, tab_action, item_action): ( (window_action, tab_action, item_action): (
&Rc<WindowAction>, &Rc<WindowAction>,
&Rc<TabAction>, &Rc<TabAction>,

View File

@ -3,18 +3,18 @@ use gtk::{
prelude::{ActionExt, ButtonExt, EditableExt, WidgetExt}, prelude::{ActionExt, ButtonExt, EditableExt, WidgetExt},
Button, Entry, Button, Entry,
}; };
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
const ICON_NAME: (&str, &str) = ("non-starred-symbolic", "starred-symbolic"); const ICON_NAME: (&str, &str) = ("non-starred-symbolic", "starred-symbolic");
const TOOLTIP_TEXT: (&str, &str) = ("Add Bookmark", "Remove Bookmark"); const TOOLTIP_TEXT: (&str, &str) = ("Add Bookmark", "Remove Bookmark");
pub trait Bookmark { pub trait Bookmark {
fn bookmark(action: &Rc<WindowAction>, profile: &Rc<Profile>, request: &Entry) -> Self; fn bookmark(action: &Rc<WindowAction>, profile: &Arc<Profile>, request: &Entry) -> Self;
fn update(&self, profile: &Profile, request: &Entry); fn update(&self, profile: &Profile, request: &Entry);
} }
impl Bookmark for Button { impl Bookmark for Button {
fn bookmark(action: &Rc<WindowAction>, profile: &Rc<Profile>, request: &Entry) -> Self { fn bookmark(action: &Rc<WindowAction>, profile: &Arc<Profile>, request: &Entry) -> Self {
let button = Button::builder() let button = Button::builder()
.action_name(format!( .action_name(format!(
"{}.{}", "{}.{}",

View File

@ -14,7 +14,7 @@ use gtk::{
}; };
use primary_icon::PrimaryIcon; use primary_icon::PrimaryIcon;
use sqlite::Transaction; use sqlite::Transaction;
use std::{cell::Cell, rc::Rc}; use std::{cell::Cell, rc::Rc, sync::Arc};
use suggestion::Suggestion; use suggestion::Suggestion;
const PREFIX_DOWNLOAD: &str = "download:"; const PREFIX_DOWNLOAD: &str = "download:";
@ -23,14 +23,14 @@ const PREFIX_SOURCE: &str = "source:";
pub struct Request { pub struct Request {
pub entry: Entry, pub entry: Entry,
suggestion: Rc<Suggestion>, suggestion: Rc<Suggestion>,
profile: Rc<Profile>, profile: Arc<Profile>,
} }
impl Request { impl Request {
// Constructors // Constructors
/// Build new `Self` /// Build new `Self`
pub fn build(item_action: &Rc<ItemAction>, profile: &Rc<Profile>) -> Self { pub fn build(item_action: &Rc<ItemAction>, profile: &Arc<Profile>) -> Self {
// Init main widget // Init main widget
let entry = Entry::builder() let entry = Entry::builder()
.placeholder_text("URL or search term...") .placeholder_text("URL or search term...")
@ -327,7 +327,7 @@ fn update_secondary_icon(entry: &Entry) {
} }
/// Present Identity [AlertDialog](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AlertDialog.html) for `Self` /// Present Identity [AlertDialog](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AlertDialog.html) for `Self`
fn show_identity_dialog(entry: &Entry, profile: &Rc<Profile>) { fn show_identity_dialog(entry: &Entry, profile: &Arc<Profile>) {
// connect identity traits // connect identity traits
use identity::{Common, Unsupported}; use identity::{Common, Unsupported};
if let Some(uri) = uri(entry) { if let Some(uri) = uri(entry) {
@ -353,7 +353,7 @@ fn show_identity_dialog(entry: &Entry, profile: &Rc<Profile>) {
} }
/// Present Search providers [AlertDialog](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AlertDialog.html) for `Self` /// 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: &Rc<Profile>) { fn show_search_dialog(entry: &Entry, profile: &Arc<Profile>) {
use search::Search; use search::Search;
AlertDialog::search(profile).present(Some(entry)) AlertDialog::search(profile).present(Some(entry))
} }

View File

@ -5,13 +5,16 @@ use crate::Profile;
use action::Action as WidgetAction; use action::Action as WidgetAction;
use adw::AlertDialog; use adw::AlertDialog;
use gtk::{glib::Uri, prelude::EditableExt}; use gtk::{glib::Uri, prelude::EditableExt};
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
// Select options // Select options
pub trait Common { pub trait Common {
fn common(profile: &Rc<Profile>, request: &Uri, callback: &Rc<impl Fn(bool) + 'static>) fn common(
-> Self; profile: &Arc<Profile>,
request: &Uri,
callback: &Rc<impl Fn(bool) + 'static>,
) -> Self;
} }
impl Common for AlertDialog { impl Common for AlertDialog {
@ -19,7 +22,7 @@ impl Common for AlertDialog {
/// Create new `Self` /// Create new `Self`
fn common( fn common(
profile: &Rc<Profile>, profile: &Arc<Profile>,
request: &Uri, request: &Uri,
callback: &Rc<impl Fn(bool) + 'static>, callback: &Rc<impl Fn(bool) + 'static>,
) -> Self { ) -> Self {

View File

@ -19,7 +19,7 @@ use gtk::{
prelude::{BoxExt, WidgetExt}, prelude::{BoxExt, WidgetExt},
Box, Button, Entry, Orientation, Box, Button, Entry, Orientation,
}; };
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
pub struct Form { pub struct Form {
// pub action_widget: Rc<Action>, // pub action_widget: Rc<Action>,
@ -30,14 +30,14 @@ pub struct Form {
pub name: Entry, pub name: Entry,
pub save: Rc<Save>, pub save: Rc<Save>,
pub g_box: Box, pub g_box: Box,
profile: Rc<Profile>, profile: Arc<Profile>,
} }
impl Form { impl Form {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn build(widget_action: &Rc<WidgetAction>, profile: &Rc<Profile>, request: &Uri) -> Self { pub fn build(widget_action: &Rc<WidgetAction>, profile: &Arc<Profile>, request: &Uri) -> Self {
// Init components // Init components
let list = Rc::new(List::build(widget_action, profile, request)); let list = Rc::new(List::build(widget_action, profile, request));
let file = Rc::new(File::build(widget_action)); let file = Rc::new(File::build(widget_action));

View File

@ -9,7 +9,7 @@ use gtk::{
prelude::{ButtonExt, WidgetExt}, prelude::{ButtonExt, WidgetExt},
Button, Button,
}; };
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
// Defaults // Defaults
@ -30,7 +30,7 @@ impl Drop {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn build(profile: &Rc<Profile>, list: &Rc<List>) -> Self { pub fn build(profile: &Arc<Profile>, list: &Rc<List>) -> Self {
// Init main widget // Init main widget
let button = Button::builder() let button = Button::builder()
.label(LABEL) .label(LABEL)

View File

@ -8,12 +8,12 @@ use gtk::{
prelude::{ButtonExt, WidgetExt}, prelude::{ButtonExt, WidgetExt},
Button, Button,
}; };
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
pub trait Exit { pub trait Exit {
fn exit( fn exit(
widget_action: &Rc<WidgetAction>, widget_action: &Rc<WidgetAction>,
profile: &Rc<Profile>, profile: &Arc<Profile>,
list: &Rc<List>, list: &Rc<List>,
request: &Uri, request: &Uri,
) -> Self; ) -> Self;
@ -25,7 +25,7 @@ impl Exit for Button {
/// Create new `Self` /// Create new `Self`
fn exit( fn exit(
widget_action: &Rc<WidgetAction>, widget_action: &Rc<WidgetAction>,
profile: &Rc<Profile>, profile: &Arc<Profile>,
list: &Rc<List>, list: &Rc<List>,
request: &Uri, request: &Uri,
) -> Self { ) -> Self {

View File

@ -1,5 +1,5 @@
pub mod item; pub mod item;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
use item::Item; use item::Item;
@ -25,7 +25,7 @@ impl List {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn build(widget_action: &Rc<WidgetAction>, profile: &Rc<Profile>, request: &Uri) -> Self { pub fn build(widget_action: &Rc<WidgetAction>, profile: &Arc<Profile>, request: &Uri) -> Self {
// Init dropdown items // Init dropdown items
let guest_session = Item::new_guest_session(); let guest_session = Item::new_guest_session();
let generate_pem = Item::new_generate_pem(); let generate_pem = Item::new_generate_pem();

View File

@ -14,7 +14,7 @@ use gtk::{
gio::TlsCertificate, gio::TlsCertificate,
glib::{self, Object}, glib::{self, Object},
}; };
use std::rc::Rc; use std::sync::Arc;
glib::wrapper! { glib::wrapper! {
pub struct Item(ObjectSubclass<imp::Item>); pub struct Item(ObjectSubclass<imp::Item>);
@ -54,7 +54,7 @@ impl Item {
} }
pub fn new_profile_identity_id( pub fn new_profile_identity_id(
profile: &Rc<Profile>, profile: &Arc<Profile>,
profile_identity_id: i64, profile_identity_id: i64,
auth_url: &str, auth_url: &str,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
@ -96,7 +96,7 @@ impl Item {
// Actions // Actions
/// Update properties for `Self` for given `Profile` and `auth_url` /// Update properties for `Self` for given `Profile` and `auth_url`
pub fn update(&self, profile: &Rc<Profile>, auth_url: &str) -> Result<(), Error> { pub fn update(&self, profile: &Arc<Profile>, auth_url: &str) -> Result<(), Error> {
// Update item depending on value type // Update item depending on value type
match self.value_enum() { match self.value_enum() {
Value::ProfileIdentityId(profile_identity_id) => { Value::ProfileIdentityId(profile_identity_id) => {

View File

@ -1,8 +1,8 @@
use crate::profile::Profile; use crate::profile::Profile;
use std::rc::Rc; use std::sync::Arc;
pub fn new_for_profile_identity_id( pub fn new_for_profile_identity_id(
profile: &Rc<Profile>, profile: &Arc<Profile>,
profile_identity_id: i64, profile_identity_id: i64,
auth_url: &str, auth_url: &str,
) -> bool { ) -> bool {

View File

@ -9,7 +9,7 @@ use gtk::{
prelude::{ButtonExt, FileExt, OutputStreamExtManual, WidgetExt}, prelude::{ButtonExt, FileExt, OutputStreamExtManual, WidgetExt},
Button, FileDialog, FileFilter, Window, Button, FileDialog, FileFilter, Window,
}; };
use std::{path::MAIN_SEPARATOR, rc::Rc}; use std::{path::MAIN_SEPARATOR, rc::Rc, sync::Arc};
const LABEL: &str = "Export"; const LABEL: &str = "Export";
const TOOLTIP_TEXT: &str = "Export selected identity to file"; const TOOLTIP_TEXT: &str = "Export selected identity to file";
@ -24,7 +24,7 @@ impl Save {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn build(profile: &Rc<Profile>, list: &Rc<List>) -> Self { pub fn build(profile: &Arc<Profile>, list: &Rc<List>) -> Self {
// Init main widget // Init main widget
let button = Button::builder() let button = Button::builder()
.label(LABEL) .label(LABEL)
@ -46,7 +46,7 @@ impl Save {
button.set_sensitive(false); button.set_sensitive(false);
// Create PEM file based on option ID selected // Create PEM file based on option ID selected
match Certificate::build(profile.clone(), profile_identity_id) { match Certificate::build(&profile, profile_identity_id) {
Ok(certificate) => { Ok(certificate) => {
// Init file filters related with PEM extension // Init file filters related with PEM extension
let filters = ListStore::new::<FileFilter>(); let filters = ListStore::new::<FileFilter>();

View File

@ -2,7 +2,7 @@ use anyhow::{bail, Result};
use crate::profile::Profile; use crate::profile::Profile;
use gtk::{gio::TlsCertificate, prelude::TlsCertificateExt}; use gtk::{gio::TlsCertificate, prelude::TlsCertificateExt};
use std::rc::Rc; use std::sync::Arc;
/// Certificate details holder for export to file action /// Certificate details holder for export to file action
pub struct Certificate { pub struct Certificate {
@ -14,7 +14,7 @@ impl Certificate {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn build(profile: Rc<Profile>, profile_identity_id: i64) -> Result<Self> { pub fn build(profile: &Arc<Profile>, profile_identity_id: i64) -> Result<Self> {
let record = profile.identity.database.record(profile_identity_id)?; let record = profile.identity.database.record(profile_identity_id)?;
match record { match record {
Some(identity) => Ok(Self { Some(identity) => Ok(Self {

View File

@ -10,6 +10,7 @@ use form::{list::item::Value, list::Item, Form, Query};
use gtk::prelude::{EditableExt, WidgetExt}; use gtk::prelude::{EditableExt, WidgetExt};
use sourceview::prelude::CastNone; use sourceview::prelude::CastNone;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc;
// Response variants // Response variants
const RESPONSE_APPLY: (&str, &str) = ("apply", "Apply"); const RESPONSE_APPLY: (&str, &str) = ("apply", "Apply");
@ -17,14 +18,14 @@ const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel");
// const RESPONSE_MANAGE: (&str, &str) = ("manage", "Manage"); // const RESPONSE_MANAGE: (&str, &str) = ("manage", "Manage");
pub trait Search { pub trait Search {
fn search(profile: &Rc<Profile>) -> Self; fn search(profile: &Arc<Profile>) -> Self;
} }
impl Search for AlertDialog { impl Search for AlertDialog {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
fn search(profile: &Rc<Profile>) -> Self { fn search(profile: &Arc<Profile>) -> Self {
// Init child container // Init child container
let form = Rc::new(Form::build(profile)); let form = Rc::new(Form::build(profile));

View File

@ -7,7 +7,7 @@ use drop::Drop;
use gtk::{prelude::BoxExt, Box, Button, Entry, Orientation}; use gtk::{prelude::BoxExt, Box, Button, Entry, Orientation};
use list::List; use list::List;
pub use query::Query; pub use query::Query;
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
pub struct Form { pub struct Form {
pub drop: Button, pub drop: Button,
@ -20,7 +20,7 @@ impl Form {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn build(profile: &Rc<Profile>) -> Self { pub fn build(profile: &Arc<Profile>) -> Self {
// Init components // Init components
let list = Rc::new(List::build(profile)); let list = Rc::new(List::build(profile));
let query = Entry::query(); let query = Entry::query();

View File

@ -9,17 +9,17 @@ use gtk::{
prelude::{ButtonExt, WidgetExt}, prelude::{ButtonExt, WidgetExt},
Button, Button,
}; };
use std::rc::Rc; use std::{rc::Rc, sync::Arc};
pub trait Drop { pub trait Drop {
fn drop(profile: &Rc<Profile>, list: &Rc<List>) -> Self; fn drop(profile: &Arc<Profile>, list: &Rc<List>) -> Self;
} }
impl Drop for Button { impl Drop for Button {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
fn drop(profile: &Rc<Profile>, list: &Rc<List>) -> Self { fn drop(profile: &Arc<Profile>, list: &Rc<List>) -> Self {
// Defaults // Defaults
const LABEL: &str = "Delete"; const LABEL: &str = "Delete";

View File

@ -10,7 +10,7 @@ use gtk::{
Align, Box, DropDown, Label, ListItem, Orientation, SignalListItemFactory, Align, Box, DropDown, Label, ListItem, Orientation, SignalListItemFactory,
}; };
pub use item::Item; pub use item::Item;
use std::rc::Rc; use std::sync::Arc;
pub struct List { pub struct List {
pub dropdown: DropDown, pub dropdown: DropDown,
@ -21,7 +21,7 @@ impl List {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn build(profile: &Rc<Profile>) -> Self { pub fn build(profile: &Arc<Profile>) -> Self {
// Init dropdown items // Init dropdown items
let new_search_provider = Item::add(); let new_search_provider = Item::add();

View File

@ -17,14 +17,14 @@ use gtk::{
}; };
pub use item::Item; pub use item::Item;
use sourceview::prelude::ListModelExt; use sourceview::prelude::ListModelExt;
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc, sync::Arc};
pub struct Suggestion { pub struct Suggestion {
list_store: ListStore, list_store: ListStore,
list_view: ListView, list_view: ListView,
single_selection: SingleSelection, single_selection: SingleSelection,
request: Entry, request: Entry,
profile: Rc<Profile>, profile: Arc<Profile>,
popover: Popover, popover: Popover,
pub signal_handler_id: Rc<RefCell<Option<SignalHandlerId>>>, pub signal_handler_id: Rc<RefCell<Option<SignalHandlerId>>>,
} }
@ -33,7 +33,7 @@ impl Suggestion {
// Constructors // Constructors
/// Create new `Self` /// Create new `Self`
pub fn build(profile: &Rc<Profile>, request: &Entry) -> Self { pub fn build(profile: &Arc<Profile>, request: &Entry) -> Self {
let signal_handler_id = Rc::new(RefCell::new(None)); let signal_handler_id = Rc::new(RefCell::new(None));
let list_store = ListStore::new::<Item>(); let list_store = ListStore::new::<Item>();
let single_selection = { let single_selection = {
@ -162,15 +162,12 @@ impl Suggestion {
let query = self.request.text(); let query = self.request.text();
let popover = self.popover.clone(); let popover = self.popover.clone();
let list_store = self.list_store.clone(); let list_store = self.list_store.clone();
let profile = self.profile.clone();
let history = self.profile.history.memory.clone(); // @TODO
let bookmark = self.profile.bookmark.memory.clone(); // @TODO
gtk::glib::spawn_future_local(async move { gtk::glib::spawn_future_local(async move {
let list_items = gtk::gio::spawn_blocking(move || { let list_items = gtk::gio::spawn_blocking(move || {
let result = history let result = profile
.read() .history
.unwrap()
.contains_request(&query, limit) .contains_request(&query, limit)
.into_iter() .into_iter()
.sorted_by(|a, b| Ord::cmp(&b.opened.count, &a.opened.count)); .sorted_by(|a, b| Ord::cmp(&b.opened.count, &a.opened.count));
@ -184,7 +181,7 @@ impl Suggestion {
list_items.push(( list_items.push((
title, title,
subtitle, subtitle,
bookmark.read().unwrap().is_match_request(&item.request), profile.bookmark.is_match_request(&item.request),
item.request, item.request,
)) ))
} }

View File

@ -10,12 +10,12 @@ use memory::Memory;
use r2d2::Pool; use r2d2::Pool;
use r2d2_sqlite::SqliteConnectionManager; use r2d2_sqlite::SqliteConnectionManager;
use sqlite::Transaction; use sqlite::Transaction;
use std::sync::{Arc, RwLock}; use std::sync::RwLock;
pub struct Bookmark { pub struct Bookmark {
database: Database, // permanent storage database: Database, // permanent storage
pub memory: Arc<RwLock<Memory>>, // fast search index memory: RwLock<Memory>, // fast search index
} // @TODO close memory member, Arc entire profile instead }
impl Bookmark { impl Bookmark {
// Constructors // Constructors
@ -24,7 +24,7 @@ impl Bookmark {
pub fn build(database_pool: &Pool<SqliteConnectionManager>, profile_id: i64) -> Result<Self> { pub fn build(database_pool: &Pool<SqliteConnectionManager>, profile_id: i64) -> Result<Self> {
// Init children components // Init children components
let database = Database::new(database_pool, profile_id); let database = Database::new(database_pool, profile_id);
let memory = Arc::new(RwLock::new(Memory::new())); let memory = RwLock::new(Memory::new());
// Build initial index // Build initial index
{ {

View File

@ -10,12 +10,12 @@ use memory::Memory;
use r2d2::Pool; use r2d2::Pool;
use r2d2_sqlite::SqliteConnectionManager; use r2d2_sqlite::SqliteConnectionManager;
use sqlite::Transaction; use sqlite::Transaction;
use std::sync::{Arc, RwLock}; use std::sync::RwLock;
pub struct History { pub struct History {
database: Database, // permanent storage database: Database, // permanent storage
pub memory: Arc<RwLock<Memory>>, // fast search index memory: RwLock<Memory>, // fast search index
} // @TODO close memory member, Arc entire profile instead }
impl History { impl History {
// Constructors // Constructors
@ -24,7 +24,7 @@ impl History {
pub fn build(database_pool: &Pool<SqliteConnectionManager>, profile_id: i64) -> Result<Self> { pub fn build(database_pool: &Pool<SqliteConnectionManager>, profile_id: i64) -> Result<Self> {
// Init children components // Init children components
let database = Database::build(database_pool, profile_id); let database = Database::build(database_pool, profile_id);
let memory = Arc::new(RwLock::new(Memory::new())); let memory = RwLock::new(Memory::new());
for item in database.records(None, None)? { for item in database.records(None, None)? {
memory.write().unwrap().add(item) memory.write().unwrap().add(item)

View File

@ -2,11 +2,11 @@ pub mod auth;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
pub use auth::Auth; pub use auth::Auth;
use std::{cell::RefCell, collections::HashMap}; use std::{collections::HashMap, sync::RwLock};
/// Reduce disk usage by cache Auth index in memory /// Reduce disk usage by cache Auth index in memory
pub struct Memory { pub struct Memory {
index: RefCell<HashMap<String, i64>>, index: RwLock<HashMap<String, i64>>,
} }
impl Default for Memory { impl Default for Memory {
@ -21,7 +21,7 @@ impl Memory {
/// Create new `Self` /// Create new `Self`
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
index: RefCell::new(HashMap::new()), index: RwLock::new(HashMap::new()),
} }
} }
@ -31,7 +31,7 @@ impl Memory {
/// * validate record with same key does not exist yet /// * validate record with same key does not exist yet
pub fn add(&self, scope: String, profile_identity_id: i64) -> Result<()> { pub fn add(&self, scope: String, profile_identity_id: i64) -> Result<()> {
// Borrow shared index access // Borrow shared index access
let mut index = self.index.borrow_mut(); let mut index = self.index.write().unwrap();
// Prevent existing key overwrite // Prevent existing key overwrite
if index.contains_key(&scope) { if index.contains_key(&scope) {
@ -47,7 +47,7 @@ impl Memory {
/// Cleanup index /// Cleanup index
pub fn clear(&self) -> Result<()> { pub fn clear(&self) -> Result<()> {
let mut index = self.index.borrow_mut(); let mut index = self.index.write().unwrap();
index.clear(); index.clear();
if index.is_empty() { if index.is_empty() {
Ok(()) Ok(())
@ -62,7 +62,7 @@ impl Memory {
pub fn match_scope(&self, scope: &str) -> Option<Auth> { pub fn match_scope(&self, scope: &str) -> Option<Auth> {
let mut result = Vec::new(); let mut result = Vec::new();
for (value, &profile_identity_id) in self.index.borrow().iter() { for (value, &profile_identity_id) in self.index.read().unwrap().iter() {
if scope.starts_with(value) { if scope.starts_with(value) {
result.push(Auth { result.push(Auth {
profile_identity_id, profile_identity_id,
@ -83,7 +83,7 @@ impl Memory {
/// * see also parent `is_match_request` /// * see also parent `is_match_request`
pub fn total(&self, profile_identity_id: i64) -> usize { pub fn total(&self, profile_identity_id: i64) -> usize {
let mut total = 0; let mut total = 0;
for (_, _profile_identity_id) in self.index.borrow().iter() { for (_, _profile_identity_id) in self.index.read().unwrap().iter() {
if *_profile_identity_id == profile_identity_id { if *_profile_identity_id == profile_identity_id {
total += 1 total += 1
} }

View File

@ -1,9 +1,9 @@
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use std::{cell::RefCell, collections::HashMap}; use std::{collections::HashMap, sync::RwLock};
/// Reduce disk usage by cache index in memory /// Reduce disk usage by cache index in memory
pub struct Memory { pub struct Memory {
index: RefCell<HashMap<i64, String>>, index: RwLock<HashMap<i64, String>>,
} }
impl Default for Memory { impl Default for Memory {
@ -18,7 +18,7 @@ impl Memory {
/// Create new `Self` /// Create new `Self`
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
index: RefCell::new(HashMap::new()), index: RwLock::new(HashMap::new()),
} }
} }
@ -28,7 +28,7 @@ impl Memory {
/// * validate record with same key does not exist yet /// * validate record with same key does not exist yet
pub fn add(&self, profile_identity_id: i64, pem: String) -> Result<()> { pub fn add(&self, profile_identity_id: i64, pem: String) -> Result<()> {
// Borrow shared index access // Borrow shared index access
let mut index = self.index.borrow_mut(); let mut index = self.index.write().unwrap();
// Prevent existing key overwrite // Prevent existing key overwrite
if index.contains_key(&profile_identity_id) { if index.contains_key(&profile_identity_id) {
@ -44,7 +44,7 @@ impl Memory {
/// Get `pem` clone by `id` from memory index /// Get `pem` clone by `id` from memory index
pub fn get(&self, id: i64) -> Result<String> { pub fn get(&self, id: i64) -> Result<String> {
match self.index.borrow().get(&id) { match self.index.read().unwrap().get(&id) {
Some(pem) => Ok(pem.clone()), Some(pem) => Ok(pem.clone()),
None => bail!("Record `{id}` not found in memory index"), None => bail!("Record `{id}` not found in memory index"),
} }
@ -52,7 +52,7 @@ impl Memory {
/// Cleanup index /// Cleanup index
pub fn clear(&self) -> Result<()> { pub fn clear(&self) -> Result<()> {
let mut index = self.index.borrow_mut(); let mut index = self.index.write().unwrap();
index.clear(); index.clear();
if index.is_empty() { if index.is_empty() {
Ok(()) Ok(())

View File

@ -1,9 +1,9 @@
use super::database::Row; use super::database::Row;
use std::cell::RefCell; use std::sync::RwLock;
/// Reduce disk usage by cache Bookmarks index in memory /// Reduce disk usage by cache Bookmarks index in memory
pub struct Memory { pub struct Memory {
index: RefCell<Vec<Row>>, index: RwLock<Vec<Row>>,
} }
impl Memory { impl Memory {
@ -12,7 +12,7 @@ impl Memory {
/// Create new `Self` /// Create new `Self`
pub fn init() -> Self { pub fn init() -> Self {
Self { Self {
index: RefCell::new(Vec::new()), index: RwLock::new(Vec::new()),
} }
} }
@ -20,7 +20,7 @@ impl Memory {
/// Add new record /// Add new record
pub fn push(&self, id: i64, query: String, is_default: bool) { pub fn push(&self, id: i64, query: String, is_default: bool) {
self.index.borrow_mut().push(Row { self.index.write().unwrap().push(Row {
id, id,
query, query,
is_default, is_default,
@ -29,19 +29,19 @@ impl Memory {
/// Clear all records /// Clear all records
pub fn clear(&self) { pub fn clear(&self) {
self.index.borrow_mut().clear() self.index.write().unwrap().clear()
} }
// Getters // Getters
/// Get all records /// Get all records
pub fn records(&self) -> Vec<Row> { pub fn records(&self) -> Vec<Row> {
self.index.borrow().clone() self.index.read().unwrap().clone()
} }
/// Get all records /// Get all records
pub fn default(&self) -> Option<Row> { pub fn default(&self) -> Option<Row> {
for record in self.index.borrow().iter() { for record in self.index.read().unwrap().iter() {
if record.is_default { if record.is_default {
return Some(record.clone()); return Some(record.clone());
} }