aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/main.rs
blob: 9161263c20226122ddc45bca5b8939301b17006b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
mod core;
mod launcher;
mod ui;

use tokio::sync::mpsc;
use tokio::runtime::Runtime;
use std::thread;

fn main() {
    // channel for UI -> Backend
    let (tx, mut rx) = mpsc::channel(32);

    // Spawn Tokio runtime in a background thread
    thread::spawn(move || {
        let rt = Runtime::new().unwrap();
        rt.block_on(async move {
            println!("Backend started");
            while let Some(msg) = rx.recv().await {
                match msg {
                    ui::UiEvent::StartGame => {
                        println!("Backend received StartGame");
                        match core::manifest::fetch_version_manifest().await {
                            Ok(manifest) => {
                                println!("Fetched manifest. Latest release: {}", manifest.latest.release);
                                println!("Latest snapshot: {}", manifest.latest.snapshot);
                            }
                            Err(e) => {
                                eprintln!("Error fetching manifest: {}", e);
                            }
                        }
                    }
                }
            }
        });
    });

    // Run UI on main thread (must be main thread for GTK on some platforms)
    ui::init(tx);
}