MainWindow.axaml.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Input;
  4. using Avalonia.Interactivity;
  5. using Avalonia.Media;
  6. using Avalonia.Threading;
  7. using FluentAvalonia.UI.Controls;
  8. using Ryujinx.Ava.Common;
  9. using Ryujinx.Ava.Common.Locale;
  10. using Ryujinx.Ava.Input;
  11. using Ryujinx.Ava.Ui.Applet;
  12. using Ryujinx.Ava.Ui.Controls;
  13. using Ryujinx.Ava.Ui.Models;
  14. using Ryujinx.Ava.Ui.ViewModels;
  15. using Ryujinx.Common.Configuration;
  16. using Ryujinx.Common.Logging;
  17. using Ryujinx.Graphics.Gpu;
  18. using Ryujinx.HLE.FileSystem;
  19. using Ryujinx.HLE.HOS;
  20. using Ryujinx.HLE.HOS.Services.Account.Acc;
  21. using Ryujinx.Input.SDL2;
  22. using Ryujinx.Modules;
  23. using Ryujinx.Ui.App.Common;
  24. using Ryujinx.Ui.Common;
  25. using Ryujinx.Ui.Common.Configuration;
  26. using SixLabors.ImageSharp.PixelFormats;
  27. using System;
  28. using System.ComponentModel;
  29. using System.IO;
  30. using System.Threading;
  31. using System.Threading.Tasks;
  32. using InputManager = Ryujinx.Input.HLE.InputManager;
  33. namespace Ryujinx.Ava.Ui.Windows
  34. {
  35. public partial class MainWindow : StyleableWindow
  36. {
  37. private bool _canUpdate;
  38. private bool _isClosing;
  39. private bool _isLoading;
  40. private Control _mainViewContent;
  41. private UserChannelPersistence _userChannelPersistence;
  42. private static bool _deferLoad;
  43. private static string _launchPath;
  44. private static bool _startFullscreen;
  45. private string _currentEmulatedGamePath;
  46. internal readonly AvaHostUiHandler UiHandler;
  47. private AutoResetEvent _rendererWaitEvent;
  48. public VirtualFileSystem VirtualFileSystem { get; private set; }
  49. public ContentManager ContentManager { get; private set; }
  50. public AccountManager AccountManager { get; private set; }
  51. public LibHacHorizonManager LibHacHorizonManager { get; private set; }
  52. internal AppHost AppHost { get; private set; }
  53. public InputManager InputManager { get; private set; }
  54. internal RendererControl RendererControl { get; private set; }
  55. internal MainWindowViewModel ViewModel { get; private set; }
  56. public SettingsWindow SettingsWindow { get; set; }
  57. public bool CanUpdate
  58. {
  59. get => _canUpdate;
  60. set
  61. {
  62. _canUpdate = value;
  63. Dispatcher.UIThread.InvokeAsync(() => UpdateMenuItem.IsEnabled = _canUpdate);
  64. }
  65. }
  66. public static bool ShowKeyErrorOnLoad { get; set; }
  67. public ApplicationLibrary ApplicationLibrary { get; set; }
  68. public MainWindow()
  69. {
  70. ViewModel = new MainWindowViewModel(this);
  71. DataContext = ViewModel;
  72. InitializeComponent();
  73. Load();
  74. UiHandler = new AvaHostUiHandler(this);
  75. Title = $"Ryujinx {Program.Version}";
  76. Height = Height / Program.WindowScaleFactor;
  77. Width = Width / Program.WindowScaleFactor;
  78. if (Program.PreviewerDetached)
  79. {
  80. Initialize();
  81. ViewModel.Initialize();
  82. InputManager = new InputManager(new AvaloniaKeyboardDriver(this), new SDL2GamepadDriver());
  83. LoadGameList();
  84. }
  85. _rendererWaitEvent = new AutoResetEvent(false);
  86. }
  87. public void LoadGameList()
  88. {
  89. if (_isLoading)
  90. {
  91. return;
  92. }
  93. _isLoading = true;
  94. ViewModel.LoadApplications();
  95. _isLoading = false;
  96. }
  97. private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
  98. {
  99. if (ViewModel.ShowMenuAndStatusBar && !ViewModel.ShowLoadProgress)
  100. {
  101. Dispatcher.UIThread.InvokeAsync(() =>
  102. {
  103. if (args.VSyncEnabled)
  104. {
  105. ViewModel.VsyncColor = new SolidColorBrush(Color.Parse("#ff2eeac9"));
  106. }
  107. else
  108. {
  109. ViewModel.VsyncColor = new SolidColorBrush(Color.Parse("#ffff4554"));
  110. }
  111. ViewModel.DockedStatusText = args.DockedMode;
  112. ViewModel.AspectRatioStatusText = args.AspectRatio;
  113. ViewModel.GameStatusText = args.GameStatus;
  114. ViewModel.FifoStatusText = args.FifoStatus;
  115. ViewModel.GpuNameText = args.GpuName;
  116. ViewModel.BackendText = args.GpuBackend;
  117. ViewModel.ShowStatusSeparator = true;
  118. });
  119. }
  120. }
  121. public void Application_Opened(object sender, ApplicationOpenedEventArgs args)
  122. {
  123. if (args.Application != null)
  124. {
  125. ViewModel.SelectedIcon = args.Application.Icon;
  126. string path = new FileInfo(args.Application.Path).FullName;
  127. LoadApplication(path);
  128. }
  129. args.Handled = true;
  130. }
  131. public async Task PerformanceCheck()
  132. {
  133. if (ConfigurationState.Instance.Logger.EnableTrace.Value)
  134. {
  135. string mainMessage = LocaleManager.Instance["DialogPerformanceCheckLoggingEnabledMessage"];
  136. string secondaryMessage = LocaleManager.Instance["DialogPerformanceCheckLoggingEnabledConfirmMessage"];
  137. UserResult result = await ContentDialogHelper.CreateConfirmationDialog(mainMessage, secondaryMessage,
  138. LocaleManager.Instance["InputDialogYes"], LocaleManager.Instance["InputDialogNo"],
  139. LocaleManager.Instance["RyujinxConfirm"]);
  140. if (result != UserResult.Yes)
  141. {
  142. ConfigurationState.Instance.Logger.EnableTrace.Value = false;
  143. SaveConfig();
  144. }
  145. }
  146. if (!string.IsNullOrWhiteSpace(ConfigurationState.Instance.Graphics.ShadersDumpPath.Value))
  147. {
  148. string mainMessage = LocaleManager.Instance["DialogPerformanceCheckShaderDumpEnabledMessage"];
  149. string secondaryMessage =
  150. LocaleManager.Instance["DialogPerformanceCheckShaderDumpEnabledConfirmMessage"];
  151. UserResult result = await ContentDialogHelper.CreateConfirmationDialog(mainMessage, secondaryMessage,
  152. LocaleManager.Instance["InputDialogYes"], LocaleManager.Instance["InputDialogNo"],
  153. LocaleManager.Instance["RyujinxConfirm"]);
  154. if (result != UserResult.Yes)
  155. {
  156. ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = "";
  157. SaveConfig();
  158. }
  159. }
  160. }
  161. internal static void DeferLoadApplication(string launchPathArg, bool startFullscreenArg)
  162. {
  163. _deferLoad = true;
  164. _launchPath = launchPathArg;
  165. _startFullscreen = startFullscreenArg;
  166. }
  167. #pragma warning disable CS1998
  168. public async void LoadApplication(string path, bool startFullscreen = false, string titleName = "")
  169. #pragma warning restore CS1998
  170. {
  171. if (AppHost != null)
  172. {
  173. await ContentDialogHelper.CreateInfoDialog(
  174. LocaleManager.Instance["DialogLoadAppGameAlreadyLoadedMessage"],
  175. LocaleManager.Instance["DialogLoadAppGameAlreadyLoadedSubMessage"],
  176. LocaleManager.Instance["InputDialogOk"],
  177. "",
  178. LocaleManager.Instance["RyujinxInfo"]);
  179. return;
  180. }
  181. #if RELEASE
  182. await PerformanceCheck();
  183. #endif
  184. Logger.RestartTime();
  185. if (ViewModel.SelectedIcon == null)
  186. {
  187. ViewModel.SelectedIcon = ApplicationLibrary.GetApplicationIcon(path);
  188. }
  189. PrepareLoadScreen();
  190. _mainViewContent = MainContent.Content as Control;
  191. RendererControl = Program.UseVulkan ? new VulkanRendererControl(ConfigurationState.Instance.Logger.GraphicsDebugLevel) : new OpenGLRendererControl(3, 3, ConfigurationState.Instance.Logger.GraphicsDebugLevel);
  192. AppHost = new AppHost(RendererControl, InputManager, path, VirtualFileSystem, ContentManager, AccountManager, _userChannelPersistence, this);
  193. if (!AppHost.LoadGuestApplication().Result)
  194. {
  195. AppHost.DisposeContext();
  196. return;
  197. }
  198. ViewModel.LoadHeading = string.IsNullOrWhiteSpace(titleName) ? string.Format(LocaleManager.Instance["LoadingHeading"], AppHost.Device.Application.TitleName) : titleName;
  199. ViewModel.TitleName = string.IsNullOrWhiteSpace(titleName) ? AppHost.Device.Application.TitleName : titleName;
  200. SwitchToGameControl(startFullscreen);
  201. _currentEmulatedGamePath = path;
  202. Thread gameThread = new Thread(InitializeGame)
  203. {
  204. Name = "GUI.WindowThread"
  205. };
  206. gameThread.Start();
  207. }
  208. private void InitializeGame()
  209. {
  210. RendererControl.RendererInitialized += GlRenderer_Created;
  211. AppHost.StatusUpdatedEvent += Update_StatusBar;
  212. AppHost.AppExit += AppHost_AppExit;
  213. _rendererWaitEvent.WaitOne();
  214. AppHost?.Start();
  215. AppHost.DisposeContext();
  216. }
  217. private void HandleRelaunch()
  218. {
  219. if (_userChannelPersistence.PreviousIndex != -1 && _userChannelPersistence.ShouldRestart)
  220. {
  221. _userChannelPersistence.ShouldRestart = false;
  222. Dispatcher.UIThread.Post(() =>
  223. {
  224. LoadApplication(_currentEmulatedGamePath);
  225. });
  226. }
  227. else
  228. {
  229. // otherwise, clear state.
  230. _userChannelPersistence = new UserChannelPersistence();
  231. _currentEmulatedGamePath = null;
  232. }
  233. }
  234. public void SwitchToGameControl(bool startFullscreen = false)
  235. {
  236. ViewModel.ShowContent = true;
  237. ViewModel.ShowLoadProgress = false;
  238. ViewModel.IsLoadingIndeterminate = false;
  239. Dispatcher.UIThread.InvokeAsync(() =>
  240. {
  241. MainContent.Content = RendererControl;
  242. if (startFullscreen && WindowState != WindowState.FullScreen)
  243. {
  244. ViewModel.ToggleFullscreen();
  245. }
  246. RendererControl.Focus();
  247. });
  248. }
  249. public void ShowLoading(bool startFullscreen = false)
  250. {
  251. ViewModel.ShowContent = false;
  252. ViewModel.ShowLoadProgress = true;
  253. ViewModel.IsLoadingIndeterminate = true;
  254. Dispatcher.UIThread.InvokeAsync(() =>
  255. {
  256. if (startFullscreen && WindowState != WindowState.FullScreen)
  257. {
  258. ViewModel.ToggleFullscreen();
  259. }
  260. });
  261. }
  262. private void GlRenderer_Created(object sender, EventArgs e)
  263. {
  264. ShowLoading();
  265. _rendererWaitEvent.Set();
  266. }
  267. private void AppHost_AppExit(object sender, EventArgs e)
  268. {
  269. if (_isClosing)
  270. {
  271. return;
  272. }
  273. ViewModel.IsGameRunning = false;
  274. Dispatcher.UIThread.InvokeAsync(() =>
  275. {
  276. if (MainContent.Content != _mainViewContent)
  277. {
  278. MainContent.Content = _mainViewContent;
  279. }
  280. ViewModel.ShowMenuAndStatusBar = true;
  281. ViewModel.ShowContent = true;
  282. ViewModel.ShowLoadProgress = false;
  283. ViewModel.IsLoadingIndeterminate = false;
  284. Cursor = Cursor.Default;
  285. AppHost = null;
  286. HandleRelaunch();
  287. });
  288. RendererControl.RendererInitialized -= GlRenderer_Created;
  289. RendererControl = null;
  290. ViewModel.SelectedIcon = null;
  291. Dispatcher.UIThread.InvokeAsync(() =>
  292. {
  293. Title = $"Ryujinx {Program.Version}";
  294. });
  295. }
  296. public void Sort_Checked(object sender, RoutedEventArgs args)
  297. {
  298. if (sender is RadioButton button)
  299. {
  300. var sort = Enum.Parse<ApplicationSort>(button.Tag.ToString());
  301. ViewModel.Sort(sort);
  302. }
  303. }
  304. protected override void HandleWindowStateChanged(WindowState state)
  305. {
  306. WindowState = state;
  307. if (state != WindowState.Minimized)
  308. {
  309. Renderer.Start();
  310. }
  311. }
  312. public void Order_Checked(object sender, RoutedEventArgs args)
  313. {
  314. if (sender is RadioButton button)
  315. {
  316. var tag = button.Tag.ToString();
  317. ViewModel.Sort(tag != "Descending");
  318. }
  319. }
  320. private void Initialize()
  321. {
  322. _userChannelPersistence = new UserChannelPersistence();
  323. VirtualFileSystem = VirtualFileSystem.CreateInstance();
  324. LibHacHorizonManager = new LibHacHorizonManager();
  325. ContentManager = new ContentManager(VirtualFileSystem);
  326. LibHacHorizonManager.InitializeFsServer(VirtualFileSystem);
  327. LibHacHorizonManager.InitializeArpServer();
  328. LibHacHorizonManager.InitializeBcatServer();
  329. LibHacHorizonManager.InitializeSystemClients();
  330. ApplicationLibrary = new ApplicationLibrary(VirtualFileSystem);
  331. // Save data created before we supported extra data in directory save data will not work properly if
  332. // given empty extra data. Luckily some of that extra data can be created using the data from the
  333. // save data indexer, which should be enough to check access permissions for user saves.
  334. // Every single save data's extra data will be checked and fixed if needed each time the emulator is opened.
  335. // Consider removing this at some point in the future when we don't need to worry about old saves.
  336. VirtualFileSystem.FixExtraData(LibHacHorizonManager.RyujinxClient);
  337. AccountManager = new AccountManager(LibHacHorizonManager.RyujinxClient, Program.CommandLineProfile);
  338. VirtualFileSystem.ReloadKeySet();
  339. ApplicationHelper.Initialize(VirtualFileSystem, AccountManager, LibHacHorizonManager.RyujinxClient, this);
  340. RefreshFirmwareStatus();
  341. }
  342. protected void CheckLaunchState()
  343. {
  344. if (ShowKeyErrorOnLoad)
  345. {
  346. ShowKeyErrorOnLoad = false;
  347. Dispatcher.UIThread.Post(async () => await
  348. UserErrorDialog.ShowUserErrorDialog(UserError.NoKeys, this));
  349. }
  350. if (_deferLoad)
  351. {
  352. _deferLoad = false;
  353. LoadApplication(_launchPath, _startFullscreen);
  354. }
  355. if (ConfigurationState.Instance.CheckUpdatesOnStart.Value && Updater.CanUpdate(false, this))
  356. {
  357. Updater.BeginParse(this, false).ContinueWith(task =>
  358. {
  359. Logger.Error?.Print(LogClass.Application, $"Updater Error: {task.Exception}");
  360. }, TaskContinuationOptions.OnlyOnFaulted);
  361. }
  362. }
  363. public void RefreshFirmwareStatus()
  364. {
  365. SystemVersion version = null;
  366. try
  367. {
  368. version = ContentManager.GetCurrentFirmwareVersion();
  369. }
  370. catch (Exception) { }
  371. bool hasApplet = false;
  372. if (version != null)
  373. {
  374. LocaleManager.Instance.UpdateDynamicValue("StatusBarSystemVersion",
  375. version.VersionString);
  376. hasApplet = version.Major > 3;
  377. }
  378. else
  379. {
  380. LocaleManager.Instance.UpdateDynamicValue("StatusBarSystemVersion", "0.0");
  381. }
  382. ViewModel.IsAppletMenuActive = hasApplet;
  383. }
  384. private void Load()
  385. {
  386. VolumeStatus.Click += VolumeStatus_CheckedChanged;
  387. GameGrid.ApplicationOpened += Application_Opened;
  388. GameGrid.DataContext = ViewModel;
  389. GameList.ApplicationOpened += Application_Opened;
  390. GameList.DataContext = ViewModel;
  391. LoadHotKeys();
  392. }
  393. protected override void OnOpened(EventArgs e)
  394. {
  395. base.OnOpened(e);
  396. CheckLaunchState();
  397. }
  398. public static void UpdateGraphicsConfig()
  399. {
  400. int resScale = ConfigurationState.Instance.Graphics.ResScale;
  401. float resScaleCustom = ConfigurationState.Instance.Graphics.ResScaleCustom;
  402. GraphicsConfig.ResScale = resScale == -1 ? resScaleCustom : resScale;
  403. GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
  404. GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  405. GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;
  406. GraphicsConfig.EnableTextureRecompression = ConfigurationState.Instance.Graphics.EnableTextureRecompression;
  407. }
  408. public void LoadHotKeys()
  409. {
  410. HotKeyManager.SetHotKey(FullscreenHotKey, new KeyGesture(Key.Enter, KeyModifiers.Alt));
  411. HotKeyManager.SetHotKey(FullscreenHotKey2, new KeyGesture(Key.F11));
  412. HotKeyManager.SetHotKey(DockToggleHotKey, new KeyGesture(Key.F9));
  413. HotKeyManager.SetHotKey(ExitHotKey, new KeyGesture(Key.Escape));
  414. }
  415. public static void SaveConfig()
  416. {
  417. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  418. }
  419. public void UpdateGameMetadata(string titleId)
  420. {
  421. ApplicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  422. {
  423. DateTime lastPlayedDateTime = DateTime.Parse(appMetadata.LastPlayed);
  424. double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
  425. appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
  426. });
  427. }
  428. private void PrepareLoadScreen()
  429. {
  430. using MemoryStream stream = new MemoryStream(ViewModel.SelectedIcon);
  431. using var gameIconBmp = SixLabors.ImageSharp.Image.Load<Bgra32>(stream);
  432. var dominantColor = IconColorPicker.GetFilteredColor(gameIconBmp).ToPixel<Bgra32>();
  433. const int ColorDivisor = 4;
  434. Color progressFgColor = Color.FromRgb(dominantColor.R, dominantColor.G, dominantColor.B);
  435. Color progressBgColor = Color.FromRgb(
  436. (byte)(dominantColor.R / ColorDivisor),
  437. (byte)(dominantColor.G / ColorDivisor),
  438. (byte)(dominantColor.B / ColorDivisor));
  439. ViewModel.ProgressBarForegroundColor = new SolidColorBrush(progressFgColor);
  440. ViewModel.ProgressBarBackgroundColor = new SolidColorBrush(progressBgColor);
  441. }
  442. private void SearchBox_OnKeyUp(object sender, KeyEventArgs e)
  443. {
  444. ViewModel.SearchText = SearchBox.Text;
  445. }
  446. private async void StopEmulation_Click(object sender, RoutedEventArgs e)
  447. {
  448. if (AppHost != null)
  449. {
  450. await AppHost.ShowExitPrompt();
  451. }
  452. }
  453. private async void PauseEmulation_Click(object sender, RoutedEventArgs e)
  454. {
  455. await Task.Run(() =>
  456. {
  457. AppHost?.Pause();
  458. });
  459. }
  460. private async void ResumeEmulation_Click(object sender, RoutedEventArgs e)
  461. {
  462. await Task.Run(() =>
  463. {
  464. AppHost?.Resume();
  465. });
  466. }
  467. private void ScanAmiiboMenuItem_AttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e)
  468. {
  469. if (sender is MenuItem)
  470. {
  471. ViewModel.IsAmiiboRequested = AppHost.Device.System.SearchingForAmiibo(out _);
  472. }
  473. }
  474. private void VsyncStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
  475. {
  476. AppHost.Device.EnableDeviceVsync = !AppHost.Device.EnableDeviceVsync;
  477. Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {AppHost.Device.EnableDeviceVsync}");
  478. }
  479. private void DockedStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
  480. {
  481. ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value;
  482. }
  483. private void AspectRatioStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
  484. {
  485. AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value;
  486. ConfigurationState.Instance.Graphics.AspectRatio.Value = (int)aspectRatio + 1 > Enum.GetNames(typeof(AspectRatio)).Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1;
  487. }
  488. private void VolumeStatus_CheckedChanged(object sender, SplitButtonClickEventArgs e)
  489. {
  490. var volumeSplitButton = sender as ToggleSplitButton;
  491. if (ViewModel.IsGameRunning)
  492. {
  493. if (!volumeSplitButton.IsChecked)
  494. {
  495. AppHost.Device.SetVolume(ConfigurationState.Instance.System.AudioVolume);
  496. }
  497. else
  498. {
  499. AppHost.Device.SetVolume(0);
  500. }
  501. ViewModel.Volume = AppHost.Device.GetVolume();
  502. }
  503. }
  504. protected override void OnClosing(CancelEventArgs e)
  505. {
  506. if (!_isClosing && AppHost != null && ConfigurationState.Instance.ShowConfirmExit)
  507. {
  508. e.Cancel = true;
  509. ConfirmExit();
  510. return;
  511. }
  512. _isClosing = true;
  513. if (AppHost != null)
  514. {
  515. AppHost.AppExit -= AppHost_AppExit;
  516. AppHost.AppExit += (sender, e) =>
  517. {
  518. AppHost = null;
  519. Dispatcher.UIThread.Post(() =>
  520. {
  521. MainContent = null;
  522. Close();
  523. });
  524. };
  525. AppHost?.Stop();
  526. e.Cancel = true;
  527. return;
  528. }
  529. ApplicationLibrary.CancelLoading();
  530. InputManager.Dispose();
  531. Program.Exit();
  532. base.OnClosing(e);
  533. }
  534. private void ConfirmExit()
  535. {
  536. Dispatcher.UIThread.InvokeAsync(async () =>
  537. {
  538. _isClosing = await ContentDialogHelper.CreateExitDialog();
  539. if (_isClosing)
  540. {
  541. Close();
  542. }
  543. });
  544. }
  545. }
  546. }