Browse Source

create parental app mod

master
yggverse 2 months ago
parent
commit
b2aa3af46a
  1. 125
      src/app.rs
  2. 42
      src/app/action.rs
  3. 7
      src/app/browser.rs
  4. 0
      src/app/browser/db.rs
  5. 0
      src/app/browser/header.rs
  6. 0
      src/app/browser/header/subject.rs
  7. 0
      src/app/browser/header/subject/description.rs
  8. 0
      src/app/browser/header/subject/title.rs
  9. 0
      src/app/browser/header/tray.rs
  10. 1
      src/app/browser/header/tray/menu.rs
  11. 0
      src/app/browser/header/tray/tab.rs
  12. 0
      src/app/browser/main.rs
  13. 0
      src/app/browser/main/tab.rs
  14. 0
      src/app/browser/main/tab/label.rs
  15. 0
      src/app/browser/main/tab/label/pin.rs
  16. 0
      src/app/browser/main/tab/label/title.rs
  17. 0
      src/app/browser/main/tab/page.rs
  18. 0
      src/app/browser/main/tab/page/content.rs
  19. 0
      src/app/browser/main/tab/page/content/text.rs
  20. 0
      src/app/browser/main/tab/page/content/text/gemini.rs
  21. 0
      src/app/browser/main/tab/page/content/text/gemini/reader.rs
  22. 0
      src/app/browser/main/tab/page/content/text/gemini/reader/default.css
  23. 0
      src/app/browser/main/tab/page/content/text/gemini/reader/parser.rs
  24. 0
      src/app/browser/main/tab/page/content/text/gemini/reader/parser/header.rs
  25. 0
      src/app/browser/main/tab/page/content/text/gemini/reader/parser/link.rs
  26. 0
      src/app/browser/main/tab/page/content/text/gemini/reader/parser/plain.rs
  27. 0
      src/app/browser/main/tab/page/content/text/plain/reader.rs
  28. 0
      src/app/browser/main/tab/page/meta.rs
  29. 0
      src/app/browser/main/tab/page/navigation.rs
  30. 0
      src/app/browser/main/tab/page/navigation/base.rs
  31. 0
      src/app/browser/main/tab/page/navigation/bookmark.rs
  32. 0
      src/app/browser/main/tab/page/navigation/history.rs
  33. 0
      src/app/browser/main/tab/page/navigation/history/back.rs
  34. 0
      src/app/browser/main/tab/page/navigation/history/forward.rs
  35. 0
      src/app/browser/main/tab/page/navigation/reload.rs
  36. 0
      src/app/browser/main/tab/page/navigation/request.rs
  37. 112
      src/main.rs

125
src/app.rs

@ -0,0 +1,125 @@
mod action;
mod browser;
use action::Action;
use browser::Browser;
use gtk::{
glib::{user_config_dir, ExitCode},
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
Application,
};
use std::{fs::create_dir_all, sync::Arc};
const APPLICATION_ID: &str = "io.github.yggverse.Yoda";
pub struct App {
// GTK
app: Application,
// Components
//browser: Arc<Browser>,
}
impl App {
// Construct
pub fn new() -> Self {
// Init profile directory
let mut fs = user_config_dir();
fs.push(APPLICATION_ID);
if let Err(e) = create_dir_all(&fs) {
panic!("Failed to create profile directory: {e}")
}
// Init profile database
/* @TODO
let mut db = fs.clone();
db.push("database.sqlite3");
let db = match sqlite::open(db) {
Ok(db) => Arc::new(db),
Err(e) => panic!("Failed to connect profile database: {e}"),
};*/
// Init actions
let action_debug = Action::new("win", true);
let action_quit = Action::new("win", true);
let action_update = Action::new("win", true);
let action_tab_append = Action::new("win", true);
let action_tab_close = Action::new("win", true);
let action_tab_close_all = Action::new("win", true);
let action_tab_page_navigation_base = Action::new("win", false);
let action_tab_page_navigation_history_back = Action::new("win", false);
let action_tab_page_navigation_history_forward = Action::new("win", false);
let action_tab_page_navigation_reload = Action::new("win", true);
let action_tab_pin = Action::new("win", true);
// Init GTK
let app = Application::builder()
.application_id(APPLICATION_ID)
.build();
// Init accels
app.set_accels_for_action(&action_debug.detailed_name(), &["<Primary>i"]);
app.set_accels_for_action(&action_update.detailed_name(), &["<Primary>u"]);
app.set_accels_for_action(&action_quit.detailed_name(), &["<Primary>Escape"]);
app.set_accels_for_action(&action_tab_append.detailed_name(), &["<Primary>t"]);
app.set_accels_for_action(&action_tab_pin.detailed_name(), &["<Primary>p"]);
app.set_accels_for_action(&action_tab_close.detailed_name(), &["<Primary>q"]);
app.set_accels_for_action(
&action_tab_page_navigation_base.detailed_name(),
&["<Primary>h"],
);
app.set_accels_for_action(
&action_tab_page_navigation_history_back.detailed_name(),
&["<Primary>Left"],
);
app.set_accels_for_action(
&action_tab_page_navigation_history_forward.detailed_name(),
&["<Primary>Right"],
);
app.set_accels_for_action(
&action_tab_page_navigation_reload.detailed_name(),
&["<Primary>r"],
);
// Init events
app.connect_activate({
move |application| {
// Init components
let browser = Arc::new(Browser::new(
&application,
/*db.clone(),*/
action_debug.simple(),
action_quit.simple(),
action_update.simple(),
action_tab_append.simple(),
action_tab_close.simple(),
action_tab_close_all.simple(),
action_tab_page_navigation_base.simple(),
action_tab_page_navigation_history_back.simple(),
action_tab_page_navigation_history_forward.simple(),
action_tab_page_navigation_reload.simple(),
action_tab_pin.simple(),
));
// Show main widget
browser.widget().present();
// Make initial update
action_update.simple().activate(None);
}
});
// Return activated struct
Self { app }
}
// Actions
pub fn run(&self) -> ExitCode {
self.app.run()
}
}

42
src/app/action.rs

@ -0,0 +1,42 @@
// This helper created as the attempt to drop static names usage
// and replace them with objects (to follow encapsulation for children mods)
// @TODO find alternative implementation, if exist for GTK 4
use std::sync::Arc;
use gtk::{
gio::SimpleAction,
glib::{gformat, uuid_string_random, GString},
prelude::ActionExt,
};
pub struct Action {
group: GString,
simple: Arc<SimpleAction>,
}
impl Action {
// Construct
pub fn new(group: &str, is_enabled: bool) -> Self {
// Create random action name as no static values should be in use
let simple = Arc::new(SimpleAction::new(&uuid_string_random(), None));
simple.set_enabled(is_enabled);
// Assign action to the group
let group = GString::from(group);
// Return new Action
Self { group, simple }
}
// Getters
pub fn detailed_name(&self) -> GString {
gformat!("{}.{}", self.group, self.simple.name()) // @TODO find the way to ident parent group
// from SimpleAction object
}
// App mods work with simple and system-wide data types, let them take it
pub fn simple(&self) -> Arc<SimpleAction> {
self.simple.clone()
}
}

7
src/browser.rs → src/app/browser.rs

@ -1,4 +1,3 @@
mod db;
mod header; mod header;
mod main; mod main;
@ -27,7 +26,9 @@ pub struct Browser {
impl Browser { impl Browser {
// Construct // Construct
pub fn new( pub fn new(
app: &Application, // Dependencies
application: &Application,
// Extras
// connection: Arc<sqlite::Connection>, // connection: Arc<sqlite::Connection>,
// Actions // Actions
action_debug: Arc<SimpleAction>, action_debug: Arc<SimpleAction>,
@ -69,7 +70,7 @@ impl Browser {
// Init widget // Init widget
let widget = ApplicationWindow::builder() let widget = ApplicationWindow::builder()
.application(app) .application(application)
.titlebar(header.widget()) .titlebar(header.widget())
.child(main.widget()) .child(main.widget())
.default_height(DEFAULT_HEIGHT) .default_height(DEFAULT_HEIGHT)

0
src/browser/db.rs → src/app/browser/db.rs

0
src/browser/header.rs → src/app/browser/header.rs

0
src/browser/header/subject.rs → src/app/browser/header/subject.rs

0
src/browser/header/subject/description.rs → src/app/browser/header/subject/description.rs

0
src/browser/header/subject/title.rs → src/app/browser/header/subject/title.rs

0
src/browser/header/tray.rs → src/app/browser/header/tray.rs

1
src/browser/header/tray/menu.rs → src/app/browser/header/tray/menu.rs

@ -76,4 +76,5 @@ impl Menu {
fn detailed_action_name(action: Arc<SimpleAction>) -> GString { fn detailed_action_name(action: Arc<SimpleAction>) -> GString {
gformat!("win.{}", action.name()) // @TODO find the way to ident parent group gformat!("win.{}", action.name()) // @TODO find the way to ident parent group
// without application-wide dependencies import // without application-wide dependencies import
// see also src/app/action.rs
} }

0
src/browser/header/tray/tab.rs → src/app/browser/header/tray/tab.rs

0
src/browser/main.rs → src/app/browser/main.rs

0
src/browser/main/tab.rs → src/app/browser/main/tab.rs

0
src/browser/main/tab/label.rs → src/app/browser/main/tab/label.rs

0
src/browser/main/tab/label/pin.rs → src/app/browser/main/tab/label/pin.rs

0
src/browser/main/tab/label/title.rs → src/app/browser/main/tab/label/title.rs

0
src/browser/main/tab/page.rs → src/app/browser/main/tab/page.rs

0
src/browser/main/tab/page/content.rs → src/app/browser/main/tab/page/content.rs

0
src/browser/main/tab/page/content/text.rs → src/app/browser/main/tab/page/content/text.rs

0
src/browser/main/tab/page/content/text/gemini.rs → src/app/browser/main/tab/page/content/text/gemini.rs

0
src/browser/main/tab/page/content/text/gemini/reader.rs → src/app/browser/main/tab/page/content/text/gemini/reader.rs

0
src/browser/main/tab/page/content/text/gemini/reader/default.css → src/app/browser/main/tab/page/content/text/gemini/reader/default.css

0
src/browser/main/tab/page/content/text/gemini/reader/parser.rs → src/app/browser/main/tab/page/content/text/gemini/reader/parser.rs

0
src/browser/main/tab/page/content/text/gemini/reader/parser/header.rs → src/app/browser/main/tab/page/content/text/gemini/reader/parser/header.rs

0
src/browser/main/tab/page/content/text/gemini/reader/parser/link.rs → src/app/browser/main/tab/page/content/text/gemini/reader/parser/link.rs

0
src/browser/main/tab/page/content/text/gemini/reader/parser/plain.rs → src/app/browser/main/tab/page/content/text/gemini/reader/parser/plain.rs

0
src/browser/main/tab/page/content/text/plain/reader.rs → src/app/browser/main/tab/page/content/text/plain/reader.rs

0
src/browser/main/tab/page/meta.rs → src/app/browser/main/tab/page/meta.rs

0
src/browser/main/tab/page/navigation.rs → src/app/browser/main/tab/page/navigation.rs

0
src/browser/main/tab/page/navigation/base.rs → src/app/browser/main/tab/page/navigation/base.rs

0
src/browser/main/tab/page/navigation/bookmark.rs → src/app/browser/main/tab/page/navigation/bookmark.rs

0
src/browser/main/tab/page/navigation/history.rs → src/app/browser/main/tab/page/navigation/history.rs

0
src/browser/main/tab/page/navigation/history/back.rs → src/app/browser/main/tab/page/navigation/history/back.rs

0
src/browser/main/tab/page/navigation/history/forward.rs → src/app/browser/main/tab/page/navigation/history/forward.rs

0
src/browser/main/tab/page/navigation/reload.rs → src/app/browser/main/tab/page/navigation/reload.rs

0
src/browser/main/tab/page/navigation/request.rs → src/app/browser/main/tab/page/navigation/request.rs

112
src/main.rs

@ -1,112 +1,8 @@
mod browser; mod app;
use browser::Browser; use app::App;
use gtk::glib::ExitCode;
use gtk::{
gio::SimpleAction,
glib::{user_config_dir, ExitCode},
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
Application,
};
use std::{fs::create_dir_all, sync::Arc};
const APP_ID: &str = "io.github.yggverse.Yoda";
fn main() -> ExitCode { fn main() -> ExitCode {
// Init app App::new().run()
let app = Application::builder().application_id(APP_ID).build();
// Init actions
let action_debug = Arc::new(SimpleAction::new("debug", None));
let action_quit = Arc::new(SimpleAction::new("quit", None));
let action_update = Arc::new(SimpleAction::new("update", None));
let action_tab_append = Arc::new(SimpleAction::new("tab_append", None));
let action_tab_close = Arc::new(SimpleAction::new("tab_close", None));
let action_tab_close_all = Arc::new(SimpleAction::new("tab_close_all", None));
let action_tab_page_navigation_base =
Arc::new(SimpleAction::new("tab_page_navigation_base", None));
action_tab_page_navigation_base.set_enabled(false);
let action_tab_page_navigation_history_back =
Arc::new(SimpleAction::new("tab_page_navigation_history_back", None));
action_tab_page_navigation_history_back.set_enabled(false);
let action_tab_page_navigation_history_forward = Arc::new(SimpleAction::new(
"tab_page_navigation_history_forward",
None,
));
action_tab_page_navigation_history_forward.set_enabled(false);
let action_tab_page_navigation_reload =
Arc::new(SimpleAction::new("tab_page_navigation_reload", None));
let action_tab_pin = Arc::new(SimpleAction::new("tab_pin", None));
// Init accels
app.set_accels_for_action("win.debug", &["<Primary>i"]);
app.set_accels_for_action("win.update", &["<Primary>u"]);
app.set_accels_for_action("win.quit", &["<Primary>Escape"]);
app.set_accels_for_action("win.tab_append", &["<Primary>t"]);
app.set_accels_for_action("win.tab_pin", &["<Primary>p"]);
app.set_accels_for_action("win.tab_close", &["<Primary>q"]);
app.set_accels_for_action("win.tab_page_navigation_base", &["<Primary>h"]);
app.set_accels_for_action("win.tab_page_navigation_history_back", &["<Primary>Left"]);
app.set_accels_for_action(
"win.tab_page_navigation_history_forward",
&["<Primary>Right"],
);
app.set_accels_for_action("win.tab_page_navigation_reload", &["<Primary>r"]);
//app.set_accels_for_action("win.tab_page_bookmark", &["<Primary>b"]);
// Create new window
app.connect_activate({
// Init profile directory
let mut fs = user_config_dir();
fs.push(APP_ID);
if let Err(e) = create_dir_all(&fs) {
panic!("Failed to create profile directory: {e}")
}
// Init profile database
/* @TODO
let mut db = fs.clone();
db.push("database.sqlite3");
let db = match sqlite::open(db) {
Ok(db) => Arc::new(db),
Err(e) => panic!("Failed to connect profile database: {e}"),
};*/
move |this: &Application| {
Browser::new(
this,
/*db.clone(),*/
action_debug.clone(),
action_quit.clone(),
action_update.clone(),
action_tab_append.clone(),
action_tab_close.clone(),
action_tab_close_all.clone(),
action_tab_page_navigation_base.clone(),
action_tab_page_navigation_history_back.clone(),
action_tab_page_navigation_history_forward.clone(),
action_tab_page_navigation_reload.clone(),
action_tab_pin.clone(),
)
.widget()
.present();
// Make initial update
action_update.activate(None);
}
});
// Start
app.run()
} }

Loading…
Cancel
Save