using System.Windows;
using System.Windows.Threading;
using ytLive.Helpers;

namespace ytLive;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
    public App()
    {
        AppLog.Write("App ctor");
    }

    protected override void OnStartup(StartupEventArgs e)
    {
        // The app is a WinExe (no visible console) and is often debugged from
        // WSL where it can't even run, so startup checkpoints and any unhandled
        // exception are written to %APPDATA%\ytLlive\startup.log via AppLog.
        AppDomain.CurrentDomain.UnhandledException += (_, args) =>
            AppLog.Write(args.ExceptionObject is Exception ex
                ? "AppDomain unhandled exception: " + ex
                : "AppDomain unhandled exception object: " + args.ExceptionObject);

        DispatcherUnhandledException += (_, args) =>
            AppLog.Write(args.Exception, "Dispatcher unhandled exception");

        AppLog.Write("App OnStartup begin");
        base.OnStartup(e);
        AppLog.Write("App OnStartup end");
    }
}
