mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 01:25:27 +00:00
move meta entities to the page level, remove extra references, add change some db tables structure, change app version
This commit is contained in:
parent
557ad69edf
commit
2ff6b9d963
22 changed files with 313 additions and 472 deletions
|
|
@ -2,7 +2,8 @@ use sqlite::{Error, Transaction};
|
|||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
// pub app_browser_window_tab_item_id: i64, not in use
|
||||
// pub app_browser_window_tab_item_id: i64, not in use,
|
||||
pub title: String,
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
|
|
@ -11,6 +12,7 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`app_browser_window_tab_item_id` INTEGER NOT NULL,
|
||||
`title` VARCHAR(1024),
|
||||
|
||||
FOREIGN KEY (`app_browser_window_tab_item_id`) REFERENCES `app_browser_window_tab_item`(`id`)
|
||||
)",
|
||||
|
|
@ -18,19 +20,25 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn insert(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<usize, Error> {
|
||||
pub fn insert(
|
||||
tx: &Transaction,
|
||||
app_browser_window_tab_item_id: i64,
|
||||
title: &str,
|
||||
) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"INSERT INTO `app_browser_window_tab_item_page` (
|
||||
`app_browser_window_tab_item_id`
|
||||
) VALUES (?)",
|
||||
[app_browser_window_tab_item_id],
|
||||
`app_browser_window_tab_item_id`,
|
||||
`title`
|
||||
) VALUES (?, ?)",
|
||||
(app_browser_window_tab_item_id, title),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn select(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<Vec<Table>, Error> {
|
||||
pub fn select(tx: &Transaction, app_browser_window_tab_item_id: i64) -> Result<Vec<Table>, Error> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_window_tab_item_id`
|
||||
`app_browser_window_tab_item_id`,
|
||||
`title`
|
||||
FROM `app_browser_window_tab_item_page`
|
||||
WHERE `app_browser_window_tab_item_id` = ?",
|
||||
)?;
|
||||
|
|
@ -39,6 +47,7 @@ pub fn select(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<
|
|||
Ok(Table {
|
||||
id: row.get(0)?,
|
||||
// app_browser_window_tab_item_id: row.get(1)?, not in use
|
||||
title: row.get(2)?,
|
||||
})
|
||||
})?;
|
||||
|
||||
|
|
@ -52,7 +61,7 @@ pub fn select(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<
|
|||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
|
||||
pub fn delete(tx: &Transaction, id: i64) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"DELETE FROM `app_browser_window_tab_item_page` WHERE `id` = ?",
|
||||
[id],
|
||||
|
|
|
|||
|
|
@ -1,179 +0,0 @@
|
|||
mod database;
|
||||
mod redirect;
|
||||
|
||||
use redirect::Redirect;
|
||||
|
||||
use gtk::glib::GString;
|
||||
use sqlite::Transaction;
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Status {
|
||||
Complete,
|
||||
Connected,
|
||||
Connecting,
|
||||
Failure,
|
||||
Input,
|
||||
New,
|
||||
ProxyNegotiated,
|
||||
ProxyNegotiating,
|
||||
Redirect,
|
||||
Reload,
|
||||
Resolved,
|
||||
Resolving,
|
||||
SessionRestore,
|
||||
SessionRestored,
|
||||
Success,
|
||||
TlsHandshaked,
|
||||
TlsHandshaking,
|
||||
}
|
||||
|
||||
pub struct Meta {
|
||||
pub status: RefCell<Status>,
|
||||
pub title: RefCell<GString>,
|
||||
pub redirect: RefCell<Vec<Redirect>>,
|
||||
}
|
||||
|
||||
impl Meta {
|
||||
// Constructors
|
||||
|
||||
pub fn new(status: Status, title: GString) -> Self {
|
||||
Self {
|
||||
status: RefCell::new(status),
|
||||
title: RefCell::new(title),
|
||||
redirect: RefCell::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
||||
pub fn set_status(&self, status: Status) -> &Self {
|
||||
self.status.replace(status);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_title(&self, title: &str) -> &Self {
|
||||
self.title.replace(GString::from(title));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_redirect(
|
||||
&self,
|
||||
request: GString,
|
||||
referrer: Option<GString>,
|
||||
is_foreground: bool,
|
||||
) -> &Self {
|
||||
self.redirect.borrow_mut().push(Redirect {
|
||||
request,
|
||||
referrer,
|
||||
is_foreground,
|
||||
is_processed: Cell::new(false),
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn redirects(&self) -> usize {
|
||||
self.redirect.borrow().len() + 1
|
||||
}
|
||||
|
||||
pub fn redirect(&self) -> Option<Redirect> {
|
||||
if let Some(redirect) = self.redirect.borrow().last() {
|
||||
if !redirect.is_processed.replace(true) {
|
||||
return Some(redirect.clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
pub fn clean(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_page_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_window_tab_page_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
match database::delete(transaction, &record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to the item childs
|
||||
// nothing yet..
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn restore(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_page_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
match database::select(transaction, app_browser_window_tab_page_id) {
|
||||
Ok(records) => {
|
||||
for record in records {
|
||||
// Record value can be stored as NULL
|
||||
if let Some(title) = record.title {
|
||||
self.set_title(title.as_str());
|
||||
}
|
||||
|
||||
// Delegate restore action to the item childs
|
||||
// nothing yet..
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save(
|
||||
&self,
|
||||
transaction: &Transaction,
|
||||
app_browser_window_tab_page_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
// Keep value in memory until operation complete
|
||||
let title = self.title.borrow();
|
||||
|
||||
match database::insert(
|
||||
transaction,
|
||||
app_browser_window_tab_page_id,
|
||||
match title.is_empty() {
|
||||
true => None,
|
||||
false => Some(title.as_str()),
|
||||
},
|
||||
) {
|
||||
Ok(_) => {
|
||||
// let id = database::last_insert_id(transaction);
|
||||
|
||||
// Delegate save action to childs
|
||||
// nothing yet..
|
||||
}
|
||||
Err(e) => return Err(e.to_string()),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
// Migrate self components
|
||||
if let Err(e) = database::init(tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
|
||||
// Delegate migration to childs
|
||||
// nothing yet..
|
||||
|
||||
// Success
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
use sqlite::{Error, Transaction};
|
||||
|
||||
pub struct Table {
|
||||
pub id: i64,
|
||||
// pub app_browser_window_tab_item_page_id: i64, not in use
|
||||
pub title: Option<String>, // can be stored as NULL
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_meta`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`app_browser_window_tab_item_page_id` INTEGER NOT NULL,
|
||||
`title` VARCHAR(1024),
|
||||
|
||||
FOREIGN KEY (`app_browser_window_tab_item_page_id`) REFERENCES `app_browser_window_tab_item_page`(`id`)
|
||||
)",
|
||||
[],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn insert(
|
||||
tx: &Transaction,
|
||||
app_browser_window_tab_item_page_id: &i64,
|
||||
title: Option<&str>,
|
||||
) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"INSERT INTO `app_browser_window_tab_item_page_meta` (
|
||||
`app_browser_window_tab_item_page_id`,
|
||||
`title`
|
||||
) VALUES (?, ?)",
|
||||
(app_browser_window_tab_item_page_id, title),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn select(
|
||||
tx: &Transaction,
|
||||
app_browser_window_tab_item_page_id: &i64,
|
||||
) -> Result<Vec<Table>, Error> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_window_tab_item_page_id`,
|
||||
`title`
|
||||
FROM `app_browser_window_tab_item_page_meta`
|
||||
WHERE `app_browser_window_tab_item_page_id` = ?",
|
||||
)?;
|
||||
|
||||
let result = stmt.query_map([app_browser_window_tab_item_page_id], |row| {
|
||||
Ok(Table {
|
||||
id: row.get(0)?,
|
||||
// app_browser_window_tab_item_page_id: row.get(1)?, not in use
|
||||
title: row.get(2)?,
|
||||
})
|
||||
})?;
|
||||
|
||||
let mut records = Vec::new();
|
||||
|
||||
for record in result {
|
||||
let table = record?;
|
||||
records.push(table);
|
||||
}
|
||||
|
||||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"DELETE FROM `app_browser_window_tab_item_page_meta` WHERE `id` = ?",
|
||||
[id],
|
||||
)
|
||||
}
|
||||
|
||||
/* not in use
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
} */
|
||||
57
src/app/browser/window/tab/item/page/redirect.rs
Normal file
57
src/app/browser/window/tab/item/page/redirect.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
mod item;
|
||||
use item::Item;
|
||||
|
||||
use gtk::glib::GString;
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
||||
pub struct Redirect {
|
||||
index: RefCell<Vec<Item>>,
|
||||
}
|
||||
|
||||
impl Default for Redirect {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Redirect {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
index: RefCell::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
pub fn add(&self, request: GString, referrer: Option<GString>, is_foreground: bool) -> &Self {
|
||||
self.index.borrow_mut().push(Item {
|
||||
request,
|
||||
referrer,
|
||||
is_foreground,
|
||||
is_processed: Cell::new(false),
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
pub fn clear(&self) {
|
||||
self.index.borrow_mut().clear()
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn count(&self) -> usize {
|
||||
self.index.borrow().len() + 1
|
||||
}
|
||||
|
||||
pub fn last(&self) -> Option<Item> {
|
||||
if let Some(redirect) = self.index.borrow().last() {
|
||||
if !redirect.is_processed.replace(true) {
|
||||
return Some(redirect.clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
use gtk::glib::GString;
|
||||
use std::cell::Cell;
|
||||
|
||||
/// Single redirect `Item`
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Redirect {
|
||||
pub struct Item {
|
||||
pub is_foreground: bool,
|
||||
pub is_processed: Cell<bool>,
|
||||
pub referrer: Option<GString>,
|
||||
22
src/app/browser/window/tab/item/page/status.rs
Normal file
22
src/app/browser/window/tab/item/page/status.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/// `Page` status
|
||||
/// * not same as the Gemini status!
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Status {
|
||||
Complete,
|
||||
Connected,
|
||||
Connecting,
|
||||
Failure,
|
||||
Input,
|
||||
New,
|
||||
ProxyNegotiated,
|
||||
ProxyNegotiating,
|
||||
Redirect,
|
||||
Reload,
|
||||
Resolved,
|
||||
Resolving,
|
||||
SessionRestore,
|
||||
SessionRestored,
|
||||
Success,
|
||||
TlsHandshaked,
|
||||
TlsHandshaking,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue