kegtui 1.0.0

Run Windows games/apps on macOS through wine
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
// Copyright (C) 2024 Ethan Uppal.
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, version 3 of the License only.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program.  If not, see <https://www.gnu.org/licenses/>.

use std::{
    borrow::Cow,
    collections::HashMap,
    env,
    ffi::{OsStr, OsString},
    fmt::Write,
    fs::{self, File},
    io,
    os::unix::fs::PermissionsExt,
    path::{Path, PathBuf},
    process::Command,
    sync::Arc,
    thread,
    time::Duration,
};

use crate::{
    app::App,
    app_config::{AppConfig, app_config_file_path, default_keg_location},
    view::{MenuItem, MenuItemAction, NavContext},
};
use app::{AsyncState, spawn_worker};
use color_eyre::{Result, eyre::Context};
use copy_dir::copy_dir;
use tar::Archive;
use view::NavAction;
use walkdir::WalkDir;
use xz2::read::XzDecoder;

pub mod app;
pub mod app_config;
pub mod checks;
pub mod keg;
pub mod keg_config;
pub mod keg_plist;
pub mod view;
pub mod views;

fn wait_for_enter() -> Result<()> {
    io::stdin().read_line(&mut String::new())?;
    Ok(())
}

fn prompt(prompt: &str, validate: impl Fn(&str) -> bool) -> Result<String> {
    use std::io::Write;

    let mut buffer = String::new();
    loop {
        print!("{prompt}");
        io::stdout().flush()?;
        io::stdin().read_line(&mut buffer)?;
        if validate(&buffer) {
            break;
        }
    }
    Ok(buffer)
}

fn spawn_thread_with_spinner<T: Send + 'static>(
    message: &str,
    work: impl FnOnce() -> Result<T> + Send + 'static,
) -> Result<T> {
    use std::io::Write;

    let spinner = ["|", "/", "-", "\\"];
    let mut i = 0;
    let thread = thread::spawn(work);
    print!("\x1B[?25l");
    while !thread.is_finished() {
        print!("{} {message}\r", spinner[i % spinner.len()]);
        io::stdout().flush()?;
        thread::sleep(Duration::from_millis(50));
        i += 1;
    }
    print!("\x1B[?25h");
    println!("  {message}");
    thread.join().expect("Thread panicked")
}

fn read_multiline_input(
    app: &App,
    initial: &str,
    editor_file: impl AsRef<OsStr>,
) -> Result<String> {
    let editor_file = editor_file.as_ref();
    fs::write(editor_file, initial)?;
    Command::new(&app.config.editor)
        .arg(editor_file)
        .spawn()?
        .wait()?;
    let contents = fs::read_to_string(editor_file)?;
    Ok(contents)
}

fn parse_winetricks(output: &str) -> Vec<(Cow<'_, str>, &str)> {
    let mut list = vec![];
    for line in output.lines() {
        if !line.is_empty()
            && let Some((lhs, rhs)) = line.split_once(' ')
        {
            let lhs = lhs.trim();
            let rhs = rhs.trim();
            list.push((
                if lhs.chars().all(|c| c == '_' || c.is_ascii_alphanumeric()) {
                    lhs.into()
                } else {
                    format!("\"{lhs}\"").into()
                },
                rhs,
            ));
        }
    }
    list
}

const KEGWORKS_WINETRICKS_SH: &str = "/tmp/kegworks_winetricks.sh";
const KEGWORKS_WINETRICKS_CACHE_TOML: &str =
    "/tmp/kegworks_winetricks_cache.toml";
const KEGWORKS_WINETRICKS_EDITOR_TOML: &str = "/tmp/kegtui_winetricks.toml";

pub fn winetricks(app: &mut App, _state: &AsyncState) -> Result<()> {
    let Some(current_keg) = &app.current_keg else {
        return Ok(());
    };

    if !Path::new(KEGWORKS_WINETRICKS_SH).is_file() {
        eprintln!("┌────────────────────────────┐");
        eprintln!("│ Fetching latest winetricks │");
        eprintln!("└────────────────────────────┘");
        Command::new("curl").args([
            "https://raw.githubusercontent.com/ethanuppal/winetricks/refs/heads/master/src/winetricks",
            "-o",
            KEGWORKS_WINETRICKS_SH
        ]).status()?;
    }
    fs::copy(
        KEGWORKS_WINETRICKS_SH,
        current_keg.wine_prefix.join("winetricks"),
    )?;
    fs::set_permissions(
        current_keg.wine_prefix.join("winetricks"),
        fs::Permissions::from_mode(0o777),
    )?;

    let initial = if let Ok(winetricks_toml_cached) =
        fs::read_to_string(KEGWORKS_WINETRICKS_CACHE_TOML)
    {
        winetricks_toml_cached
    } else {
        eprintln!("┌─────────────────────────────┐");
        eprintln!("│ Loading winetricks apps     │");
        let apps_list = String::from_utf8(
            Command::new("/bin/sh")
                .args([KEGWORKS_WINETRICKS_SH, "apps", "list"])
                .output()?
                .stdout,
        )?;
        let apps = parse_winetricks(&apps_list);

        eprintln!("│                    dlls     │");
        let dlls_list = String::from_utf8(
            Command::new("/bin/sh")
                .args([KEGWORKS_WINETRICKS_SH, "dlls", "list"])
                .output()?
                .stdout,
        )?;
        let dlls = parse_winetricks(&dlls_list);

        eprintln!("│                    fonts    │");
        let fonts_list = String::from_utf8(
            Command::new("/bin/sh")
                .args([KEGWORKS_WINETRICKS_SH, "fonts", "list"])
                .output()?
                .stdout,
        )?;
        let fonts = parse_winetricks(&fonts_list);

        eprintln!("│                    settings │");
        eprintln!("└─────────────────────────────┘");
        let settings_list = String::from_utf8(
            Command::new("/bin/sh")
                .args([KEGWORKS_WINETRICKS_SH, "settings", "list"])
                .output()?
                .stdout,
        )?;
        let settings = parse_winetricks(&settings_list);

        let mut winetricks_toml = String::from(
            "# Uncomment each winetrick to install\n# Save and quit your editor to select\n\n",
        );
        for (app, description) in apps {
            winetricks_toml
                .push_str(&format!("# app.{app} = \"{description}\"\n"));
        }
        for (dll, description) in dlls {
            winetricks_toml
                .push_str(&format!("# dll.{dll} = \"{description}\"\n"));
        }
        for (font, description) in fonts {
            winetricks_toml
                .push_str(&format!("# font.{font} = \"{description}\"\n"));
        }
        for (setting, description) in settings {
            winetricks_toml.push_str(&format!(
                "# setting.{setting} = \"{description}\"\n"
            ));
        }
        fs::write(KEGWORKS_WINETRICKS_CACHE_TOML, &winetricks_toml)?;
        winetricks_toml
    };
    let result =
        read_multiline_input(app, &initial, KEGWORKS_WINETRICKS_EDITOR_TOML)?;
    let selected_winetricks: HashMap<String, HashMap<String, String>> =
        toml::from_str(&result)?;
    let selected_winetricks =
        selected_winetricks.iter().fold(vec![], |mut list, map| {
            list.extend(map.1.keys());
            list
        });
    if !current_keg.winetricks_logfile.try_exists()? {
        fs::write(&current_keg.winetricks_logfile, "")?;
    }
    if !selected_winetricks.is_empty() {
        let mut console = Command::new("open")
            .arg(&current_keg.winetricks_logfile)
            .spawn()?;
        Command::new(&current_keg.wineskin_launcher)
            .arg("WSS-winetricks")
            .args(selected_winetricks)
            .status()?;
        console.kill()?;
    }

    Ok(())
}

pub fn clear_winetricks_cache(
    _app: &mut App,
    _state: &AsyncState,
) -> Result<()> {
    eprintln!("┌──────────────────────────────────┐");
    eprintln!("│ Press enter to return to the TUI │");
    eprintln!("└──────────────────────────────────┘");
    for file in [
        KEGWORKS_WINETRICKS_SH,
        KEGWORKS_WINETRICKS_CACHE_TOML,
        KEGWORKS_WINETRICKS_EDITOR_TOML,
    ] {
        if PathBuf::from(file).try_exists()? {
            fs::remove_file(file)?;
            eprintln!("rm {file}");
        }
    }
    wait_for_enter()?;

    Ok(())
}

pub fn open_c_drive(app: &mut App, _state: &AsyncState) -> Result<()> {
    let Some(current_keg) = &app.current_keg else {
        return Ok(());
    };
    Command::new(&app.config.explorer)
        .arg(current_keg.c_drive.to_string_lossy().to_string())
        .status()?;
    Ok(())
}

pub fn edit_config(app: &mut App, _state: &AsyncState) -> Result<()> {
    if let Some(current_keg) = &mut app.current_keg {
        let toml_config =
            toml::to_string_pretty(&current_keg.plist.extract_config())?;
        let file = "/tmp/kegtui.toml";
        fs::write(file, toml_config)?;
        Command::new(&app.config.editor).arg(file).status()?;
        let new_toml_config = toml::from_str(&fs::read_to_string(file)?)?;
        current_keg.plist.update_from_config(&new_toml_config);
        plist::to_file_xml(&current_keg.config_file, &current_keg.plist)?;
    }
    Ok(())
}

pub fn launch_keg(app: &mut App, _state: &AsyncState) -> Result<()> {
    if let Some(current_keg) = &app.current_keg {
        eprintln!("┌──────────────────────────────────┐");
        eprintln!("│ Launching this keg               │");
        eprintln!("│ Press enter to return to the TUI │");
        eprintln!("└──────────────────────────────────┘");
        let wrapper = current_keg.wineskin_launcher.clone();
        thread::spawn(move || {
            let _ = Command::new(wrapper).status();
        });
        app.open_kegs_wineskin_launchers
            .insert(current_keg.wineskin_launcher.clone());
        wait_for_enter()?;
    }
    Ok(())
}

fn kill_wineserver_via_wineskin_launcher(
    wineskin_launcher: &OsString,
) -> Result<()> {
    Command::new(wineskin_launcher)
        .arg("WSS-wineserverkill")
        .status()?;
    Ok(())
}

pub fn kill_wineserver(app: &mut App, _state: &AsyncState) -> Result<()> {
    if let Some(current_keg) = &app.current_keg {
        eprintln!("┌─────────────────────────────────────────┐");
        eprintln!("│ Killing processes spawned from this keg │");
        eprintln!("└─────────────────────────────────────────┘");
        kill_wineserver_via_wineskin_launcher(&current_keg.wineskin_launcher)?;
        app.open_kegs_wineskin_launchers
            .remove(&current_keg.wineskin_launcher);
    }
    Ok(())
}

fn kill_all_wineservers(app: &mut App, _state: &AsyncState) -> Result<()> {
    if app.open_kegs_wineskin_launchers.is_empty() {
        eprintln!("┌──────────────────────────────────┐");
        eprintln!("│ No kegs opened                   │");
        eprintln!("│ Press enter to return to the TUI │");
        eprintln!("└──────────────────────────────────┘");
        wait_for_enter()?;
    } else {
        eprintln!("┌─────────────────────────────────────────┐");
        eprintln!("│ Killing all processes spawned from kegs │");
        eprintln!("└─────────────────────────────────────────┘");
        for wineskin_launcher in app.open_kegs_wineskin_launchers.drain() {
            kill_wineserver_via_wineskin_launcher(&wineskin_launcher)?;
        }
    }
    Ok(())
}

pub fn create_keg(app: &mut App, state: &AsyncState) -> Result<()> {
    eprintln!("┌─────────────┐");
    eprintln!("│ Keg creator │");
    eprintln!("└─────────────┘");

    let mut creator_txt = String::from(
        "# Uncomment the engine and wrapper to use\n# Save and quit your editor to select\n# Select nothing to quit\n# If you don't see new engines or wrappers here, reopen kegtui\n\n",
    );
    for engine in &state.engines {
        writeln!(&mut creator_txt, "# {}", engine.path.display())?;
    }
    writeln!(&mut creator_txt)?;
    for wrapper in &state.wrappers {
        writeln!(&mut creator_txt, "# {}", wrapper.path.display())?;
    }

    enum Action {
        EngineAndWrapper { engine: String, wrapper: String },
        Quit,
    }

    let action;
    loop {
        let choices =
            read_multiline_input(app, &creator_txt, "/tmp/kegcreator.txt")?;

        let engine_and_wrapper = choices
            .lines()
            .map(|line| line.trim())
            .filter(|line| !line.is_empty() && !line.starts_with("#"))
            .collect::<Vec<_>>();

        if engine_and_wrapper.is_empty() {
            action = Action::Quit;
            break;
        } else if engine_and_wrapper.len() == 2 {
            let potential_engine = engine_and_wrapper[0];
            let potential_wrapper = engine_and_wrapper[1];
            println!("You have selected:");
            println!("  Engine:  {potential_engine}");
            println!("  Wrapper: {potential_wrapper}");
            let answer = prompt("Is this correct? [yY/nN/q] ", |answer| {
                ["y", "Y", "n", "N", "q"].contains(&answer.trim())
            })?;
            let answer = answer.trim();

            if ["y", "Y"].contains(&answer) {
                action = Action::EngineAndWrapper {
                    engine: potential_engine.to_owned(),
                    wrapper: potential_wrapper.to_owned(),
                };
                break;
            } else if answer == "q" {
                action = Action::Quit;
                break;
            }
        }
    }

    match action {
        Action::EngineAndWrapper { engine, wrapper } => {
            let home_directory = env::var("HOME")
                .expect("User missing home directory env variable");
            let keg_directory = PathBuf::from(
                default_keg_location().replace("~", &home_directory),
            );
            fs::create_dir_all(&keg_directory)
                .context("Failed to create keg directory")?;

            let mut keg_path;
            loop {
                let name = prompt("Name (can be changed later): ", |_| true)?;
                keg_path = keg_directory.join(format!("{}.app", name.trim()));
                if keg_path.try_exists().context(
                    "Failed to check if new keg location exists already",
                )? {
                    println!("{} already exists", keg_path.display());
                } else {
                    break;
                }
            }

            let engine_path = Path::new(&engine);
            let wrapper_path = Path::new(&wrapper);

            copy_dir(wrapper_path, &keg_path).context(format!(
                "Failed to copy wrapper ({wrapper}) to keg path ({})",
                keg_path.display()
            ))?;
            println!("  Copied template {wrapper} to {}", keg_path.display());

            const TMP_ENGINE: &str = "/tmp/kegtui_engine.tar";
            if Path::new(TMP_ENGINE).try_exists()? {
                fs::remove_file(TMP_ENGINE)
                    .context("Failed to remove temporary engine file")?;
            }

            let engine_pathbuf = engine_path.to_owned();
            spawn_thread_with_spinner(
                &format!("Decoding {engine} to {TMP_ENGINE}..."),
                move || {
                    let engine_xz = File::open(engine_pathbuf)
                        .context("Failed to open engine tarball")?;
                    let mut engine_tmp = File::create(TMP_ENGINE)
                        .context("Failed to create temporary engine file")?;
                    io::copy(&mut XzDecoder::new(engine_xz), &mut engine_tmp)
                        .context("Failed to decode engine XZ")?;
                    Ok(())
                },
            )?;

            let keg_path_copy = keg_path.clone();
            let wine_folder = spawn_thread_with_spinner(
                &format!(
                    "Unpacking {TMP_ENGINE} into {}...",
                    keg_path.display()
                ),
                move || {
                    let engine_tmp = File::open(TMP_ENGINE)
                        .context("Failed to create temporary engine file")?;
                    let mut archive = Archive::new(engine_tmp);
                    let parent = keg_path_copy.join("Contents/SharedSupport");
                    fs::create_dir_all(&parent).context(
                        "Failed to create directory in keg to place engine",
                    )?;
                    archive
                        .unpack(&parent)
                        .context("Failed to move engine into keg")?;
                    let unpacked_folder = parent.join("wswine.bundle"); // Not sure how to programmatically determine this
                    let wine_folder = parent.join("wine");
                    fs::rename(unpacked_folder, &wine_folder)?;
                    Ok(wine_folder)
                },
            )?;

            let permissions = fs::Permissions::from_mode(0o777);
            for entry in WalkDir::new(&keg_path) {
                if let Ok(entry) = entry
                    && entry.file_type().is_file()
                {
                    fs::set_permissions(entry.path(), permissions.clone())?;
                }
            }
            fs::set_permissions(wine_folder, permissions)?;

            for entry in WalkDir::new(&keg_path) {
                if let Ok(entry) = entry
                    && entry.file_type().is_file()
                {
                    let _ = xattrs::remove_xattr(
                        entry.path(),
                        "com.apple.quarantine",
                    );
                }
            }
            let _ =
                xattrs::remove_xattr(keg_path.clone(), "com.apple.quarantine");

            let output =
                Command::new(keg_path.join("Contents/MacOS/wineskinlauncher"))
                    .arg("WSS-wineprefixcreate")
                    .spawn()?
                    .wait_with_output()?;

            if !output.status.success() {
                use std::io::Write;

                eprintln!("FAILED");
                eprintln!("== STDOUT ==");
                io::stdout().write_all(&output.stdout)?;
                eprintln!("== STDERR ==");
                io::stdout().write_all(&output.stderr)?;
                eprintln!("\nPlease try again");
            } else {
                eprintln!("┌──────────────────────────────────┐");
                eprintln!("│ Created your keg!                │");
                eprintln!("│ Press enter to return to the TUI │");
                eprintln!("└──────────────────────────────────┘");
            }
            wait_for_enter()?;
        }
        Action::Quit => {
            eprintln!("Quitting Keg creator");
        }
    }

    Ok(())
}

fn setup_wizard(_app: &mut App, _state: &AsyncState) -> Result<()> {
    const COMMAND: &str = "curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ethanuppal/kegtui/refs/heads/main/download.sh | sh";

    eprintln!("┌──────────────┐");
    eprintln!("│ Setup wizard │");
    eprintln!("└──────────────┘");
    println!("kegtui will now run the following command:");
    println!("  {COMMAND}");

    let answer = prompt("Is this ok? [yY/nN] ", |answer| {
        ["y", "Y", "n", "N"].contains(&answer.trim())
    })?;
    let answer = answer.trim();

    if ["y", "Y"].contains(&answer) {
        Command::new("sh").args(["-c", COMMAND]).spawn()?.wait()?;

        eprintln!("┌──────────────────────────────────┐");
        eprintln!("│ Press enter to return to the TUI │");
        eprintln!("└──────────────────────────────────┘");
        wait_for_enter()?;
    }

    Ok(())
}

fn main() -> Result<()> {
    let mut context = NavContext::default();

    let kegs_view = context.view("kegs", &views::kegs::KegsView);
    let credits_view = context.view("credits", &views::credits::CreditsView);

    let main_nav = context.nav(
        "main",
        [
            MenuItem::new("Kegs", MenuItemAction::LoadView(kegs_view)),
            MenuItem::new("Create Keg", MenuItemAction::External(create_keg)),
            MenuItem::new(
                "Kill All Kegs",
                MenuItemAction::External(kill_all_wineservers),
            ),
            MenuItem::new(
                "Clear Winetricks Cache",
                MenuItemAction::External(clear_winetricks_cache),
            ),
            MenuItem::new(
                "Setup Wizard",
                MenuItemAction::External(setup_wizard),
            ),
            MenuItem::new("Credits", MenuItemAction::LoadView(credits_view)),
        ],
    );

    context.nav(
        "keg",
        [
            MenuItem::new("Back", MenuItemAction::NavAction(NavAction::Pop)),
            MenuItem::new("Launch", MenuItemAction::External(launch_keg))
                .default(),
            MenuItem::new("Winetricks", MenuItemAction::External(winetricks)),
            MenuItem::new(
                "Open C Drive",
                MenuItemAction::External(open_c_drive),
            ),
            MenuItem::new("Edit Config", MenuItemAction::External(edit_config)),
            MenuItem::new(
                "Kill Processes",
                MenuItemAction::External(kill_wineserver),
            )
            .default(),
        ],
    );

    let app_config_file_path = app_config_file_path();
    if !app_config_file_path.try_exists().unwrap_or_else(|_| {
        panic!(
            "Failed to check existence of {}",
            app_config_file_path.display()
        )
    }) {
        let parent_directory = app_config_file_path
            .parent()
            .expect("app_config_file_path should be a full path to the file");
        fs::create_dir_all(parent_directory).unwrap_or_else(|_| {
            panic!("Failed to create directory {}", parent_directory.display())
        });
        fs::write(&app_config_file_path, "").unwrap_or_else(|_| {
            panic!(
                "Failed to create empty config file at {}",
                app_config_file_path.display()
            )
        });
    }
    let app_config_file_contents = fs::read_to_string(&app_config_file_path)
        .unwrap_or_else(|_| {
            panic!(
                "Failed to read config file {} as string",
                app_config_file_path.display()
            )
        });
    let app_config = Arc::new(
        toml::from_str::<AppConfig>(&app_config_file_contents).unwrap_or_else(
            |_| {
                panic!(
                    "Failed to parse config file {}",
                    app_config_file_path.display()
                )
            },
        ),
    );

    let (async_state, _terminate_worker_guard) =
        spawn_worker(app_config.clone());

    color_eyre::install()?;
    let mut terminal = ratatui::init();
    let app_result = App::new(&app_config).run(
        &mut context,
        main_nav,
        &mut terminal,
        async_state,
    );
    ratatui::restore();
    app_result
}