2023-08-09 18:02:20 +00:00
|
|
|
use chrono::{Datelike, Local, Utc};
|
2023-08-09 16:53:14 +00:00
|
|
|
use geo_types::{Latitude, Longitude};
|
2023-08-09 17:15:32 +00:00
|
|
|
use glib::Sender;
|
2023-08-09 18:04:48 +00:00
|
|
|
use gtk::prelude::*;
|
2023-08-08 02:35:43 +00:00
|
|
|
use ifc::IFC;
|
2023-08-09 16:53:14 +00:00
|
|
|
use std::{
|
|
|
|
env,
|
|
|
|
sync::{Arc, RwLock},
|
|
|
|
};
|
2023-08-08 21:25:21 +00:00
|
|
|
|
2023-08-09 17:54:56 +00:00
|
|
|
mod app_window;
|
|
|
|
use app_window::ApplicationWindow;
|
|
|
|
|
2023-08-09 17:15:32 +00:00
|
|
|
mod components;
|
2023-08-07 23:06:00 +00:00
|
|
|
|
2023-08-09 17:15:32 +00:00
|
|
|
mod drawing;
|
2023-07-28 18:42:25 +00:00
|
|
|
|
|
|
|
mod soluna_client;
|
2023-08-09 18:04:48 +00:00
|
|
|
use soluna_client::SolunaClient;
|
2023-07-28 18:42:25 +00:00
|
|
|
|
|
|
|
mod solstices;
|
2023-08-07 23:06:00 +00:00
|
|
|
use solstices::EVENTS;
|
2023-07-28 18:42:25 +00:00
|
|
|
|
2023-08-09 17:54:56 +00:00
|
|
|
mod types;
|
|
|
|
use types::State;
|
|
|
|
|
|
|
|
/*
|
2023-07-28 18:42:25 +00:00
|
|
|
const EO_TEXT: &'static str = "
|
|
|
|
day = {$day ->
|
|
|
|
*[Sunday] Dimanĉo
|
|
|
|
[Monday] Lundo
|
|
|
|
[Tuesday] Mardo
|
|
|
|
[Wednesday] Merkredo
|
|
|
|
[Thursday] Ĵaŭdo
|
|
|
|
[Friday] Vendredo
|
|
|
|
[Saturday] Sabato
|
|
|
|
[LeapDay] Leap Day
|
|
|
|
[YearDay] Year Day
|
|
|
|
}
|
|
|
|
month = {$month ->
|
|
|
|
*[January] Januaro
|
|
|
|
[February] Februaro
|
|
|
|
[March] Marto
|
|
|
|
[April] Aprilo
|
|
|
|
[May] Mayo
|
|
|
|
[June] Junio
|
|
|
|
[Sol] Solo
|
|
|
|
[July] Julio
|
|
|
|
[August] Aŭgusto
|
|
|
|
[September] Septembro
|
|
|
|
[October] Oktobro
|
|
|
|
[November] Novembro
|
|
|
|
[December] Decembro
|
|
|
|
}
|
|
|
|
spring_equinox = Printempa Ekvinokso
|
|
|
|
summer_solstice = Somera Solstico
|
|
|
|
autumn_equinox = Aŭtuna Ekvinokso
|
|
|
|
winter_solstice = Vintra Solstico
|
|
|
|
";
|
2023-08-09 17:54:56 +00:00
|
|
|
*/
|
2023-07-28 18:42:25 +00:00
|
|
|
|
2023-08-09 16:53:14 +00:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum Message {
|
|
|
|
Refresh(State),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Core {
|
|
|
|
tx: Arc<RwLock<Option<Sender<Message>>>>,
|
|
|
|
}
|
|
|
|
|
2023-08-07 23:06:00 +00:00
|
|
|
pub fn main() {
|
2023-08-10 15:07:35 +00:00
|
|
|
gio::resources_register_include!("com.luminescent-dreams.dashboard.gresource")
|
|
|
|
.expect("Failed to register resources");
|
|
|
|
|
2023-08-10 03:33:51 +00:00
|
|
|
let app = adw::Application::builder()
|
2023-08-07 23:06:00 +00:00
|
|
|
.application_id("com.luminescent-dreams.dashboard")
|
2023-08-08 21:25:21 +00:00
|
|
|
.resource_base_path("/com/luminescent-dreams/dashboard")
|
2023-08-07 23:06:00 +00:00
|
|
|
.build();
|
|
|
|
|
2023-08-09 16:53:14 +00:00
|
|
|
let latitude = Latitude::from(41.78);
|
|
|
|
let longitude = Longitude::from(-71.41);
|
|
|
|
|
2023-08-10 17:14:45 +00:00
|
|
|
let runtime = tokio::runtime::Builder::new_multi_thread()
|
|
|
|
.enable_all()
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
2023-08-07 23:06:00 +00:00
|
|
|
|
2023-08-09 16:53:14 +00:00
|
|
|
let core = Core {
|
|
|
|
tx: Arc::new(RwLock::new(None)),
|
|
|
|
};
|
|
|
|
|
2023-10-04 21:28:55 +00:00
|
|
|
runtime.spawn({
|
2023-08-09 16:53:14 +00:00
|
|
|
let core = core.clone();
|
|
|
|
async move {
|
|
|
|
let soluna_client = SolunaClient::new();
|
|
|
|
|
|
|
|
loop {
|
2023-08-10 13:11:05 +00:00
|
|
|
let transit = soluna_client
|
|
|
|
.request(latitude.clone(), longitude.clone(), Local::now())
|
|
|
|
.await;
|
|
|
|
|
|
|
|
let now = Local::now();
|
|
|
|
let state = State {
|
|
|
|
date: IFC::from(now.date_naive().with_year(12023).unwrap()),
|
|
|
|
next_event: EVENTS.next_event(now.with_timezone(&Utc)).unwrap(),
|
2023-08-10 16:35:48 +00:00
|
|
|
events: EVENTS.yearly_events(now.year()).unwrap(),
|
2023-08-10 13:11:05 +00:00
|
|
|
transit: Some(transit),
|
|
|
|
};
|
|
|
|
|
2023-08-09 16:53:14 +00:00
|
|
|
if let Some(ref gtk_tx) = *core.tx.read().unwrap() {
|
|
|
|
let _ = gtk_tx.send(Message::Refresh(state.clone()));
|
2023-09-21 13:37:56 +00:00
|
|
|
std::thread::sleep(std::time::Duration::from_secs(60));
|
|
|
|
} else {
|
|
|
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
2023-08-09 16:53:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
app.connect_activate(move |app| {
|
|
|
|
let (gtk_tx, gtk_rx) =
|
|
|
|
gtk::glib::MainContext::channel::<Message>(gtk::glib::PRIORITY_DEFAULT);
|
|
|
|
|
|
|
|
*core.tx.write().unwrap() = Some(gtk_tx);
|
|
|
|
|
2023-08-09 17:54:56 +00:00
|
|
|
let window = ApplicationWindow::new(app);
|
|
|
|
window.window.present();
|
2023-08-09 16:53:14 +00:00
|
|
|
|
2023-08-09 17:54:56 +00:00
|
|
|
gtk_rx.attach(None, {
|
|
|
|
let window = window.clone();
|
|
|
|
move |msg| {
|
|
|
|
let Message::Refresh(state) = msg;
|
|
|
|
ApplicationWindow::update_state(&window, state);
|
2023-08-09 16:53:14 +00:00
|
|
|
|
2023-08-09 17:54:56 +00:00
|
|
|
Continue(true)
|
2023-08-09 16:53:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-08 21:25:21 +00:00
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
ApplicationExtManual::run_with_args(&app, &args);
|
2023-08-10 17:14:45 +00:00
|
|
|
runtime.shutdown_background();
|
2023-07-28 18:42:25 +00:00
|
|
|
}
|