-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
93 lines (84 loc) · 3.34 KB
/
Copy pathProgram.cs
File metadata and controls
93 lines (84 loc) · 3.34 KB
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
using Velopack;
using TTNOverlay.Overlay;
using TTNOverlay.Services;
using TTNOverlay.Native;
namespace TTNOverlay;
/// <summary>
/// Application entry point: loads settings, applies theme/language, and starts the native overlay window.
/// </summary>
internal static class Program
{
[STAThread]
private static void Main()
{
VelopackApp.Build().Run();
DebugLog.Write("App starting. Log in: " + DebugLog.FilePath);
AppDomain.CurrentDomain.UnhandledException += (_, args) =>
{
if (args.ExceptionObject is Exception ex)
DebugLog.WriteException("AppDomain.UnhandledException", ex);
DebugLog.FlushNow();
};
TaskScheduler.UnobservedTaskException += (_, args) =>
{
DebugLog.WriteException("UnobservedTaskException", args.Exception);
DebugLog.FlushNow();
args.SetObserved();
};
var settings = SettingsService.Load();
DebugLog.Enabled = settings.EnableDebugMode;
ThemeService.Apply(settings.Theme);
LocalizationService.Instance.SetLanguage(AppLanguageExtensions.FromSettingsLabel(settings.Language));
try
{
using var chatRenderWindow = new ChatRenderWindow();
chatRenderWindow.Create(
"TTNOverlay",
(int)settings.WindowLeft,
(int)settings.WindowTop,
(int)settings.WindowWidth,
(int)settings.WindowHeight,
visible: false
);
UpdateService.CheckForPendingReleaseNotesAndShow(chatRenderWindow.ShowReleaseNotesDialog);
// The overlay stays hidden (created above with visible: false) until the update prompt
// below has been shown (or skipped, if there's nothing to update). This way the update
// dialog is always the first thing the user sees on startup instead of appearing on top
// of an already-visible overlay a moment later.
_ = RunStartupUpdateCheckAsync(chatRenderWindow);
chatRenderWindow.RunMessageLoop();
}
catch (Exception ex)
{
DebugLog.WriteException("UnhandledException", ex);
Win32.MessageBoxW(
IntPtr.Zero,
$"Unhandled error:\n{ex.Message}\n\nDetail in:\n{DebugLog.FilePath}",
"TTNOverlay - Error",
Win32.MB_OK | Win32.MB_ICONERROR
);
}
finally
{
SharedGraphicsResources.Shutdown();
}
}
/// <summary>
/// Runs the startup update check and, whether or not an update prompt ends up being shown,
/// reveals the overlay window afterward via <see cref="OverlayWindowBase.ShowWindow"/> (which
/// itself hops to the UI thread, so this is safe to await from here). If an update is confirmed
/// and applied, the app restarts before this ever runs, so revealing the (about-to-be-replaced)
/// window is moot in that path.
/// </summary>
private static async Task RunStartupUpdateCheckAsync(ChatRenderWindow chatRenderWindow)
{
try
{
await UpdateService.CheckForUpdateAndPromptAsync(chatRenderWindow.ShowConfirmDialog, chatRenderWindow.ShowUpdateProgressDialog);
}
finally
{
chatRenderWindow.ShowWindow();
}
}
}