using Microsoft.Windows.AppLifecycle; using MBN_STOCK_WEBVIEW.Playout.Configuration; namespace MBN_STOCK_WEBVIEW.LegacyParityApp; public partial class App : Application { private const string MainInstanceKey = "Wickedness.MBNStockWebView.LegacyParity.Main"; private Window? _window; private AppInstance? _mainInstance; internal static bool IsDevelopmentLiveLaunch { get; private set; } internal static bool IsDevelopmentLiveLaunchRequested { get; private set; } public App() { InitializeComponent(); } protected override async void OnLaunched(LaunchActivatedEventArgs args) { var registeredInstance = AppInstance.FindOrRegisterForKey(MainInstanceKey); if (!registeredInstance.IsCurrent) { try { var activation = AppInstance.GetCurrent().GetActivatedEventArgs(); if (activation is not null) { await registeredInstance.RedirectActivationToAsync(activation); } } finally { Exit(); } return; } _mainInstance = registeredInstance; _mainInstance.Activated += OnMainInstanceActivated; #if DEBUG const bool isDebugBuild = true; #else const bool isDebugBuild = false; #endif #if SOURCE_ONLY_RUNTIME const bool isSourceOnlyBuild = true; #else const bool isSourceOnlyBuild = false; #endif var launchArguments = isSourceOnlyBuild ? null : DevelopmentLiveLaunchBootstrap.ResolveLaunchArguments( args.Arguments, Environment.GetCommandLineArgs()); IsDevelopmentLiveLaunchRequested = string.Equals( launchArguments, DevelopmentLiveLaunchBootstrap.ExactLaunchArgument, StringComparison.Ordinal); var developmentLive = DevelopmentLiveLaunchBootstrap.TryApply( launchArguments, isDebugBuild); IsDevelopmentLiveLaunch = developmentLive.IsApplied; System.Diagnostics.Debug.WriteLine( $"Development Live bootstrap: {developmentLive.Code}"); _window = new MainWindow(); _window.Activate(); } private void OnMainInstanceActivated(object? sender, AppActivationArguments args) { _window?.DispatcherQueue.TryEnqueue(_window.Activate); } }