Skip to content

Commit

Permalink
Update exif loading and fix taskbar progress display not updating
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Oct 30, 2024
1 parent 81f31ae commit bc409bc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/PicView.Avalonia/Navigation/ExifHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace PicView.Avalonia.Navigation;

public static class ExifHandling
{
public static void UpdateExifValues(ImageModel imageModel, MainViewModel vm)
public static void UpdateExifValues(MainViewModel vm)
{
if (vm.FileInfo is null || vm is { PixelWidth: <= 0, PixelHeight: <= 0 })
{
Expand Down Expand Up @@ -45,16 +45,16 @@ public static void UpdateExifValues(ImageModel imageModel, MainViewModel vm)
}
}

if (vm.DpiX is 0 && imageModel.ImageType is ImageType.Bitmap or ImageType.AnimatedGif or ImageType.AnimatedWebp)
if (vm.DpiX is 0 && vm.ImageType is ImageType.Bitmap or ImageType.AnimatedGif or ImageType.AnimatedWebp)
{
if (imageModel.Image is Bitmap bmp)
if (vm.ImageSource is Bitmap bmp)
{
vm.DpiX = bmp?.Dpi.X ?? 0;
vm.DpiY = bmp?.Dpi.Y ?? 0;
}
}

vm.GetOrientation = imageModel.EXIFOrientation switch
vm.GetOrientation = vm.ExifOrientation switch
{
EXIFHelper.EXIFOrientation.Horizontal => TranslationHelper.Translation.Normal,
EXIFHelper.EXIFOrientation.MirrorHorizontal => TranslationHelper.Translation.Flipped,
Expand Down
3 changes: 1 addition & 2 deletions src/PicView.Avalonia/Navigation/NavigationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public static async Task LoadPicFromUrlAsync(string url, MainViewModel vm)
var imageModel = await GetImageModel.GetImageModelAsync(fileInfo).ConfigureAwait(false);
UpdateImage.SetSingleImage(imageModel.Image, imageModel.ImageType, url, vm);
vm.FileInfo = fileInfo;
ExifHandling.UpdateExifValues(imageModel, vm);
vm.ExifOrientation = imageModel.EXIFOrientation;
FileHistoryNavigation.Add(url);

vm.IsLoading = false;
Expand Down Expand Up @@ -434,7 +434,6 @@ await Task.Run(async () =>
ImageType = ImageType.Bitmap
};
UpdateImage.SetSingleImage(imageModel.Image, imageModel.ImageType, TranslationHelper.Translation.Base64Image, vm);
ExifHandling.UpdateExifValues(imageModel, vm);
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PicView.Avalonia/Navigation/UpdateImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ await Dispatcher.UIThread.InvokeAsync(() =>
}

vm.GetIndex = index + 1;
vm.ExifOrientation = preLoadValue.ImageModel.EXIFOrientation;
vm.FileInfo = preLoadValue.ImageModel.FileInfo;
vm.ZoomValue = 1;
vm.PixelWidth = preLoadValue.ImageModel.PixelWidth;
vm.PixelHeight = preLoadValue.ImageModel.PixelHeight;
ExifHandling.UpdateExifValues(preLoadValue.ImageModel, vm);

if (SettingsHelper.Settings.ImageScaling.ShowImageSideBySide)
{
Expand Down
27 changes: 17 additions & 10 deletions src/PicView.Avalonia/StartUp/QuickLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public static async Task QuickLoadAsync(MainViewModel vm, string file)
await NavigationHelper.LoadPicFromArchiveAsync(file, vm).ConfigureAwait(false);
return;
}
vm.CurrentView = vm.ImageViewer;
vm.FileInfo ??= fileInfo;
vm.FileInfo = fileInfo;

var imageModel = await GetImageModel.GetImageModelAsync(fileInfo).ConfigureAwait(false);

Expand Down Expand Up @@ -60,8 +59,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
vm.ZoomValue = 1;
vm.PixelWidth = imageModel.PixelWidth;
vm.PixelHeight = imageModel.PixelHeight;

ExifHandling.UpdateExifValues(imageModel, vm);

vm.ImageIterator ??= new ImageIterator(fileInfo, vm);
vm.GetIndex = vm.ImageIterator.CurrentIndex + 1;

Expand All @@ -81,10 +79,7 @@ await Dispatcher.UIThread.InvokeAsync(() =>
SetTitleHelper.SetTitle(vm, imageModel);
}

if (SettingsHelper.Settings.UIProperties.IsTaskbarProgressEnabled)
{
vm.PlatformService.SetTaskbarProgress((ulong)vm.ImageIterator.CurrentIndex, (ulong)vm.ImageIterator.ImagePaths.Count);
}
vm.ExifOrientation = imageModel.EXIFOrientation;

// Add recent files, except when browsing archive
if (string.IsNullOrWhiteSpace(TempFileHelper.TempFilePath))
Expand All @@ -94,9 +89,21 @@ await Dispatcher.UIThread.InvokeAsync(() =>

var tasks = new List<Task>
{
vm.ImageIterator.AddAsync(vm.ImageIterator.CurrentIndex, imageModel),
vm.ImageIterator.Preload()
vm.ImageIterator.AddAsync(vm.ImageIterator.CurrentIndex, imageModel)
};

if (vm.ImageIterator.ImagePaths.Count > 1)
{
if (SettingsHelper.Settings.UIProperties.IsTaskbarProgressEnabled)
{
await Dispatcher.UIThread.InvokeAsync(() =>
{
vm.PlatformService.SetTaskbarProgress((ulong)vm.ImageIterator.CurrentIndex, (ulong)vm.ImageIterator.ImagePaths.Count);
});
}

tasks.Add(vm.ImageIterator.Preload());
}

if (SettingsHelper.Settings.Gallery.IsBottomGalleryShown)
{
Expand Down
9 changes: 9 additions & 0 deletions src/PicView.Avalonia/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PicView.Core.Extensions;
using PicView.Core.ImageDecoding;
using PicView.Core.Localization;
using ReactiveUI;

Expand Down Expand Up @@ -2137,5 +2138,13 @@ public double DpiY
set => this.RaiseAndSetIfChanged(ref _dpiY, value);
}

private EXIFHelper.EXIFOrientation? _exifOrientation;

public EXIFHelper.EXIFOrientation? ExifOrientation
{
get => _exifOrientation;
set => this.RaiseAndSetIfChanged(ref _exifOrientation, value);
}

#endregion Image
}
18 changes: 17 additions & 1 deletion src/PicView.Avalonia/Views/ExifView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using Avalonia.Controls;
using System.Reactive.Linq;
using Avalonia.Controls;
using Avalonia.Input;
using PicView.Avalonia.Converters;
using PicView.Avalonia.Navigation;
using PicView.Avalonia.Resizing;
using PicView.Avalonia.ViewModels;
using ReactiveUI;

namespace PicView.Avalonia.Views;

public partial class ExifView : UserControl
{
private IDisposable? _imageUpdateSubscription;

public ExifView()
{
InitializeComponent();
Expand All @@ -19,6 +24,17 @@ public ExifView()
PixelWidthTextBox.KeyUp += delegate { AdjustAspectRatio(PixelWidthTextBox); };
PixelHeightTextBox.KeyUp += delegate { AdjustAspectRatio(PixelHeightTextBox); };
if (DataContext is not MainViewModel vm)
{
return;
}
ExifHandling.UpdateExifValues(vm);
_imageUpdateSubscription = vm.WhenAnyValue(x => x.FileInfo).Select(x => x is not null).Subscribe(_ =>
{
ExifHandling.UpdateExifValues(vm);
});
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/PicView.WindowsNT/Taskbar/TaskbarProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class TaskbarProgress
/// </exception>
public TaskbarProgress(IntPtr windowHandle)
{
var hr = CoCreateInstance(ref _clsidTaskbarList, IntPtr.Zero, 1 /*CLSCTX_INPROC_SERVER*/, ref _iidITaskbarList3, out _taskbarInstance);
var hr = CoCreateInstance(ref _clsidTaskbarList, IntPtr.Zero, 1, ref _iidITaskbarList3, out _taskbarInstance);
if (hr != 0 || _taskbarInstance == null)
{
throw new InvalidOperationException("Failed to create TaskbarList COM object.");
Expand Down

0 comments on commit bc409bc

Please sign in to comment.