-
Notifications
You must be signed in to change notification settings - Fork 500
Enforce Snackbar usage only in packaged Windows apps #3276
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
55a148b
Enforce Snackbar usage only in packaged Windows apps
ne0rrmatrix e2e7ed2
Apply suggestions from code review
ne0rrmatrix 5e18ce0
Refactor IsPackagedApp() to use reflection on Windows
ne0rrmatrix 190c0da
Simplify IsPackagedApp method implementation
ne0rrmatrix dd98d3f
Simplify IsPackagedApp method implementation
ne0rrmatrix 2332c44
Merge branch 'main' into FixComException
ne0rrmatrix fb57990
Merge branch 'main' into FixComException
ne0rrmatrix 007333b
Add back the try catch. We are doing this so that we control the thro…
ne0rrmatrix 95c0604
Refactor Snackbar initialization error handling for unpackaged Window…
ne0rrmatrix 0bbe0bd
Switch to using our own AppPackagExtension method. I copied it from M…
ne0rrmatrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/CommunityToolkit.Maui/Extensions/AppPackageExtensions.windows.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using Windows.ApplicationModel; | ||
|
|
||
| namespace CommunityToolkit.Maui.Extensions; | ||
|
|
||
| // Since MediaElement can't access .NET MAUI internals we have to copy this code here | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please update comment since it is not only for Media Element |
||
| // https://github.com/dotnet/maui/blob/main/src/Essentials/src/AppInfo/AppInfo.uwp.cs | ||
| static class AppPackageExtensions | ||
| { | ||
| static readonly Lazy<bool> isPackagedAppHolder = new(() => | ||
| { | ||
| try | ||
| { | ||
| if (Package.Current is not null) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| // no-op | ||
| } | ||
|
|
||
| return false; | ||
| }); | ||
|
|
||
| static readonly Lazy<string> fullAppPackageFilePathHolder = new(() => | ||
| { | ||
| return IsPackagedApp | ||
| ? Package.Current.InstalledLocation.Path | ||
| : AppContext.BaseDirectory; | ||
| }); | ||
|
|
||
| /// <summary> | ||
| /// Gets if this app is a packaged app. | ||
| /// </summary> | ||
| public static bool IsPackagedApp => isPackagedAppHolder.Value; | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Gets full application path. | ||
| /// </summary> | ||
| public static string FullAppPackageFilePath => fullAppPackageFilePathHolder.Value; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this necessary?
We keep
Microsoft.Maui.Controlsversion as*to ensure the sample app always uses the most recent MuGet release. This allows us to run + test the sample app on the latest version to avoid breaking changes in our library which runs on an older version ofMicrosoft.Maui.Controls.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.
The wildcard * caused the sample app to resolve Microsoft.Maui.Controls to the latest NuGet version (10.0.90), while every other MAUI package in the repo — including Microsoft.Maui.Controls.Maps, Microsoft.Maui.Core, and the MAUI assemblies pulled in transitively by the CommunityToolkit.Maui.* project references — was pinned to 10.0.60 via $(MauiPackageVersion).
This version mismatch broke the Windows build because both MAUI 10.0.60 and 10.0.90 ship the same framework resource file (Files/Microsoft.Maui/Platform/Windows/Styles/Resources.xbf) but with different content. When the Windows App SDK PRI generator merged resources from both versions, it found the same path with conflicting values, producing:
By pinning the sample to $(MauiPackageVersion) (10.0.60), all MAUI packages resolve to the same version, eliminating the duplicate resource conflict.