Skip to content
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
4 changes: 2 additions & 2 deletions .EditorConfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ csharp_style_deconstructed_variable_declaration = true
dotnet_diagnostic.IDE0042.severity = suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true
dotnet_diagnostic.IDE0045.severity = warning
dotnet_style_prefer_conditional_expression_over_return = true
dotnet_diagnostic.IDE0046.severity = warning
dotnet_style_prefer_conditional_expression_over_return = false
dotnet_diagnostic.IDE0046.severity = none
dotnet_style_prefer_compound_assignment = true
dotnet_diagnostic.IDE0054.severity = warning
dotnet_diagnostic.IDE0074.severity = warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddStorageManagerServiceInProcess(options =>
{
// Configure with custom script path
// options.BasePath = "content/";
// options.ScriptPath = $"custom-path/{FileSystemOptions.DefaultNamespace}.js";
});
builder.Services.AddStorageManagerServiceInProcess();

builder.Services.AddURLServiceInProcess();

Expand Down
19 changes: 2 additions & 17 deletions src/KristofferStrube.Blazor.FileSystem/BaseJSWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ public abstract class BaseJSWrapper : IAsyncDisposable, IJSWrapper
/// </summary>
protected readonly Lazy<Task<IJSObjectReference>> helperTask;

/// <summary>
/// Options for where the helper JS module is located.
/// </summary>
protected readonly FileSystemOptions fileSystemOptions;

/// <summary>
/// Options for where the helper JS module is located.
/// </summary>
[Obsolete("This is here for backwards compatibility. It was replaced by 'fileSystemOptions' as 'options' was ambiguous.")]
protected readonly FileSystemOptions options;

/// <inheritdoc/>
public IJSRuntime JSRuntime { get; }

Expand All @@ -35,13 +24,9 @@ public abstract class BaseJSWrapper : IAsyncDisposable, IJSWrapper
public bool DisposesJSReference { get; }

/// <inheritdoc cref="IJSCreatable{T}.CreateAsync(IJSRuntime, IJSObjectReference, CreationOptions)"/>
internal BaseJSWrapper(IJSRuntime jSRuntime, IJSObjectReference jSReference, FileSystemOptions fileSystemOptions, CreationOptions options)
internal BaseJSWrapper(IJSRuntime jSRuntime, IJSObjectReference jSReference, CreationOptions options)
{
this.fileSystemOptions = fileSystemOptions;
#pragma warning disable CS0618 // Type or member is obsolete
this.options = fileSystemOptions;
#pragma warning restore CS0618 // Type or member is obsolete
helperTask = new(async () => await jSRuntime.GetHelperAsync(fileSystemOptions));
helperTask = new(jSRuntime.GetHelperAsync);
JSReference = jSReference;
JSRuntime = jSRuntime;
DisposesJSReference = options.DisposesJSReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ namespace KristofferStrube.Blazor.FileSystem.Extensions;

internal static class IJSRuntimeExtensions
{
internal static async Task<IJSObjectReference> GetHelperAsync(this IJSRuntime jSRuntime, FileSystemOptions options)
{
return await GetHelperAsync<IJSObjectReference>(jSRuntime, options);
}
private const string helperPath = "./_content/KristofferStrube.Blazor.FileSystem/KristofferStrube.Blazor.FileSystem.js";

internal static async Task<IJSInProcessObjectReference> GetInProcessHelperAsync(this IJSRuntime jSRuntime, FileSystemOptions options)
internal static async Task<IJSObjectReference> GetHelperAsync(this IJSRuntime jSRuntime)
{
return await GetHelperAsync<IJSInProcessObjectReference>(jSRuntime, options);
return await jSRuntime.InvokeAsync<IJSObjectReference>("import", helperPath);
}

private static async Task<T> GetHelperAsync<T>(IJSRuntime jSRuntime, FileSystemOptions options)
internal static async Task<IJSInProcessObjectReference> GetInProcessHelperAsync(this IJSRuntime jSRuntime)
{
return await jSRuntime.InvokeAsync<T>("import", options.FullScriptPath);
return await jSRuntime.InvokeAsync<IJSInProcessObjectReference>("import", helperPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ public static class IServiceCollectionExtensions
/// <param name="serviceCollection">The service collection to add the service to.</param>
public static IServiceCollection AddStorageManagerService(this IServiceCollection serviceCollection)
{
return AddStorageManagerService(serviceCollection, null);
}

/// <summary>
/// Adds a <see cref="IStorageManagerService"/> to the service collection with the option to configure where the helper JS module is located.
/// </summary>
/// <param name="serviceCollection">The service collection to add the service to.</param>
/// <param name="configure">An action to configure the <see cref="FileSystemOptions"/> that defines where the helper JS module is located.</param>
public static IServiceCollection AddStorageManagerService(this IServiceCollection serviceCollection, Action<FileSystemOptions>? configure)
{
ConfigureFsOptions(serviceCollection, configure);

return serviceCollection.AddScoped<IStorageManagerService, StorageManagerService>();
}

Expand All @@ -34,18 +22,6 @@ public static IServiceCollection AddStorageManagerService(this IServiceCollectio
/// <param name="serviceCollection">The service collection to add the service to.</param>
public static IServiceCollection AddStorageManagerServiceInProcess(this IServiceCollection serviceCollection)
{
return AddStorageManagerServiceInProcess(serviceCollection, null);
}

/// <summary>
/// Adds a <see cref="IStorageManagerServiceInProcess"/> to the service collection with the option to configure where the helper JS module is located.
/// </summary>
/// <param name="serviceCollection">The service collection to add the service to.</param>
/// <param name="configure">An action to configure the <see cref="FileSystemOptions"/> that defines where the helper JS module is located.</param>
public static IServiceCollection AddStorageManagerServiceInProcess(this IServiceCollection serviceCollection, Action<FileSystemOptions>? configure)
{
ConfigureFsOptions(serviceCollection, configure);

return serviceCollection
.AddScoped<IStorageManagerServiceInProcess, StorageManagerServiceInProcess>()
.AddScoped(sp =>
Expand All @@ -54,12 +30,4 @@ public static IServiceCollection AddStorageManagerServiceInProcess(this IService
return (IStorageManagerService)service;
});
}

private static void ConfigureFsOptions(IServiceCollection services, Action<FileSystemOptions>? configure)
{
if (configure is null) { return; }

_ = services.Configure(configure);
configure(FileSystemOptions.DefaultInstance);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using KristofferStrube.Blazor.DOM.Extensions;
using KristofferStrube.Blazor.FileSystem.Extensions;
using KristofferStrube.Blazor.FileSystem.Extensions;
using KristofferStrube.Blazor.WebIDL;
using Microsoft.JSInterop;

Expand All @@ -21,43 +20,18 @@ public class FileSystemDirectoryHandleInProcess : FileSystemDirectoryHandle, IFi
/// <inheritdoc/>
public static async Task<FileSystemDirectoryHandleInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference)
{
return await CreateAsync(jSRuntime, jSReference, new CreationOptions());
return await CreateAsync(jSRuntime, jSReference, new());
}

/// <inheritdoc/>
public static async Task<FileSystemDirectoryHandleInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference, CreationOptions options)
{
IJSInProcessObjectReference inProcessHelper = await jSRuntime.GetInProcessHelperAsync(FileSystemOptions.DefaultInstance);
return new FileSystemDirectoryHandleInProcess(jSRuntime, inProcessHelper, jSReference, FileSystemOptions.DefaultInstance, options);
}

/// <summary>
/// Constructs a wrapper instance for an equivalent JS instance of a <see cref="FileSystemDirectoryHandleInProcess"/> with options for where the JS helper module will be found at.
/// </summary>
/// <param name="jSRuntime">An <see cref="IJSRuntime"/> instance.</param>
/// <param name="jSReference">A JS reference to an existing JS instance that should be wrapped.</param>
/// <param name="options">Options for what path the JS helper module will be found at.</param>
public static async Task<FileSystemDirectoryHandleInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference, FileSystemOptions options)
{
IJSInProcessObjectReference inProcessHelper = await jSRuntime.GetInProcessHelperAsync(options);
return new FileSystemDirectoryHandleInProcess(jSRuntime, inProcessHelper, jSReference, options, new() { DisposesJSReference = true });
}

/// <summary>
/// Constructs a wrapper instance for an equivalent JS instance of a <see cref="FileSystemDirectoryHandleInProcess"/> with options for where the JS helper module will be found at and whether its JS reference should be disposed.
/// </summary>
/// <param name="jSRuntime">An <see cref="IJSRuntime"/> instance.</param>
/// <param name="jSReference">A JS reference to an existing JS instance that should be wrapped.</param>
/// <param name="fileSystemOptions">Options for what path the JS helper module will be found at.</param>
/// <param name="creationOptions">Options for what path the JS helper module will be found at.</param>
public static async Task<FileSystemDirectoryHandleInProcess> CreateAsync(IJSRuntime jSRuntime, IJSInProcessObjectReference jSReference, FileSystemOptions fileSystemOptions, CreationOptions creationOptions)
{
IJSInProcessObjectReference inProcessHelper = await jSRuntime.GetInProcessHelperAsync(fileSystemOptions);
return new FileSystemDirectoryHandleInProcess(jSRuntime, inProcessHelper, jSReference, fileSystemOptions, creationOptions);
IJSInProcessObjectReference inProcessHelper = await jSRuntime.GetInProcessHelperAsync();
return new FileSystemDirectoryHandleInProcess(jSRuntime, inProcessHelper, jSReference, options);
}

/// <inheritdoc cref="CreateAsync(IJSRuntime, IJSInProcessObjectReference, CreationOptions)" />
protected FileSystemDirectoryHandleInProcess(IJSRuntime jSRuntime, IJSInProcessObjectReference inProcessHelper, IJSInProcessObjectReference jSReference, FileSystemOptions fileSystemOptions, CreationOptions options) : base(jSRuntime, jSReference, fileSystemOptions, options)
protected FileSystemDirectoryHandleInProcess(IJSRuntime jSRuntime, IJSInProcessObjectReference inProcessHelper, IJSInProcessObjectReference jSReference, CreationOptions options) : base(jSRuntime, jSReference, options)
{
this.inProcessHelper = inProcessHelper;
JSReference = jSReference;
Expand All @@ -83,21 +57,21 @@ protected FileSystemDirectoryHandleInProcess(IJSRuntime jSRuntime, IJSInProcessO
{
FileSystemHandleInProcess fileSystemHandle = await FileSystemHandleInProcess.CreateAsync(
JSRuntime,
await jSEntries.InvokeAsync<IJSInProcessObjectReference>("at", i),
fileSystemOptions);
await jSEntries.InvokeAsync<IJSInProcessObjectReference>("at", i)
);

FileSystemHandleKind kind = await fileSystemHandle.GetKindAsync();

if (kind is FileSystemHandleKind.File)
{
return await FileSystemFileHandleInProcess.CreateAsync(JSRuntime, fileSystemHandle.JSReference, fileSystemOptions, new CreationOptions()
return await FileSystemFileHandleInProcess.CreateAsync(JSRuntime, fileSystemHandle.JSReference, new()
{
DisposesJSReference = true
});
}
else
{
return await CreateAsync(JSRuntime, fileSystemHandle.JSReference, new CreationOptions()
return await CreateAsync(JSRuntime, fileSystemHandle.JSReference, new()
{
DisposesJSReference = true
});
Expand All @@ -112,7 +86,7 @@ await jSEntries.InvokeAsync<IJSInProcessObjectReference>("at", i),
public new async Task<FileSystemFileHandleInProcess> GetFileHandleAsync(string name, FileSystemGetFileOptions? options = null)
{
IJSInProcessObjectReference jSFileSystemFileHandle = await JSReference.InvokeAsync<IJSInProcessObjectReference>("getFileHandle", name, options);
return await FileSystemFileHandleInProcess.CreateAsync(JSRuntime, jSFileSystemFileHandle, fileSystemOptions, new CreationOptions()
return await FileSystemFileHandleInProcess.CreateAsync(JSRuntime, jSFileSystemFileHandle, new()
{
DisposesJSReference = true
});
Expand All @@ -122,7 +96,7 @@ await jSEntries.InvokeAsync<IJSInProcessObjectReference>("at", i),
public new async Task<FileSystemDirectoryHandleInProcess> GetDirectoryHandleAsync(string name, FileSystemGetDirectoryOptions? options = null)
{
IJSInProcessObjectReference jSFileSystemFileHandle = await JSReference.InvokeAsync<IJSInProcessObjectReference>("getDirectoryHandle", name, options);
return await CreateAsync(JSRuntime, jSFileSystemFileHandle, fileSystemOptions, new CreationOptions()
return await CreateAsync(JSRuntime, jSFileSystemFileHandle, new()
{
DisposesJSReference = true
});
Expand Down
Loading