Skip to content
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

Remove IImageSourceServiceConfiguration #4954

Merged
merged 2 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
}
}

This file was deleted.

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