KEMBAR78
Clean up the windows code a bit by mattleibow · Pull Request #6501 · dotnet/maui · GitHub
Skip to content

Conversation

@mattleibow
Copy link
Member

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.

@mattleibow mattleibow added this to the 6.0.300-rc.3 milestone Apr 26, 2022
@mattleibow mattleibow requested a review from PureWeen April 26, 2022 08:23
@mattleibow mattleibow self-assigned this Apr 26, 2022
Comment on lines 56 to 62
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));
Copy link
Member Author

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.

Copy link
Member Author

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

Comment on lines -25 to +29
InitializeComponent();
IsSettingsVisible = false;
IsPaneToggleButtonVisible = false;
PaneDisplayMode = NavigationViewPaneDisplayMode.LeftMinimal;
IsTitleBarAutoPaddingEnabled = false;
IsBackButtonVisible = NavigationViewBackButtonVisible.Collapsed;
Copy link
Member Author

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.

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this chance made our Controls.DeviceTests grumpy

image

@Eilon Eilon added the area-core-hosting Extensions / Hosting / AppBuilder / Startup label Apr 28, 2022
Comment on lines +73 to +74
appBuilder.Services.AddSingleton<IDispatcherProvider>(svc => TestDispatcher.Provider);
appBuilder.Services.AddScoped<IDispatcher>(svc => TestDispatcher.Current);
Copy link
Member Author

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.

Comment on lines +55 to +61
// 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();
Copy link
Member Author

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

@mattleibow mattleibow dismissed PureWeen’s stale review April 29, 2022 19:33

Thanks for reminding me to run the Windows tests! Caught some nasty bois.

@mattleibow mattleibow requested a review from PureWeen April 29, 2022 19:33
@mattleibow mattleibow merged commit 5e4dfa3 into main May 2, 2022
@mattleibow mattleibow deleted the dev/startup-tweaks branch May 2, 2022 16:50
@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
@samhouts samhouts added the fixed-in-6.0.300-rc.3 Look for this fix in 6.0.300-rc.3! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-core-hosting Extensions / Hosting / AppBuilder / Startup fixed-in-6.0.300-rc.3 Look for this fix in 6.0.300-rc.3! platform/windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants