MainWindow.axaml.cs 23 KB

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