From 1b7fb26bc42a5e090dd6a028672209d3c1ef5a41 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Fri, 1 Aug 2025 14:23:11 +0200 Subject: [PATCH] change program to async/await --- EDPlayerJournal | 2 +- src/Construction/Colony.cs | 2 +- src/Construction/Depot.cs | 2 +- src/Edith.cs | 38 +++++++++++++++++++++++++++++++++++--- src/Program.cs | 4 ++-- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/EDPlayerJournal b/EDPlayerJournal index f21bf5e..ed68876 160000 --- a/EDPlayerJournal +++ b/EDPlayerJournal @@ -1 +1 @@ -Subproject commit f21bf5ea5e3116fb1ec44bb90d2917506862d66e +Subproject commit ed68876300b2b32b97c2dfc436f3fb98e7f1a45d diff --git a/src/Construction/Colony.cs b/src/Construction/Colony.cs index 0a3cbb3..63edd3a 100644 --- a/src/Construction/Colony.cs +++ b/src/Construction/Colony.cs @@ -25,7 +25,7 @@ internal class Colony : ITreeNode { } public override string ToString() { - return $" ☀ {System.Name}"; + return $" {System.Name}"; } } diff --git a/src/Construction/Depot.cs b/src/Construction/Depot.cs index 2043ee3..9176fc8 100644 --- a/src/Construction/Depot.cs +++ b/src/Construction/Depot.cs @@ -28,6 +28,6 @@ internal class Depot : ITreeNode { public override string ToString() { string percent = (Progress * 100.0).ToString("00.0"); - return String.Format($" ⚓ {percent}% {Station.Name}"); + return String.Format($" {percent}% {Station.Name}"); } } diff --git a/src/Edith.cs b/src/Edith.cs index df3d884..4278194 100644 --- a/src/Edith.cs +++ b/src/Edith.cs @@ -22,6 +22,8 @@ internal class Edith { private static Edith instance = new(); public static Edith Instance => instance; + private bool quit = false; + private Edith() { } @@ -39,7 +41,32 @@ internal class Edith { } } - public void Run() { + private async Task ProcessQueue() { + while (watcher != null) { + watcher.ProcessQueues(); + await Task.Delay(100); + } + } + + private async Task RunGUILoop() { + RunState state; + bool first = true; + + if (window == null) { + return; + } + + state = Application.Begin(window); + + while (!quit) { + Application.RunLoop(state); + await Task.Delay(100); + } + + Application.End(state); + } + + public async Task Run() { try { SetupJournal(); } catch (Exception e) { @@ -47,10 +74,15 @@ internal class Edith { return; } + Application.Init(); + window = new MainWindow(); - Application.Init(); - Application.Run(window); + Task gui = Task.Run(RunGUILoop); + Task queue = Task.Run(ProcessQueue); + + await Task.WhenAll([gui, queue]); + window.Dispose(); } } diff --git a/src/Program.cs b/src/Program.cs index 437db10..1ca886c 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -2,7 +2,7 @@ public class Program { - public static void Main(string[] args) { - Edith.Instance.Run(); + public static async Task Main(string[] args) { + await Edith.Instance.Run(); } } \ No newline at end of file