mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
remove direct memory access
This commit is contained in:
parent
33369e31ea
commit
19a07cdf1d
32 changed files with 112 additions and 111 deletions
|
|
@ -15,7 +15,7 @@ use gtk::{
|
|||
};
|
||||
use page::Page;
|
||||
use sqlite::Transaction;
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
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: &Rc<Profile>,
|
||||
profile: &Arc<Profile>,
|
||||
(browser_action, window_action, tab_action): (
|
||||
&Rc<BrowserAction>,
|
||||
&Rc<WindowAction>,
|
||||
|
|
|
|||
|
|
@ -9,21 +9,21 @@ use gtk::{
|
|||
glib::{Uri, UriFlags},
|
||||
prelude::{ActionExt, CancellableExt},
|
||||
};
|
||||
use std::{cell::Cell, rc::Rc};
|
||||
use std::{cell::Cell, rc::Rc, sync::Arc};
|
||||
|
||||
/// Multi-protocol client API for tab `Item`
|
||||
pub struct Client {
|
||||
cancellable: Cell<Cancellable>,
|
||||
driver: Rc<Driver>,
|
||||
page: Rc<Page>,
|
||||
profile: Rc<Profile>,
|
||||
profile: Arc<Profile>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn init(profile: &Rc<Profile>, page: &Rc<Page>) -> Self {
|
||||
pub fn init(profile: &Arc<Profile>, page: &Rc<Page>) -> Self {
|
||||
Self {
|
||||
cancellable: Cell::new(Cancellable::new()),
|
||||
driver: Rc::new(Driver::build(page)),
|
||||
|
|
@ -108,7 +108,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: &Rc<Profile>,
|
||||
profile: &Arc<Profile>,
|
||||
query: &str,
|
||||
cancellable: Cancellable,
|
||||
callback: impl FnOnce(Rc<Feature>, Cancellable, Result<Uri, String>) + 'static,
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ use input::Input;
|
|||
use navigation::Navigation;
|
||||
use search::Search;
|
||||
use sqlite::Transaction;
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
pub struct Page {
|
||||
pub profile: Rc<Profile>,
|
||||
pub profile: Arc<Profile>,
|
||||
// Actions
|
||||
pub browser_action: Rc<BrowserAction>,
|
||||
pub item_action: Rc<ItemAction>,
|
||||
|
|
@ -38,7 +38,7 @@ impl Page {
|
|||
// Constructors
|
||||
|
||||
pub fn build(
|
||||
profile: &Rc<Profile>,
|
||||
profile: &Arc<Profile>,
|
||||
(browser_action, window_action, tab_action, item_action): (
|
||||
&Rc<BrowserAction>,
|
||||
&Rc<WindowAction>,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use home::Home;
|
|||
use reload::Reload;
|
||||
use request::Request;
|
||||
use sqlite::Transaction;
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
const MARGIN: i32 = 6;
|
||||
const SPACING: i32 = 6;
|
||||
|
|
@ -30,7 +30,7 @@ pub struct Navigation {
|
|||
|
||||
impl Navigation {
|
||||
pub fn build(
|
||||
profile: &Rc<Profile>,
|
||||
profile: &Arc<Profile>,
|
||||
(window_action, tab_action, item_action): (
|
||||
&Rc<WindowAction>,
|
||||
&Rc<TabAction>,
|
||||
|
|
|
|||
|
|
@ -3,18 +3,18 @@ use gtk::{
|
|||
prelude::{ActionExt, ButtonExt, EditableExt, WidgetExt},
|
||||
Button, Entry,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
const ICON_NAME: (&str, &str) = ("non-starred-symbolic", "starred-symbolic");
|
||||
const TOOLTIP_TEXT: (&str, &str) = ("Add Bookmark", "Remove 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);
|
||||
}
|
||||
|
||||
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()
|
||||
.action_name(format!(
|
||||
"{}.{}",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use gtk::{
|
|||
};
|
||||
use primary_icon::PrimaryIcon;
|
||||
use sqlite::Transaction;
|
||||
use std::{cell::Cell, rc::Rc};
|
||||
use std::{cell::Cell, rc::Rc, sync::Arc};
|
||||
use suggestion::Suggestion;
|
||||
|
||||
const PREFIX_DOWNLOAD: &str = "download:";
|
||||
|
|
@ -23,14 +23,14 @@ const PREFIX_SOURCE: &str = "source:";
|
|||
pub struct Request {
|
||||
pub entry: Entry,
|
||||
suggestion: Rc<Suggestion>,
|
||||
profile: Rc<Profile>,
|
||||
profile: Arc<Profile>,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
// Constructors
|
||||
|
||||
/// 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
|
||||
let entry = Entry::builder()
|
||||
.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`
|
||||
fn show_identity_dialog(entry: &Entry, profile: &Rc<Profile>) {
|
||||
fn show_identity_dialog(entry: &Entry, profile: &Arc<Profile>) {
|
||||
// connect identity traits
|
||||
use identity::{Common, Unsupported};
|
||||
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`
|
||||
fn show_search_dialog(entry: &Entry, profile: &Rc<Profile>) {
|
||||
fn show_search_dialog(entry: &Entry, profile: &Arc<Profile>) {
|
||||
use search::Search;
|
||||
AlertDialog::search(profile).present(Some(entry))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,16 @@ use crate::Profile;
|
|||
use action::Action as WidgetAction;
|
||||
use adw::AlertDialog;
|
||||
use gtk::{glib::Uri, prelude::EditableExt};
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
// Select options
|
||||
|
||||
pub trait Common {
|
||||
fn common(profile: &Rc<Profile>, request: &Uri, callback: &Rc<impl Fn(bool) + 'static>)
|
||||
-> Self;
|
||||
fn common(
|
||||
profile: &Arc<Profile>,
|
||||
request: &Uri,
|
||||
callback: &Rc<impl Fn(bool) + 'static>,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
impl Common for AlertDialog {
|
||||
|
|
@ -19,7 +22,7 @@ impl Common for AlertDialog {
|
|||
|
||||
/// Create new `Self`
|
||||
fn common(
|
||||
profile: &Rc<Profile>,
|
||||
profile: &Arc<Profile>,
|
||||
request: &Uri,
|
||||
callback: &Rc<impl Fn(bool) + 'static>,
|
||||
) -> Self {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use gtk::{
|
|||
prelude::{BoxExt, WidgetExt},
|
||||
Box, Button, Entry, Orientation,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
pub struct Form {
|
||||
// pub action_widget: Rc<Action>,
|
||||
|
|
@ -30,14 +30,14 @@ pub struct Form {
|
|||
pub name: Entry,
|
||||
pub save: Rc<Save>,
|
||||
pub g_box: Box,
|
||||
profile: Rc<Profile>,
|
||||
profile: Arc<Profile>,
|
||||
}
|
||||
|
||||
impl Form {
|
||||
// Constructors
|
||||
|
||||
/// 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
|
||||
let list = Rc::new(List::build(widget_action, profile, request));
|
||||
let file = Rc::new(File::build(widget_action));
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use gtk::{
|
|||
prelude::{ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
// Defaults
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ impl Drop {
|
|||
// Constructors
|
||||
|
||||
/// 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
|
||||
let button = Button::builder()
|
||||
.label(LABEL)
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ use gtk::{
|
|||
prelude::{ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
pub trait Exit {
|
||||
fn exit(
|
||||
widget_action: &Rc<WidgetAction>,
|
||||
profile: &Rc<Profile>,
|
||||
profile: &Arc<Profile>,
|
||||
list: &Rc<List>,
|
||||
request: &Uri,
|
||||
) -> Self;
|
||||
|
|
@ -25,7 +25,7 @@ impl Exit for Button {
|
|||
/// Create new `Self`
|
||||
fn exit(
|
||||
widget_action: &Rc<WidgetAction>,
|
||||
profile: &Rc<Profile>,
|
||||
profile: &Arc<Profile>,
|
||||
list: &Rc<List>,
|
||||
request: &Uri,
|
||||
) -> Self {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
pub mod item;
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
use item::Item;
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ impl List {
|
|||
// Constructors
|
||||
|
||||
/// 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
|
||||
let guest_session = Item::new_guest_session();
|
||||
let generate_pem = Item::new_generate_pem();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use gtk::{
|
|||
gio::TlsCertificate,
|
||||
glib::{self, Object},
|
||||
};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct Item(ObjectSubclass<imp::Item>);
|
||||
|
|
@ -54,7 +54,7 @@ impl Item {
|
|||
}
|
||||
|
||||
pub fn new_profile_identity_id(
|
||||
profile: &Rc<Profile>,
|
||||
profile: &Arc<Profile>,
|
||||
profile_identity_id: i64,
|
||||
auth_url: &str,
|
||||
) -> Result<Self, Error> {
|
||||
|
|
@ -96,7 +96,7 @@ impl Item {
|
|||
// Actions
|
||||
|
||||
/// 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
|
||||
match self.value_enum() {
|
||||
Value::ProfileIdentityId(profile_identity_id) => {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::profile::Profile;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn new_for_profile_identity_id(
|
||||
profile: &Rc<Profile>,
|
||||
profile: &Arc<Profile>,
|
||||
profile_identity_id: i64,
|
||||
auth_url: &str,
|
||||
) -> bool {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use gtk::{
|
|||
prelude::{ButtonExt, FileExt, OutputStreamExtManual, WidgetExt},
|
||||
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 TOOLTIP_TEXT: &str = "Export selected identity to file";
|
||||
|
|
@ -24,7 +24,7 @@ impl Save {
|
|||
// Constructors
|
||||
|
||||
/// 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
|
||||
let button = Button::builder()
|
||||
.label(LABEL)
|
||||
|
|
@ -46,7 +46,7 @@ impl Save {
|
|||
button.set_sensitive(false);
|
||||
|
||||
// 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) => {
|
||||
// Init file filters related with PEM extension
|
||||
let filters = ListStore::new::<FileFilter>();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use anyhow::{bail, Result};
|
|||
|
||||
use crate::profile::Profile;
|
||||
use gtk::{gio::TlsCertificate, prelude::TlsCertificateExt};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// 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: 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)?;
|
||||
match record {
|
||||
Some(identity) => Ok(Self {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use form::{list::item::Value, list::Item, Form, Query};
|
|||
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");
|
||||
|
|
@ -17,14 +18,14 @@ const RESPONSE_CANCEL: (&str, &str) = ("cancel", "Cancel");
|
|||
// const RESPONSE_MANAGE: (&str, &str) = ("manage", "Manage");
|
||||
|
||||
pub trait Search {
|
||||
fn search(profile: &Rc<Profile>) -> Self;
|
||||
fn search(profile: &Arc<Profile>) -> Self;
|
||||
}
|
||||
|
||||
impl Search for AlertDialog {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
fn search(profile: &Rc<Profile>) -> Self {
|
||||
fn search(profile: &Arc<Profile>) -> Self {
|
||||
// Init child container
|
||||
let form = Rc::new(Form::build(profile));
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use drop::Drop;
|
|||
use gtk::{prelude::BoxExt, Box, Button, Entry, Orientation};
|
||||
use list::List;
|
||||
pub use query::Query;
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
pub struct Form {
|
||||
pub drop: Button,
|
||||
|
|
@ -20,7 +20,7 @@ impl Form {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(profile: &Rc<Profile>) -> Self {
|
||||
pub fn build(profile: &Arc<Profile>) -> Self {
|
||||
// Init components
|
||||
let list = Rc::new(List::build(profile));
|
||||
let query = Entry::query();
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ use gtk::{
|
|||
prelude::{ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
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 {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
fn drop(profile: &Rc<Profile>, list: &Rc<List>) -> Self {
|
||||
fn drop(profile: &Arc<Profile>, list: &Rc<List>) -> Self {
|
||||
// Defaults
|
||||
|
||||
const LABEL: &str = "Delete";
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use gtk::{
|
|||
Align, Box, DropDown, Label, ListItem, Orientation, SignalListItemFactory,
|
||||
};
|
||||
pub use item::Item;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct List {
|
||||
pub dropdown: DropDown,
|
||||
|
|
@ -21,7 +21,7 @@ impl List {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(profile: &Rc<Profile>) -> Self {
|
||||
pub fn build(profile: &Arc<Profile>) -> Self {
|
||||
// Init dropdown items
|
||||
let new_search_provider = Item::add();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,14 +17,14 @@ use gtk::{
|
|||
};
|
||||
pub use item::Item;
|
||||
use sourceview::prelude::ListModelExt;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||
|
||||
pub struct Suggestion {
|
||||
list_store: ListStore,
|
||||
list_view: ListView,
|
||||
single_selection: SingleSelection,
|
||||
request: Entry,
|
||||
profile: Rc<Profile>,
|
||||
profile: Arc<Profile>,
|
||||
popover: Popover,
|
||||
pub signal_handler_id: Rc<RefCell<Option<SignalHandlerId>>>,
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ impl Suggestion {
|
|||
// Constructors
|
||||
|
||||
/// 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 list_store = ListStore::new::<Item>();
|
||||
let single_selection = {
|
||||
|
|
@ -162,15 +162,12 @@ impl Suggestion {
|
|||
let query = self.request.text();
|
||||
let popover = self.popover.clone();
|
||||
let list_store = self.list_store.clone();
|
||||
|
||||
let history = self.profile.history.memory.clone(); // @TODO
|
||||
let bookmark = self.profile.bookmark.memory.clone(); // @TODO
|
||||
let profile = self.profile.clone();
|
||||
|
||||
gtk::glib::spawn_future_local(async move {
|
||||
let list_items = gtk::gio::spawn_blocking(move || {
|
||||
let result = history
|
||||
.read()
|
||||
.unwrap()
|
||||
let result = profile
|
||||
.history
|
||||
.contains_request(&query, limit)
|
||||
.into_iter()
|
||||
.sorted_by(|a, b| Ord::cmp(&b.opened.count, &a.opened.count));
|
||||
|
|
@ -184,7 +181,7 @@ impl Suggestion {
|
|||
list_items.push((
|
||||
title,
|
||||
subtitle,
|
||||
bookmark.read().unwrap().is_match_request(&item.request),
|
||||
profile.bookmark.is_match_request(&item.request),
|
||||
item.request,
|
||||
))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue