MainWindow.axaml.cs 23 KB

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