-
Notifications
You must be signed in to change notification settings - Fork 8.1k
[Peek] Stop fail-fast in AppWindow.Closing path; reset cached preview-handler factories on release #48564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Peek] Stop fail-fast in AppWindow.Closing path; reset cached preview-handler factories on release #48564
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,11 +213,29 @@ | |
|
|
||
| public static void ReleaseHandlerFactories() | ||
| { | ||
| foreach (var factory in HandlerFactories.Values) | ||
| // Snapshot and clear the dictionary up front so that a subsequent call | ||
| // or a concurrent LoadPreviewAsync can't pick up a stale RCW we are | ||
Check failureCode scanning / check-spelling Unrecognized Spelling Error
RCW is not a recognized word
|
||
| // about to release. This also makes the method idempotent: a second | ||
| // call won't try to FinalRelease the same already-separated RCWs. | ||
Check failureCode scanning / check-spelling Unrecognized Spelling Error
RCWs is not a recognized word
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| var factories = HandlerFactories.ToArray(); | ||
| HandlerFactories.Clear(); | ||
|
|
||
| foreach (var kvp in factories) | ||
| { | ||
| // Mirror the LockServer(true) we did when caching, so the local | ||
| // server can shut down cleanly. Both calls are wrapped because the | ||
| // RCW may already be unreachable during process teardown. | ||
Check failureCode scanning / check-spelling Unrecognized Spelling Error
RCW is not a recognized word
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| try | ||
| { | ||
| Marshal.FinalReleaseComObject(factory); | ||
| kvp.Value.LockServer(false); | ||
| } | ||
| catch | ||
| { | ||
| } | ||
|
|
||
| try | ||
| { | ||
| Marshal.FinalReleaseComObject(kvp.Value); | ||
| } | ||
| catch | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,9 +290,22 @@ | |
| /// <param name="args">AppWindowClosingEventArgs</param> | ||
| private void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args) | ||
| { | ||
| args.Cancel = true; | ||
| PowerToysTelemetry.Log.WriteEvent(new ClosedEvent()); | ||
| Uninitialize(); | ||
| // 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. We want a Closing handler that can never crash Peek, even if | ||
| // a callee (e.g., a cached preview-handler RCW that has been separated | ||
Check failureCode scanning / check-spelling Unrecognized Spelling Error
RCW is not a recognized word
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| // during teardown) throws InvalidComObjectException. | ||
| try | ||
| { | ||
| args.Cancel = true; | ||
| PowerToysTelemetry.Log.WriteEvent(new ClosedEvent()); | ||
| Uninitialize(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Logger.LogError("Unhandled exception in Peek MainWindow.AppWindow_Closing; suppressing to avoid fail-fast.", ex); | ||
| args.Cancel = true; | ||
| } | ||
| } | ||
|
|
||
| private bool IsNewSingleSelectedItem(SelectedItem selectedItem) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| // 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; | ||
|
|
@@ -15,10 +17,27 @@ | |
| /// </summary> | ||
| private void AppWindow_Closing(Microsoft.UI.Windowing.AppWindow sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs args) | ||
| { | ||
| 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)); | ||
| // 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 | ||
Check failureCode scanning / check-spelling Unrecognized Spelling Error
RCW is not a recognized word
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| // 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> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.