Yoda/src/main.rs

60 lines
1.8 KiB
Rust
Raw Normal View History

2024-09-20 18:02:10 +03:00
mod browser;
2024-09-18 20:33:29 +03:00
2024-09-21 14:21:39 +03:00
use std::fs;
2024-09-20 18:02:10 +03:00
use gtk::prelude::{ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt};
2024-09-20 18:02:10 +03:00
use gtk::{glib, Application};
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-21 23:28:46 +03:00
fn main() -> glib::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-19 17:06:40 +03:00
// Init accels
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"]);
app.set_accels_for_action("win.debug", &["<Primary>i"]);
2024-09-24 23:08:40 +03:00
app.set_accels_for_action("win.update", &["<Primary>u"]);
2024-09-24 22:26:30 +03:00
app.set_accels_for_action("win.quit", &["<Primary>Escape"]);
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-21 23:35:49 +03:00
let mut fs = glib::user_config_dir();
2024-09-21 23:28:46 +03:00
fs.push(APP_ID);
if let Err(e) = fs::create_dir_all(&fs) {
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-23 18:51:48 +03:00
browser::Browser::new(this, /*db.clone(),*/ 640, 480)
2024-09-22 17:34:22 +03:00
.widget()
.present();
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
}