Skip to content

Commit

Permalink
Remove IImageSourceServiceConfiguration (#4954)
Browse files Browse the repository at this point in the history
* Remove IImageSourceServiceConfiguration

This was a hack around a hack

* oops
  • Loading branch information
mattleibow committed Feb 28, 2022
1 parent 67b39b1 commit 7165e52
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal static MauiAppBuilder ConfigureImageSourceHandlers(this MauiAppBuilder
{
builder.ConfigureImageSources(services =>
{
services.AddService<FileImageSource>(svcs => new FileImageSourceService(svcs.GetService<IImageSourceServiceConfiguration>(), svcs.CreateLogger<FileImageSourceService>()));
services.AddService<FileImageSource>(svcs => new FileImageSourceService(svcs.CreateLogger<FileImageSourceService>()));
services.AddService<FontImageSource>(svcs => new FontImageSourceService(svcs.GetRequiredService<IFontManager>(), svcs.CreateLogger<FontImageSourceService>()));
services.AddService<StreamImageSource>(svcs => new StreamImageSourceService(svcs.CreateLogger<StreamImageSourceService>()));
services.AddService<UriImageSource>(svcs => new UriImageSourceService(svcs.CreateLogger<UriImageSourceService>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ public static string GetImageDirectory(BindableObject element)

static void OnImageDirectoryChanged(BindableObject bindable, object oldValue, object newValue)
{
#if WINDOWS
var config = MauiWinUIApplication.Current.Services.GetService<IImageSourceServiceConfiguration>();
config?.SetImageDirectory(newValue?.ToString());
#endif
// TODO: somehow pass this onto Core
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static MauiAppBuilder ConfigureImageSources(this MauiAppBuilder builder)
{
builder.ConfigureImageSources(services =>
{
services.AddService<IFileImageSource>(svcs => new FileImageSourceService(svcs.GetService<IImageSourceServiceConfiguration>(), svcs.CreateLogger<FileImageSourceService>()));
services.AddService<IFileImageSource>(svcs => new FileImageSourceService(svcs.CreateLogger<FileImageSourceService>()));
services.AddService<IFontImageSource>(svcs => new FontImageSourceService(svcs.GetRequiredService<IFontManager>(), svcs.CreateLogger<FontImageSourceService>()));
services.AddService<IStreamImageSource>(svcs => new StreamImageSourceService(svcs.CreateLogger<StreamImageSourceService>()));
services.AddService<IUriImageSource>(svcs => new UriImageSourceService(svcs.CreateLogger<UriImageSourceService>()));
Expand All @@ -28,7 +28,6 @@ public static MauiAppBuilder ConfigureImageSources(this MauiAppBuilder builder,
builder.Services.AddSingleton<ImageSourceRegistration>(new ImageSourceRegistration(configureDelegate));
}

builder.Services.TryAddSingleton<IImageSourceServiceConfiguration, ImageSourceServiceConfiguration>();
builder.Services.TryAddSingleton<IImageSourceServiceProvider>(svcs => new ImageSourceServiceProvider(svcs.GetRequiredService<IImageSourceServiceCollection>(), svcs));
builder.Services.TryAddSingleton<IImageSourceServiceCollection, ImageSourceServiceBuilder>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public partial class FileImageSourceService

BitmapImage GetAppPackage(string filename)
{
return new BitmapImage(new Uri("ms-appx:///" + Configuration.GetFileLocation(filename)));
return new BitmapImage(new Uri("ms-appx:///" + filename));
}

static async Task<BitmapImage?> GetLocal(string filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ namespace Microsoft.Maui
public partial class FileImageSourceService : ImageSourceService, IImageSourceService<IFileImageSource>
{
public FileImageSourceService()
: this(null, null)
: this(null)
{
}

public FileImageSourceService(IImageSourceServiceConfiguration? configuration = null, ILogger<FileImageSourceService>? logger = null)
public FileImageSourceService(ILogger<FileImageSourceService>? logger = null)
: base(logger)
{
Configuration = configuration;
}

public IImageSourceServiceConfiguration? Configuration { get; }
}
}
9 changes: 0 additions & 9 deletions src/Core/src/ImageSources/IImageSourceServiceConfiguration.cs

This file was deleted.

9 changes: 0 additions & 9 deletions src/Core/src/ImageSources/ImageSourceServiceConfiguration.cs

This file was deleted.

This file was deleted.

17 changes: 1 addition & 16 deletions src/Core/src/Platform/Windows/ImageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,13 @@ public static Size GetImageSourceSize(this ImageSource source, FrameworkElement?
throw new InvalidCastException($"\"{source.GetType().FullName}\" is not supported.");
}

internal static string GetFileLocation(this IImageSourceServiceConfiguration? configuration, string filename)
{
var imageDirectory = configuration?.GetImageDirectory();
if (!string.IsNullOrEmpty(imageDirectory))
{
var directory = Path.GetDirectoryName(filename);
if (string.IsNullOrEmpty(directory) || !Path.GetFullPath(directory).Equals(Path.GetFullPath(imageDirectory)))
filename = Path.Combine(imageDirectory, filename);
}

return filename;
}

public static IconSource? ToIconSource(this IImageSource source, IMauiContext mauiContext)
{
IconSource? image = null;

if (source is IFileImageSource fis)
{
var configuration = mauiContext.Services?.GetService<IImageSourceServiceConfiguration>();
string filename = configuration.GetFileLocation(fis.File);
image = new BitmapIconSource { UriSource = new Uri("ms-appx:///" + filename) };
image = new BitmapIconSource { UriSource = new Uri("ms-appx:///" + fis.File) };
}
else if (source is IUriImageSource uri)
{
Expand Down

0 comments on commit 7165e52

Please sign in to comment.