2024-09-20 18:02:10 +03:00
|
|
|
mod browser;
|
2024-09-18 20:33:29 +03:00
|
|
|
|
2024-09-30 02:00:14 +03:00
|
|
|
use browser::Browser;
|
2024-09-21 14:21:39 +03:00
|
|
|
|
2024-09-30 02:00:14 +03:00
|
|
|
use gtk::{
|
2024-09-30 13:43:46 +03:00
|
|
|
gio::SimpleAction,
|
2024-09-30 02:00:14 +03:00
|
|
|
glib::{user_config_dir, ExitCode},
|
2024-09-30 13:43:46 +03:00
|
|
|
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
|
2024-09-30 02:00:14 +03:00
|
|
|
Application,
|
|
|
|
};
|
2024-09-19 00:34:46 +03:00
|
|
|
|
2024-09-30 13:43:46 +03:00
|
|
|
use std::{fs::create_dir_all, sync::Arc};
|
2024-09-18 16:24:25 +03:00
|
|
|
|
2024-09-21 23:28:46 +03:00
|
|
|
const APP_ID: &str = "io.github.yggverse.Yoda";
|
2024-09-21 20:48:12 +03:00
|
|
|
|
2024-09-30 02:00:14 +03:00
|
|
|
fn main() -> ExitCode {
|
2024-09-19 17:06:40 +03:00
|
|
|
// Init app
|
2024-09-21 14:21:39 +03:00
|
|
|
let app = Application::builder().application_id(APP_ID).build();
|
2024-09-18 16:24:25 +03:00
|
|
|
|
2024-09-30 13:43:46 +03:00
|
|
|
// 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));
|
2024-09-30 14:49:37 +03:00
|
|
|
let action_tab_page_navigation_reload = Arc::new(SimpleAction::new("tab_page_reload", None));
|
2024-09-30 13:43:46 +03:00
|
|
|
let action_tab_pin = Arc::new(SimpleAction::new("tab_pin", None));
|
|
|
|
|
2024-09-19 17:06:40 +03:00
|
|
|
// Init accels
|
2024-09-30 13:43:46 +03:00
|
|
|
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"]);
|
|
|
|
|
2024-09-24 22:26:30 +03:00
|
|
|
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_base", &["<Primary>h"]);
|
|
|
|
app.set_accels_for_action("win.tab_page_history_back", &["<Primary>Left"]);
|
|
|
|
app.set_accels_for_action("win.tab_page_history_forward", &["<Primary>Right"]);
|
|
|
|
app.set_accels_for_action("win.tab_page_reload", &["<Primary>r"]);
|
|
|
|
app.set_accels_for_action("win.tab_page_bookmark", &["<Primary>b"]);
|
2024-09-19 17:06:40 +03:00
|
|
|
|
|
|
|
// Create new window
|
2024-09-21 23:28:46 +03:00
|
|
|
app.connect_activate({
|
|
|
|
// Init profile directory
|
2024-09-30 02:00:14 +03:00
|
|
|
let mut fs = user_config_dir();
|
2024-09-21 23:28:46 +03:00
|
|
|
|
|
|
|
fs.push(APP_ID);
|
|
|
|
|
2024-09-30 02:00:14 +03:00
|
|
|
if let Err(e) = create_dir_all(&fs) {
|
2024-09-21 23:28:46 +03:00
|
|
|
panic!("Failed to create profile directory: {e}")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init profile database
|
2024-09-23 18:51:48 +03:00
|
|
|
/* @TODO
|
2024-09-21 23:28:46 +03:00
|
|
|
let mut db = fs.clone();
|
|
|
|
|
|
|
|
db.push("database.sqlite3");
|
|
|
|
|
|
|
|
let db = match sqlite::open(db) {
|
2024-09-22 12:30:32 +03:00
|
|
|
Ok(db) => Arc::new(db),
|
2024-09-21 23:28:46 +03:00
|
|
|
Err(e) => panic!("Failed to connect profile database: {e}"),
|
2024-09-23 18:51:48 +03:00
|
|
|
};*/
|
2024-09-21 23:28:46 +03:00
|
|
|
|
2024-09-23 12:44:57 +03:00
|
|
|
move |this: &Application| {
|
2024-09-30 13:43:46 +03:00
|
|
|
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(),
|
2024-09-30 14:49:37 +03:00
|
|
|
action_tab_page_navigation_reload.clone(),
|
2024-09-30 13:43:46 +03:00
|
|
|
action_tab_pin.clone(),
|
|
|
|
)
|
|
|
|
.widget()
|
|
|
|
.present();
|
|
|
|
|
|
|
|
// Make initial update
|
|
|
|
action_update.activate(None);
|
2024-09-21 23:28:46 +03:00
|
|
|
}
|
2024-09-20 18:02:10 +03:00
|
|
|
});
|
2024-09-18 16:24:25 +03:00
|
|
|
|
2024-09-19 17:06:40 +03:00
|
|
|
// Start
|
2024-09-18 16:24:25 +03:00
|
|
|
app.run()
|
2024-09-20 18:02:10 +03:00
|
|
|
}
|