-
Notifications
You must be signed in to change notification settings - Fork 7.9k
CmdPal: Add slideshow background mode and rotation settings #46452
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
Open
Error0229
wants to merge
8
commits into
microsoft:main
Choose a base branch
from
Error0229:feature/cmdpal-background-slideshow-45879
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2519bda
CmdPal: Add slideshow background mode and rotation settings (#45879)
catol-abacus 515c0bc
refactor: remove unnecessary StackPanel wrappers in appearance settings
catol-abacus 10dfd24
refactor: extract URI creation into BackgroundImagePathResolver.Creat…
catol-abacus 1d6734e
chore: add 'slideshow' to spell-check expect list
catol-abacus 6982536
Merge upstream/main: resolve Resources.resw conflict with PinToDock s…
catol-abacus 76b64dc
fix: guard TryGetLocalFolderPath against malformed paths, make Suppor…
catol-abacus 71dde9e
Merge upstream/main: resolve SettingsModel.cs conflict (BackdropStyle…
catol-abacus 5f1ff3c
fix: replace removed Save() calls with _saveTimer.Debounce
catol-abacus 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
154 changes: 154 additions & 0 deletions
154
src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/BackgroundImagePathResolver.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,154 @@ | ||
| // 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.Collections.Frozen; | ||
|
|
||
| namespace Microsoft.CmdPal.UI.ViewModels; | ||
|
|
||
| /// <summary> | ||
| /// Resolves configured background image paths that can target either a single image file or a folder. | ||
| /// </summary> | ||
| public static class BackgroundImagePathResolver | ||
| { | ||
| public static readonly FrozenSet<string> SupportedImageExtensions = FrozenSet.ToFrozenSet( | ||
| new[] | ||
| { | ||
| ".png", | ||
| ".bmp", | ||
| ".jpg", | ||
| ".jpeg", | ||
| ".jfif", | ||
| ".gif", | ||
| ".tiff", | ||
| ".tif", | ||
| ".webp", | ||
| ".jxr", | ||
| }, | ||
| StringComparer.OrdinalIgnoreCase); | ||
|
|
||
| /// <summary> | ||
| /// Returns true when <paramref name="configuredPath"/> points to an existing local directory. | ||
| /// </summary> | ||
| public static bool TryGetLocalFolderPath(string? configuredPath, out string folderPath) | ||
| { | ||
| folderPath = string.Empty; | ||
| if (string.IsNullOrWhiteSpace(configuredPath)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| var candidate = configuredPath.Trim(); | ||
|
|
||
| if (Uri.TryCreate(candidate, UriKind.Absolute, out var absoluteUri)) | ||
| { | ||
| if (!absoluteUri.IsFile) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| var localPath = absoluteUri.LocalPath; | ||
| if (!Directory.Exists(localPath)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| folderPath = localPath; | ||
| return true; | ||
| } | ||
|
|
||
| if (!Uri.TryCreate(candidate, UriKind.RelativeOrAbsolute, out var uri) || uri.IsAbsoluteUri) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| var localCandidate = Path.GetFullPath(candidate); | ||
| if (!Directory.Exists(localCandidate)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| folderPath = localCandidate; | ||
| return true; | ||
| } | ||
| catch (Exception ex) when (ex is ArgumentException or NotSupportedException) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets sorted image files from <paramref name="folderPath"/> supported by the background pipeline. | ||
| /// </summary> | ||
| public static IReadOnlyList<string> GetSupportedImageFiles(string folderPath) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(folderPath) || !Directory.Exists(folderPath)) | ||
| { | ||
| return []; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| return Directory | ||
| .EnumerateFiles(folderPath, "*", SearchOption.TopDirectoryOnly) | ||
| .Where(IsSupportedImageFile) | ||
| .OrderBy(path => path, StringComparer.OrdinalIgnoreCase) | ||
| .ToArray(); | ||
| } | ||
| catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) | ||
| { | ||
| return []; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Resolves a stable preview path for settings UI. For folders, this returns the first supported image. | ||
| /// </summary> | ||
| public static string? ResolvePreviewImagePath(string? configuredPath) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(configuredPath)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| if (!TryGetLocalFolderPath(configuredPath, out var folderPath)) | ||
| { | ||
| return configuredPath.Trim(); | ||
| } | ||
|
|
||
| var files = GetSupportedImageFiles(folderPath); | ||
| return files.Count > 0 ? files[0] : null; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a <see cref="Uri"/> suitable for <see cref="Microsoft.UI.Xaml.Media.Imaging.BitmapImage"/> | ||
| /// from a resolved image path. Returns null when the path is empty or invalid. | ||
| /// </summary> | ||
| public static Uri? CreateImageUri(string? imagePath) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(imagePath)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| if (!Uri.TryCreate(imagePath, UriKind.RelativeOrAbsolute, out var uri)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| if (!uri.IsAbsoluteUri && File.Exists(imagePath)) | ||
| { | ||
| return new Uri(Path.GetFullPath(imagePath)); | ||
| } | ||
|
|
||
| return uri; | ||
| } | ||
|
|
||
| private static bool IsSupportedImageFile(string filePath) | ||
| { | ||
| var extension = Path.GetExtension(filePath); | ||
| return SupportedImageExtensions.Contains(extension); | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -10,4 +10,5 @@ public enum ColorizationMode | |
| WindowsAccentColor, | ||
| CustomColor, | ||
| Image, | ||
| Slideshow, | ||
| } | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.