/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/registrypreview/RegistryPreview/MainWindow.Events.cs
53 строки
2 KB
Clint Rutkas
[Peek] Stop fail-fast in AppWindow.Closing path; reset cached preview-handler factories on release (#48564)
23 июн 2026, 16:32
Не верифицирован
23 июн 2026, 16:32
968a7ac
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using Microsoft.UI.Xaml; using Windows.Data.Json; using WinUIEx; namespace RegistryPreview { public sealed partial class MainWindow : WindowEx { /// <summary> /// Event handler to grab the main window's size and position before it closes /// </summary> private void AppWindow_Closing(Microsoft.UI.Windowing.AppWindow sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs args) { // Any exception that escapes a WinRT event handler is projected back to // the CsWinRT dispatcher as a failed HRESULT, and CFlat fail-fasts the // process. Defend the handler so a transient teardown failure (e.g., // null placement state, separated RCW during shutdown) can't terminate // the editor unexpectedly. try { if (jsonWindowPlacement == null) { return; } jsonWindowPlacement.SetNamedValue("appWindow.Position.X", JsonValue.CreateNumberValue(AppWindow.Position.X)); jsonWindowPlacement.SetNamedValue("appWindow.Position.Y", JsonValue.CreateNumberValue(AppWindow.Position.Y)); jsonWindowPlacement.SetNamedValue("appWindow.Size.Width", JsonValue.CreateNumberValue(AppWindow.Size.Width)); jsonWindowPlacement.SetNamedValue("appWindow.Size.Height", JsonValue.CreateNumberValue(AppWindow.Size.Height)); } catch (Exception ex) { ManagedCommon.Logger.LogError("Unhandled exception in RegistryPreview MainWindow.AppWindow_Closing; suppressing to avoid fail-fast.", ex); } } /// <summary> /// Event that is will prevent the app from closing if the "save file" flag is active /// </summary> public void Window_Closed(object sender, WindowEventArgs args) { // Save window placement SaveWindowPlacementFile(settingsFolder, windowPlacementFile); (Application.Current as App).EtwTrace?.Dispose(); } } }