-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Clean up the windows code a bit #6501
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
Conversation
| var dispatcher = | ||
| services.GetService<IDispatcher>() ?? | ||
| MauiWinUIApplication.Current.Services.GetRequiredService<IDispatcher>(); | ||
| if (UI.Xaml.Application.Current?.Resources is not UI.Xaml.ResourceDictionary resources) | ||
| return; | ||
|
|
||
| if (!dispatcher.IsDispatchRequired) | ||
| SetupResources(); | ||
| if (resources.DispatcherQueue.HasThreadAccess) | ||
| SetupResources(resources); | ||
| else | ||
| dispatcher.Dispatch(SetupResources); | ||
| resources.DispatcherQueue.TryEnqueue(() => SetupResources(resources)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using super complicated dispatcher logic, use the literally free dispatcher on the very dictionary we are adding to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crashes in the very case it was designed to work in: https://github.com/microsoft/WindowsAppSDK/issues/2451
| InitializeComponent(); | ||
| IsSettingsVisible = false; | ||
| IsPaneToggleButtonVisible = false; | ||
| PaneDisplayMode = NavigationViewPaneDisplayMode.LeftMinimal; | ||
| IsTitleBarAutoPaddingEnabled = false; | ||
| IsBackButtonVisible = NavigationViewBackButtonVisible.Collapsed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set the xaml values in C# to avoid errors so ambiguous that you feel like a -10x engineer. If there is any error at any point in the code or types inside this constructor, the whole operation fails with "Xaml Parser Failed" and no way of knowing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| appBuilder.Services.AddSingleton<IDispatcherProvider>(svc => TestDispatcher.Provider); | ||
| appBuilder.Services.AddScoped<IDispatcher>(svc => TestDispatcher.Current); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the test dispatchers to the services for the tests.
| // WORKAROUND: use the MAUI dispatcher instead of the OS dispatcher to | ||
| // avoid crashing: https://github.com/microsoft/WindowsAppSDK/issues/2451 | ||
| var dispatcher = services.GetRequiredService<IDispatcher>(); | ||
| if (dispatcher.IsDispatchRequired) | ||
| dispatcher.Dispatch(() => SetupResources()); | ||
| else | ||
| dispatcher.Dispatch(SetupResources); | ||
| SetupResources(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An attempt to just avoid all issues and use the OS dispatcher assigned to the resource dictionary failed because of: https://github.com/microsoft/WindowsAppSDK/issues/2451
Thanks for reminding me to run the Windows tests! Caught some nasty bois.

Description of Change
There appears to have been some duplicate xaml files and also removed a xaml file because if there is any error in any part of that, the compilation fails with the most ambiguous error: "Xaml Parser Failed" which is a total lie because it DID parse just fine, that is why the error happens in the now-inflated view...
Issues Fixed
Fixes my happiness levels.