zoodex/src/main.rs

60 lines
1.4 KiB
Rust
Raw Normal View History

2024-11-20 16:32:37 +01:00
mod collection ;
2024-11-29 21:06:14 +01:00
mod error ;
2024-11-20 16:32:37 +01:00
mod persistence ;
mod ui ;
mod utility ;
2024-12-24 01:18:05 +01:00
use {
gtk4 :: {
CssProvider ,
style_context_add_provider_for_display ,
STYLE_PROVIDER_PRIORITY_APPLICATION ,
gdk :: * ,
glib :: * ,
} ,
libadwaita :: { * , prelude :: * } } ;
2024-11-20 16:32:37 +01:00
use crate :: { error :: { * , ZoodexError :: * } , persistence :: * , ui :: * } ;
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 ,
) ;
}
fn show_window ( app : & Application ) {
let ui = UI :: new (app) ;
2024-11-20 16:32:37 +01:00
ui . show_window () ;
spawn_future_local ( async move {
async_unit_result_context (
async {
2024-12-22 21:02:39 +01:00
let collection = get_collection_from_file () . await ? ;
ui . render_collection (collection) ;
Ok (())
} ,
|error| {
match error {
CollectionFileReadError => eprintln ! ("Could not read collection file") ,
} ;
ui . close_window () ;
} ,
) . await ;
2024-11-20 16:32:37 +01:00
} ) ;
}