72 lines
1.8 KiB
Rust
72 lines
1.8 KiB
Rust
mod error ;
|
|
mod data_manager ;
|
|
mod ui ;
|
|
mod utility ;
|
|
|
|
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 ;
|
|
use libadwaita :: prelude :: * ;
|
|
|
|
use crate :: data_manager :: * ;
|
|
use crate :: error :: * ;
|
|
use crate :: error :: ZoodexError :: * ;
|
|
use crate :: ui :: * ;
|
|
use crate :: utility :: * ;
|
|
|
|
|
|
|
|
fn main () -> ExitCode {
|
|
let application = Application :: builder ()
|
|
. application_id ("com.kernelmaft.zoodex")
|
|
. build () ;
|
|
application . connect_startup (add_style_provider) ;
|
|
application . connect_activate (show_window) ;
|
|
application . run ()
|
|
}
|
|
|
|
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 ,
|
|
) ;
|
|
}
|
|
|
|
fn show_window ( application : & Application ) {
|
|
let window = leak ( Window :: new (application) ) ;
|
|
|
|
spawn_future_local ( async move {
|
|
async_result_context ! (
|
|
async {
|
|
// 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| {
|
|
data_manager . get_film_details (film_uuid) . await
|
|
. expect ("A film with the given UUID should exist")
|
|
} ,
|
|
) ;
|
|
window . show () ;
|
|
|
|
let collection = data_manager . get_collection_overview () . await ? ;
|
|
ui . render_collection_overview (collection) . await ;
|
|
Ok (())
|
|
} ,
|
|
err => |error| {
|
|
match error {
|
|
CollectionFileReadError => eprintln ! ("Could not read collection file") ,
|
|
} ;
|
|
window . close () ;
|
|
} ,
|
|
) ;
|
|
} ) ;
|
|
}
|