zoodex/src/main.rs

72 lines
1.8 KiB
Rust
Raw Normal View History

2024-11-29 21:06:14 +01:00
mod error ;
2025-02-05 00:03:26 +01:00
mod data_manager ;
2024-11-20 16:32:37 +01:00
mod ui ;
mod utility ;
2025-02-05 14:57:07 +01:00
use gtk4 :: CssProvider ;
use gtk4 :: style_context_add_provider_for_display ;
use gtk4 :: STYLE_PROVIDER_PRIORITY_APPLICATION ;
use gtk4 :: gdk :: * ;
use gtk4 :: glib :: * ;
use libadwaita :: Application ;
2025-02-05 14:57:07 +01:00
use libadwaita :: prelude :: * ;
2024-11-20 16:32:37 +01:00
2025-02-05 14:57:07 +01:00
use crate :: data_manager :: * ;
use crate :: error :: * ;
use crate :: error :: ZoodexError :: * ;
use crate :: ui :: * ;
use crate :: utility :: * ;
2024-11-20 16:32:37 +01:00
fn main () -> ExitCode {
let application = Application :: builder ()
. application_id ("com.kernelmaft.zoodex")
. build () ;
2024-12-24 01:18:05 +01:00
application . connect_startup (add_style_provider) ;
application . connect_activate (show_window) ;
2024-11-20 16:32:37 +01:00
application . run ()
}
2024-12-24 01:18:05 +01:00
fn add_style_provider ( _ : & Application ) {
let style_provider = CssProvider :: new () ;
style_provider . load_from_string ( include_str ! ("application.css") ) ;
style_context_add_provider_for_display (
& Display :: default () . unwrap () ,
& style_provider ,
STYLE_PROVIDER_PRIORITY_APPLICATION ,
) ;
}
2025-02-05 14:57:07 +01:00
fn show_window ( application : & Application ) {
let window = leak ( Window :: new (application) ) ;
2024-11-20 16:32:37 +01:00
spawn_future_local ( async move {
2025-02-12 11:34:38 +01:00
async_result_context ! (
async {
2026-01-01 14:34:13 +01:00
// TODO: Move non-UI async tasks to non-local context
let data_manager = leak ( DataManager :: new () . await ? ) ;
let ui = UI :: new (
window ,
async |film_uuid| {
2025-02-18 18:31:05 +01:00
data_manager . get_film_details (film_uuid) . await
. expect ("A film with the given UUID should exist")
} ,
) ;
window . show () ;
2025-02-12 11:34:38 +01:00
let collection = data_manager . get_collection_overview () . await ? ;
2025-02-05 13:51:22 +01:00
ui . render_collection_overview (collection) . await ;
Ok (())
} ,
2025-02-12 11:34:38 +01:00
err => |error| {
match error {
CollectionFileReadError => eprintln ! ("Could not read collection file") ,
} ;
window . close () ;
} ,
2025-02-12 11:34:38 +01:00
) ;
2024-11-20 16:32:37 +01:00
} ) ;
}