casualexpiesource

cu-trainer/Ultra Paradise Linux/app/Program.cs

89 lines · 2.8 KB · plain text · download

1using System;
2using System.IO;
3using System.Linq;
4using System.Threading.Tasks;
5using Avalonia.Controls;
6using System.Reflection;
7using Avalonia;
8using Avalonia.Controls.ApplicationLifetimes;
9using Avalonia.Media;
10using Avalonia.Media.Imaging;
11using Avalonia.Themes.Fluent;
12
13[assembly: AssemblyMetadata("Notice", "Copyright (c) casualexpie. Source available at https://opensource.smellypawz.com under the casualexpie Source-Available License. Don't redistribute, sell or reuse it without permission.")]
14
15namespace UltraParadise.Linux
16{
17 internal static class Program
18 {
19 public const string Name = "Ultra Paradise CU:Trainer";
20 public const string Version = "2.0.14";
21 public static string[] Args = Array.Empty<string>();
22 public static string Platform => OperatingSystem.IsMacOS() ? "macOS" : "Linux";
23
24 [STAThread]
25 public static int Main(string[] args)
26 {
27 Args = args;
28 Settings.Load();
29 Ui.Load();
30 Bark.LoadSaved();
31 return AppBuilder.Configure<App>()
32 .UsePlatformDetect()
33 .WithInterFont()
34 .LogToTrace()
35 .StartWithClassicDesktopLifetime(args);
36 }
37
38 public static Bitmap Image(string name)
39 {
40 using Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
41 return s == null ? null : new Bitmap(s);
42 }
43 }
44
45 internal sealed class App : Application
46 {
47 public override void Initialize()
48 {
49 Styles.Add(new FluentTheme());
50 if (Ui.Base == "system") Ui.Apply();
51 Ui.ApplyApp();
52 }
53
54 public override void OnFrameworkInitializationCompleted()
55 {
56 if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime d)
57 {
58 d.ShutdownMode = ShutdownMode.OnExplicitShutdown;
59 Flow(d);
60 }
61 base.OnFrameworkInitializationCompleted();
62 }
63
64 private static Task Shown(Window w)
65 {
66 TaskCompletionSource tcs = new();
67 w.Closed += (_, _) => tcs.TrySetResult();
68 w.Show();
69 return tcs.Task;
70 }
71
72 private static async void Flow(IClassicDesktopStyleApplicationLifetime d)
73 {
74 bool skip = Program.Args.Contains("--updated") || Program.Args.Contains("--installed");
75 if (!skip)
76 {
77 LauncherWindow l = new();
78 await Shown(l);
79 if (l.Restarting) { d.Shutdown(); return; }
80 }
81 if (Settings.On("splash", true)) await Shown(new SplashWindow());
82 MainWindow m = new();
83 d.MainWindow = m;
84 m.Closed += (_, _) => d.Shutdown();
85
86 m.Show();
87 }
88 }
89}