Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Keep the colour profile without metadata, scroll the presets list on its own, stay quiet offline

KnifeLemon35980d91f474
diff --git a/Directory.Build.props b/Directory.Build.props
index dcd8a42a..298451d9 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -14,7 +14,7 @@
parameters of a member is fine (CS1573). -->
<NoWarn>$(NoWarn);CS1591;CS1573</NoWarn>
- <Version>1.2.2</Version>
+ <Version>1.2.3</Version>
<Product>Filee</Product>
<Authors>Filee contributors</Authors>
<Copyright>Copyright (c) Filee contributors</Copyright>
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index 1533acc1..cc1bef99 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -244,6 +244,8 @@
"presets.dpi": "DPI",
"presets.dpi_keep": "Keep",
"presets.keep_metadata": "Keep metadata (EXIF)",
+ "presets.keep_color_profile": "Keep colour profile (ICC)",
+ "presets.keep_color_profile_hint": "Available when metadata is removed. Without the colour profile, wide-gamut photos (Display P3 from phones) can look washed out.",
"presets.grayscale": "Grayscale",
"presets.background": "Background for transparency",
"presets.tiff_compression": "TIFF compression",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 1e2c7d12..bfd5effb 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -244,6 +244,8 @@
"presets.dpi": "DPI",
"presets.dpi_keep": "유지",
"presets.keep_metadata": "메타데이터(EXIF) 유지",
+ "presets.keep_color_profile": "색 프로필 유지 (ICC)",
+ "presets.keep_color_profile_hint": "메타데이터를 지울 때 선택할 수 있어요. 색 프로필이 없으면 휴대폰의 Display P3 사진처럼 색 영역이 넓은 사진은 색이 바래 보일 수 있어요.",
"presets.grayscale": "흑백으로",
"presets.background": "투명 영역 배경색",
"presets.tiff_compression": "TIFF 압축",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index b2f3ec2d..60188273 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -244,6 +244,8 @@
"presets.dpi": "DPI",
"presets.dpi_keep": "保持",
"presets.keep_metadata": "保留元数据 (EXIF)",
+ "presets.keep_color_profile": "保留颜色配置文件 (ICC)",
+ "presets.keep_color_profile_hint": "删除元数据时可选。没有颜色配置文件时,手机拍摄的 Display P3 等广色域照片可能会显得发灰。",
"presets.grayscale": "转为灰度",
"presets.background": "透明区域背景色",
"presets.tiff_compression": "TIFF 压缩",
diff --git a/src/Filee.App/Services/UpdateService.cs b/src/Filee.App/Services/UpdateService.cs
index 02844285..bc9006ba 100644
--- a/src/Filee.App/Services/UpdateService.cs
+++ b/src/Filee.App/Services/UpdateService.cs
@@ -21,10 +21,15 @@ public sealed partial class UpdateService : ObservableObject
private readonly HttpClient _http;
private DispatcherTimer? _timer;
- public UpdateService(ILogger<UpdateService> log)
+ public UpdateService(ILogger<UpdateService> log) : this(log, new HttpClientHandler())
+ {
+ }
+
+ /// <param name="handler">Network access; tests pass a handler that simulates being offline.</param>
+ internal UpdateService(ILogger<UpdateService> log, HttpMessageHandler handler)
{
_log = log;
- _http = new HttpClient { Timeout = TimeSpan.FromSeconds(20) };
+ _http = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(20) };
_http.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Filee", CurrentVersion));
_http.DefaultRequestHeaders.Accept.ParseAdd("application/vnd.github+json");
}
@@ -82,7 +87,10 @@ public sealed partial class UpdateService : ObservableObject
await Dispatcher.UIThread.InvokeAsync(() => Publish(newer));
return newer;
}
- catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException or JsonException or InvalidOperationException)
+ // Offline, DNS failure, timeout, a connection dropped while reading, or an unexpected answer: Filee works
+ // offline, so a failed check is only logged and the next one is tried later.
+ catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException or IOException or JsonException
+ or InvalidOperationException)
{
_log.LogInformation("Update check failed: {Message}", ex.Message);
return LatestVersion;
diff --git a/src/Filee.App/ViewModels/MainWindowViewModel.cs b/src/Filee.App/ViewModels/MainWindowViewModel.cs
index 2ab6fe70..6c210ccf 100644
--- a/src/Filee.App/ViewModels/MainWindowViewModel.cs
+++ b/src/Filee.App/ViewModels/MainWindowViewModel.cs
@@ -2,6 +2,7 @@
using Avalonia;
using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
@@ -71,7 +72,15 @@ public sealed partial class MainWindowViewModel : ObservableObject
public UpdateService Updates { get; }
[ObservableProperty] private NavItem _selectedItem;
- [ObservableProperty] private ObservableObject _currentPage;
+ [ObservableProperty]
+ [NotifyPropertyChangedFor(nameof(PageScroll))]
+ private ObservableObject _currentPage;
+
+ /// <summary>
+ /// Pages scroll as a whole, except pages that fit the window height and scroll their own parts
+ /// (<see cref="IFitsWindowHeight"/>, e.g. the presets list and editor).
+ /// </summary>
+ public ScrollBarVisibility PageScroll => CurrentPage is IFitsWindowHeight ? ScrollBarVisibility.Disabled : ScrollBarVisibility.Auto;
[ObservableProperty] private string _versionText = "";
[ObservableProperty] private string _updateText = "";
diff --git a/src/Filee.App/ViewModels/Pages/PresetsPageViewModel.cs b/src/Filee.App/ViewModels/Pages/PresetsPageViewModel.cs
index 9f0627fe..b786b7d1 100644
--- a/src/Filee.App/ViewModels/Pages/PresetsPageViewModel.cs
+++ b/src/Filee.App/ViewModels/Pages/PresetsPageViewModel.cs
@@ -28,7 +28,10 @@ public sealed partial class PresetListItem(Preset preset, ILocalizer loc) : Obse
: "→ " + (FormatLabels.NameOf(l, p.TargetFormat) ?? p.TargetFormat);
}
-public sealed partial class PresetsPageViewModel : ObservableObject
+/// <summary>Pages that fill the window height and scroll their own parts instead of scrolling as a whole.</summary>
+public interface IFitsWindowHeight;
+
+public sealed partial class PresetsPageViewModel : ObservableObject, IFitsWindowHeight
{
private readonly UserDataStore _store;
private readonly ILocalizer _loc;
diff --git a/src/Filee.App/ViewModels/PresetEditorViewModel.cs b/src/Filee.App/ViewModels/PresetEditorViewModel.cs
index 7a816b81..05bc90d9 100644
--- a/src/Filee.App/ViewModels/PresetEditorViewModel.cs
+++ b/src/Filee.App/ViewModels/PresetEditorViewModel.cs
@@ -86,6 +86,7 @@ public sealed partial class PresetEditorViewModel : ObservableObject
_setDpi = _edit.Image.Dpi.HasValue;
_dpi = _edit.Image.Dpi ?? 300;
_keepMetadata = _edit.Image.KeepMetadata;
+ _keepColorProfile = _edit.Image.KeepColorProfile;
_grayscale = _edit.Image.Grayscale;
_background = _edit.Image.Background;
_webpLossless = _edit.Image.WebpLossless;
@@ -140,7 +141,28 @@ public sealed partial class PresetEditorViewModel : ObservableObject
[ObservableProperty] private int _longEdge;
[ObservableProperty] private bool _setDpi;
[ObservableProperty] private int _dpi;
- [ObservableProperty] private bool _keepMetadata;
+ [ObservableProperty]
+ [NotifyPropertyChangedFor(nameof(CanChangeColorProfile), nameof(ColorProfileChecked))]
+ private bool _keepMetadata;
+
+ /// <summary>Keep the ICC colour profile when metadata is removed (ImageOptions.KeepColorProfile).</summary>
+ [ObservableProperty]
+ [NotifyPropertyChangedFor(nameof(ColorProfileChecked))]
+ private bool _keepColorProfile;
+
+ /// <summary>The colour profile choice only matters while metadata is removed; kept metadata includes it.</summary>
+ public bool CanChangeColorProfile => !KeepMetadata;
+
+ /// <summary>What the checkbox shows: always ticked (and disabled) while all metadata is kept.</summary>
+ public bool ColorProfileChecked
+ {
+ get => KeepMetadata || KeepColorProfile;
+ set
+ {
+ if (!KeepMetadata)
+ KeepColorProfile = value;
+ }
+ }
[ObservableProperty] private bool _grayscale;
[ObservableProperty] private string _background;
[ObservableProperty] private bool _webpLossless;
@@ -214,6 +236,7 @@ public sealed partial class PresetEditorViewModel : ObservableObject
image.LongEdge = Math.Clamp(LongEdge, 16, 20000);
image.Dpi = SetDpi ? Math.Clamp(Dpi, 36, 2400) : null;
image.KeepMetadata = KeepMetadata;
+ image.KeepColorProfile = KeepColorProfile;
image.Grayscale = Grayscale;
image.Background = string.IsNullOrWhiteSpace(Background) ? "#FFFFFF" : Background.Trim();
image.TiffCompression = TiffCompression.Value;
diff --git a/src/Filee.App/Views/MainWindow.axaml b/src/Filee.App/Views/MainWindow.axaml
index 97aa7ec8..67cb631b 100644
--- a/src/Filee.App/Views/MainWindow.axaml
+++ b/src/Filee.App/Views/MainWindow.axaml
@@ -45,7 +45,7 @@
</Border>
<!-- Page -->
- <ScrollViewer Grid.Column="1" x:Name="PageScroller">
+ <ScrollViewer Grid.Column="1" x:Name="PageScroller" VerticalScrollBarVisibility="{Binding PageScroll}">
<ContentControl Classes="page" Content="{Binding CurrentPage}" Margin="32,26,32,32" MaxWidth="980" HorizontalAlignment="Stretch" />
</ScrollViewer>
</Grid>
diff --git a/src/Filee.App/Views/Pages/PresetsPage.axaml b/src/Filee.App/Views/Pages/PresetsPage.axaml
index 472fbc1b..3903e6a5 100644
--- a/src/Filee.App/Views/Pages/PresetsPage.axaml
+++ b/src/Filee.App/Views/Pages/PresetsPage.axaml
@@ -7,9 +7,9 @@
<Grid RowDefinitions="Auto,*" ColumnDefinitions="260,20,*">
<TextBlock Grid.ColumnSpan="3" Classes="h1" Text="{DynamicResource presets.title}" Margin="0,0,0,18" />
- <!-- List -->
- <StackPanel Grid.Row="1" Spacing="8">
- <WrapPanel>
+ <!-- List: fits the window height and scrolls on its own (the page itself does not scroll, IFitsWindowHeight) -->
+ <DockPanel Grid.Row="1">
+ <WrapPanel DockPanel.Dock="Top" Margin="0,0,0,8">
<Button Classes="accent" Command="{Binding AddCommand}" Margin="0,0,6,6">
<StackPanel Orientation="Horizontal" Spacing="6">
<PathIcon Width="12" Height="12" Data="{StaticResource Icon.Plus}" />
@@ -33,18 +33,22 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
- </StackPanel>
+ </DockPanel>
- <!-- Editor (same control as the donut's preset popup) -->
- <StackPanel Grid.Row="1" Grid.Column="2" Spacing="12">
- <TextBlock Classes="muted" Text="{DynamicResource presets.select}" IsVisible="{Binding Editor, Converter={x:Static ObjectConverters.IsNull}}" />
- <views:PresetEditorView DataContext="{Binding Editor}" IsVisible="{Binding $parent[UserControl].((vm:PresetsPageViewModel)DataContext).Editor, Converter={x:Static ObjectConverters.IsNotNull}}" />
- <StackPanel Orientation="Horizontal" Spacing="8" HorizontalAlignment="Right"
+ <!-- Editor (same control as the donut's preset popup): scrolls on its own, Save stays visible below it -->
+ <DockPanel Grid.Row="1" Grid.Column="2">
+ <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Spacing="8" HorizontalAlignment="Right" Margin="0,12,0,0"
IsVisible="{Binding Editor, Converter={x:Static ObjectConverters.IsNotNull}}">
<TextBlock Text="{Binding SavedMessage}" VerticalAlignment="Center" Foreground="{DynamicResource SuccessBrush}" FontWeight="Bold" />
<Button Content="{DynamicResource presets.revert}" Command="{Binding RevertCommand}" />
<Button Classes="accent" Content="{DynamicResource presets.save}" Command="{Binding SaveCommand}" />
</StackPanel>
- </StackPanel>
+ <ScrollViewer>
+ <StackPanel Spacing="12" Margin="0,0,12,0">
+ <TextBlock Classes="muted" Text="{DynamicResource presets.select}" IsVisible="{Binding Editor, Converter={x:Static ObjectConverters.IsNull}}" />
+ <views:PresetEditorView DataContext="{Binding Editor}" IsVisible="{Binding $parent[UserControl].((vm:PresetsPageViewModel)DataContext).Editor, Converter={x:Static ObjectConverters.IsNotNull}}" />
+ </StackPanel>
+ </ScrollViewer>
+ </DockPanel>
</Grid>
</UserControl>
diff --git a/src/Filee.App/Views/PresetEditorView.axaml b/src/Filee.App/Views/PresetEditorView.axaml
index 535df2bd..c6e7a860 100644
--- a/src/Filee.App/Views/PresetEditorView.axaml
+++ b/src/Filee.App/Views/PresetEditorView.axaml
@@ -68,6 +68,8 @@
</Grid>
<WrapPanel>
<CheckBox Content="{DynamicResource presets.keep_metadata}" IsChecked="{Binding KeepMetadata}" Margin="0,0,18,0" />
+ <CheckBox Content="{DynamicResource presets.keep_color_profile}" IsChecked="{Binding ColorProfileChecked}"
+ IsEnabled="{Binding CanChangeColorProfile}" ToolTip.Tip="{DynamicResource presets.keep_color_profile_hint}" ToolTip.ShowOnDisabled="True" Margin="0,0,18,0" />
<CheckBox Content="{DynamicResource presets.grayscale}" IsChecked="{Binding Grayscale}" Margin="0,0,18,0" />
<CheckBox Content="{DynamicResource presets.webp_lossless}" IsChecked="{Binding WebpLossless}" IsVisible="{Binding ShowWebp}" />
</WrapPanel>
diff --git a/src/Filee.Core/Presets/Preset.cs b/src/Filee.Core/Presets/Preset.cs
index f58287bf..5e95e9c2 100644
--- a/src/Filee.Core/Presets/Preset.cs
+++ b/src/Filee.Core/Presets/Preset.cs
@@ -99,6 +99,12 @@ public sealed class ImageOptions
/// <summary>Keep EXIF / XMP / ICC metadata.</summary>
public bool KeepMetadata { get; set; } = true;
+ /// <summary>
+ /// When metadata is removed, still keep the ICC colour profile: without it, wide-gamut photos (Display P3 from
+ /// phones) look washed out. Has no effect while <see cref="KeepMetadata"/> is on (everything is kept then).
+ /// </summary>
+ public bool KeepColorProfile { get; set; } = true;
+
/// <summary>Convert to grayscale.</summary>
public bool Grayscale { get; set; }
diff --git a/src/Filee.Engines/Magick/ImageEncoder.cs b/src/Filee.Engines/Magick/ImageEncoder.cs
index ca7aa0f0..5c2d3167 100644
--- a/src/Filee.Engines/Magick/ImageEncoder.cs
+++ b/src/Filee.Engines/Magick/ImageEncoder.cs
@@ -137,7 +137,12 @@ internal static class ImageEncoder
image.Density = new Density(options.Dpi.Value, options.Dpi.Value, DensityUnit.PixelsPerInch);
if (!options.KeepMetadata)
+ {
+ var colorProfile = options.KeepColorProfile ? image.GetColorProfile() : null;
image.Strip();
+ if (colorProfile is not null)
+ image.SetProfile(colorProfile);
+ }
if (NoAlpha.Contains(targetFormat) && image.HasAlpha)
{
diff --git a/tests/Filee.App.Tests/UpdateServiceTests.cs b/tests/Filee.App.Tests/UpdateServiceTests.cs
index 1e662afd..3820ece0 100644
--- a/tests/Filee.App.Tests/UpdateServiceTests.cs
+++ b/tests/Filee.App.Tests/UpdateServiceTests.cs
@@ -1,4 +1,7 @@
+using System.Net;
+using System.Net.Sockets;
using Filee.App.Services;
+using Microsoft.Extensions.Logging.Abstractions;
namespace Filee.App.Tests;
@@ -15,6 +18,47 @@ public class UpdateServiceTests
public void Release_tags_compare_by_version(string? tag, string current, bool newer) =>
Assert.Equal(newer, UpdateService.IsNewer(tag, current));
+ /// <summary>Filee works offline: a failed update check must neither throw nor report an update.</summary>
+ public static TheoryData<string> OfflineFailures => ["no network", "timeout", "dropped while reading", "not json"];
+
+ [Theory]
+ [MemberData(nameof(OfflineFailures))]
+ public async Task Update_check_without_internet_is_quiet(string failure)
+ {
+ var updates = new UpdateService(NullLogger<UpdateService>.Instance, new FakeNetwork(failure));
+
+ var found = await updates.CheckAsync(TestContext.Current.CancellationToken);
+
+ Assert.Null(found);
+ Assert.False(updates.IsUpdateAvailable);
+ }
+
+ private sealed class FakeNetwork(string failure) : HttpMessageHandler
+ {
+ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) => failure switch
+ {
+ "no network" => throw new HttpRequestException("No such host is known.", new SocketException((int)SocketError.HostNotFound)),
+ "timeout" => throw new TaskCanceledException("The request was canceled due to the configured HttpClient.Timeout."),
+ "dropped while reading" => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(new BrokenStream()) }),
+ _ => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("<html>captive portal</html>") }),
+ };
+ }
+
+ /// <summary>A response body whose connection breaks after the headers.</summary>
+ private sealed class BrokenStream : Stream
+ {
+ public override bool CanRead => true;
+ public override bool CanSeek => false;
+ public override bool CanWrite => false;
+ public override long Length => throw new NotSupportedException();
+ public override long Position { get => 0; set => throw new NotSupportedException(); }
+ public override int Read(byte[] buffer, int offset, int count) => throw new IOException("The connection was reset.");
+ public override void Flush() { }
+ public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
+ public override void SetLength(long value) => throw new NotSupportedException();
+ public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException();
+ }
+
[Fact]
public void Download_page_is_the_latest_release()
{
diff --git a/tests/Filee.Engines.Tests/ImageAndPdfTests.cs b/tests/Filee.Engines.Tests/ImageAndPdfTests.cs
index b8b3f70c..5d9910c5 100644
--- a/tests/Filee.Engines.Tests/ImageAndPdfTests.cs
+++ b/tests/Filee.Engines.Tests/ImageAndPdfTests.cs
@@ -103,6 +103,36 @@ public class ImageAndPdfTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Equal(2, job.Outputs.Count());
}
+ [Theory]
+ [InlineData(true, true, true)] // all metadata kept
+ [InlineData(false, true, false)] // metadata removed, colour profile kept
+ [InlineData(false, false, false)] // everything removed
+ public async Task Removing_metadata_can_keep_the_colour_profile(bool keepMetadata, bool keepColorProfile, bool exifExpected)
+ {
+ var dir = fx.NewFolder();
+ var source = Path.Combine(dir, "photo.jpg");
+ using (var image = new MagickImage(MagickColors.SkyBlue, 64, 48))
+ {
+ var exif = new ExifProfile();
+ exif.SetValue(ExifTag.Model, "TestPhone");
+ image.SetProfile(exif);
+ // A wide-gamut profile, like Display P3 from a phone (an sRGB profile would just become PNG's sRGB chunk).
+ image.SetProfile(ColorProfiles.AdobeRGB1998);
+ image.Write(source, MagickFormat.Jpeg);
+ }
+
+ var job = await fx.ConvertAsync([source], new Preset
+ {
+ TargetFormat = "webp",
+ Image = { KeepMetadata = keepMetadata, KeepColorProfile = keepColorProfile },
+ });
+
+ AssertDone(job);
+ using var result = new MagickImage(job.Outputs.Single());
+ Assert.Equal(exifExpected, result.GetExifProfile() is not null);
+ Assert.Equal(keepMetadata || keepColorProfile, result.GetColorProfile() is not null);
+ }
+
[Fact]
public async Task Jpg_output_flattens_transparency_and_applies_quality()
{