|
5 | 5 | using Files.Shared.Helpers;
|
6 | 6 | using LibGit2Sharp;
|
7 | 7 | using Microsoft.Extensions.Logging;
|
| 8 | +using Microsoft.UI.Xaml; |
8 | 9 | using Microsoft.UI.Xaml.Data;
|
9 | 10 | using Microsoft.UI.Xaml.Media;
|
10 | 11 | using Microsoft.UI.Xaml.Media.Imaging;
|
@@ -73,6 +74,41 @@ public string? SolutionFilePath
|
73 | 74 | private set => SetProperty(ref _SolutionFilePath, value);
|
74 | 75 | }
|
75 | 76 |
|
| 77 | + private ImageSource? _FolderBackgroundImageSource; |
| 78 | + public ImageSource? FolderBackgroundImageSource |
| 79 | + { |
| 80 | + get => _FolderBackgroundImageSource; |
| 81 | + private set => SetProperty(ref _FolderBackgroundImageSource, value); |
| 82 | + } |
| 83 | + |
| 84 | + private float _FolderBackgroundImageOpacity = 1f; |
| 85 | + public float FolderBackgroundImageOpacity |
| 86 | + { |
| 87 | + get => _FolderBackgroundImageOpacity; |
| 88 | + private set => SetProperty(ref _FolderBackgroundImageOpacity, value); |
| 89 | + } |
| 90 | + |
| 91 | + private Stretch _FolderBackgroundImageFit = Stretch.UniformToFill; |
| 92 | + public Stretch FolderBackgroundImageFit |
| 93 | + { |
| 94 | + get => _FolderBackgroundImageFit; |
| 95 | + private set => SetProperty(ref _FolderBackgroundImageFit, value); |
| 96 | + } |
| 97 | + |
| 98 | + private VerticalAlignment _FolderBackgroundImageVerticalAlignment = VerticalAlignment.Center; |
| 99 | + public VerticalAlignment FolderBackgroundImageVerticalAlignment |
| 100 | + { |
| 101 | + get => _FolderBackgroundImageVerticalAlignment; |
| 102 | + private set => SetProperty(ref _FolderBackgroundImageVerticalAlignment, value); |
| 103 | + } |
| 104 | + |
| 105 | + private HorizontalAlignment _FolderBackgroundImageHorizontalAlignment = HorizontalAlignment.Center; |
| 106 | + public HorizontalAlignment FolderBackgroundImageHorizontalAlignment |
| 107 | + { |
| 108 | + get => _FolderBackgroundImageHorizontalAlignment; |
| 109 | + private set => SetProperty(ref _FolderBackgroundImageHorizontalAlignment, value); |
| 110 | + } |
| 111 | + |
76 | 112 | private GitProperties _EnabledGitProperties;
|
77 | 113 | public GitProperties EnabledGitProperties
|
78 | 114 | {
|
@@ -495,11 +531,17 @@ public ShellViewModel(LayoutPreferencesManager folderSettingsViewModel)
|
495 | 531 | fileTagsSettingsService.OnSettingImportedEvent += FileTagsSettingsService_OnSettingUpdated;
|
496 | 532 | fileTagsSettingsService.OnTagsUpdated += FileTagsSettingsService_OnSettingUpdated;
|
497 | 533 | folderSizeProvider.SizeChanged += FolderSizeProvider_SizeChanged;
|
| 534 | + folderSettings.LayoutModeChangeRequested += LayoutModeChangeRequested; |
498 | 535 | RecycleBinManager.Default.RecycleBinItemCreated += RecycleBinItemCreatedAsync;
|
499 | 536 | RecycleBinManager.Default.RecycleBinItemDeleted += RecycleBinItemDeletedAsync;
|
500 | 537 | RecycleBinManager.Default.RecycleBinRefreshRequested += RecycleBinRefreshRequestedAsync;
|
501 | 538 | }
|
502 | 539 |
|
| 540 | + private async void LayoutModeChangeRequested(object? sender, LayoutModeEventArgs e) |
| 541 | + { |
| 542 | + await dispatcherQueue.EnqueueOrInvokeAsync(CheckForBackgroundImage, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low); |
| 543 | + } |
| 544 | + |
503 | 545 | private async void RecycleBinRefreshRequestedAsync(object sender, FileSystemEventArgs e)
|
504 | 546 | {
|
505 | 547 | if (!Constants.UserEnvironmentPaths.RecycleBinPath.Equals(CurrentFolder?.ItemPath, StringComparison.OrdinalIgnoreCase))
|
@@ -542,7 +584,7 @@ private async void RecycleBinItemCreatedAsync(object sender, FileSystemEventArgs
|
542 | 584 | await ApplyFilesAndFoldersChangesAsync();
|
543 | 585 | }
|
544 | 586 |
|
545 |
| - private async void FolderSizeProvider_SizeChanged(object? sender, SizeChangedEventArgs e) |
| 587 | + private async void FolderSizeProvider_SizeChanged(object? sender, Services.SizeProvider.SizeChangedEventArgs e) |
546 | 588 | {
|
547 | 589 | try
|
548 | 590 | {
|
@@ -1003,7 +1045,8 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
|
1003 | 1045 | if (loadNonCachedThumbnail)
|
1004 | 1046 | {
|
1005 | 1047 | // Get non-cached thumbnail asynchronously
|
1006 |
| - _ = Task.Run(async () => { |
| 1048 | + _ = Task.Run(async () => |
| 1049 | + { |
1007 | 1050 | await loadThumbnailSemaphore.WaitAsync(cancellationToken);
|
1008 | 1051 | try
|
1009 | 1052 | {
|
@@ -1186,7 +1229,8 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
|
1186 | 1229 | // Try loading thumbnail for cloud files in case they weren't cached the first time
|
1187 | 1230 | if (item.SyncStatusUI.SyncStatus != CloudDriveSyncStatus.NotSynced && item.SyncStatusUI.SyncStatus != CloudDriveSyncStatus.Unknown)
|
1188 | 1231 | {
|
1189 |
| - _ = Task.Run(async () => { |
| 1232 | + _ = Task.Run(async () => |
| 1233 | + { |
1190 | 1234 | await Task.Delay(500);
|
1191 | 1235 | cts.Token.ThrowIfCancellationRequested();
|
1192 | 1236 | await LoadThumbnailAsync(item, cts.Token);
|
@@ -1691,6 +1735,7 @@ await Task.Run(async () =>
|
1691 | 1735 | await OrderFilesAndFoldersAsync();
|
1692 | 1736 | await ApplyFilesAndFoldersChangesAsync();
|
1693 | 1737 | await dispatcherQueue.EnqueueOrInvokeAsync(CheckForSolutionFile, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
|
| 1738 | + await dispatcherQueue.EnqueueOrInvokeAsync(CheckForBackgroundImage, Microsoft.UI.Dispatching.DispatcherQueuePriority.Low); |
1694 | 1739 | });
|
1695 | 1740 |
|
1696 | 1741 | rootFolder ??= await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path));
|
@@ -1751,6 +1796,56 @@ private void CheckForSolutionFile()
|
1751 | 1796 | .FirstOrDefault()?.ItemPath;
|
1752 | 1797 | }
|
1753 | 1798 |
|
| 1799 | + public void CheckForBackgroundImage() |
| 1800 | + { |
| 1801 | + var iniPath = Path.Combine(WorkingDirectory, "desktop.ini"); |
| 1802 | + if (!File.Exists(iniPath)) |
| 1803 | + return; |
| 1804 | + |
| 1805 | + // Read data |
| 1806 | + var lines = File.ReadLines(iniPath); |
| 1807 | + var keys = lines.Select(line => line.Split('=')) |
| 1808 | + .Where(parts => parts.Length == 2) |
| 1809 | + .ToDictionary(parts => parts[0].Trim(), parts => parts[1].Trim()); |
| 1810 | + |
| 1811 | + // Image source |
| 1812 | + if (folderSettings.LayoutMode is not FolderLayoutModes.ColumnView && keys.TryGetValue("Files_BackgroundImage", out var backgroundImage)) |
| 1813 | + FolderBackgroundImageSource = new BitmapImage |
| 1814 | + { |
| 1815 | + UriSource = new Uri(backgroundImage, UriKind.RelativeOrAbsolute), |
| 1816 | + CreateOptions = BitmapCreateOptions.IgnoreImageCache |
| 1817 | + }; |
| 1818 | + else |
| 1819 | + { |
| 1820 | + FolderBackgroundImageSource = null; |
| 1821 | + return; |
| 1822 | + } |
| 1823 | + |
| 1824 | + // Opacity |
| 1825 | + if (keys.TryGetValue("Files_BackgroundOpacity", out var backgroundOpacity) && float.TryParse(backgroundOpacity, out var opacity)) |
| 1826 | + FolderBackgroundImageOpacity = opacity; |
| 1827 | + else |
| 1828 | + FolderBackgroundImageOpacity = 1f; |
| 1829 | + |
| 1830 | + // Stretch |
| 1831 | + if (keys.TryGetValue("Files_BackgroundFit", out var backgroundFit) && Enum.TryParse<Stretch>(backgroundFit, out var fit)) |
| 1832 | + FolderBackgroundImageFit = fit; |
| 1833 | + else |
| 1834 | + FolderBackgroundImageFit = Stretch.UniformToFill; |
| 1835 | + |
| 1836 | + // VerticalAlignment |
| 1837 | + if (keys.TryGetValue("Files_BackgroundVerticalAlignment", out var verticalAlignment) && Enum.TryParse<VerticalAlignment>(verticalAlignment, out var vAlignment)) |
| 1838 | + FolderBackgroundImageVerticalAlignment = vAlignment; |
| 1839 | + else |
| 1840 | + FolderBackgroundImageVerticalAlignment = VerticalAlignment.Center; |
| 1841 | + |
| 1842 | + // HorizontalAlignment |
| 1843 | + if (keys.TryGetValue("Files_BackgroundHorizontalAlignment", out var horizontalAlignment) && Enum.TryParse<HorizontalAlignment>(horizontalAlignment, out var hAlignment)) |
| 1844 | + FolderBackgroundImageHorizontalAlignment = hAlignment; |
| 1845 | + else |
| 1846 | + FolderBackgroundImageHorizontalAlignment = HorizontalAlignment.Center; |
| 1847 | + } |
| 1848 | + |
1754 | 1849 | public async Task<CloudDriveSyncStatus> CheckCloudDriveSyncStatusAsync(IStorageItem item)
|
1755 | 1850 | {
|
1756 | 1851 | int? syncStatus = null;
|
@@ -2471,6 +2566,7 @@ public void Dispose()
|
2471 | 2566 | fileTagsSettingsService.OnSettingImportedEvent -= FileTagsSettingsService_OnSettingUpdated;
|
2472 | 2567 | fileTagsSettingsService.OnTagsUpdated -= FileTagsSettingsService_OnSettingUpdated;
|
2473 | 2568 | folderSizeProvider.SizeChanged -= FolderSizeProvider_SizeChanged;
|
| 2569 | + folderSettings.LayoutModeChangeRequested -= LayoutModeChangeRequested; |
2474 | 2570 | }
|
2475 | 2571 | }
|
2476 | 2572 |
|
|
0 commit comments