Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/Validate/ValidateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public virtual void ToggleMessage(IEnumerable<ValidationResult> results)

private JSModule? ValidateModule { get; set; }

private Task<JSModule> LoadValidateModule() => JSRuntime.LoadModule("./_content/BootstrapBlazor/modules/validate.js");
private Task<JSModule> LoadValidateModule() => JSRuntime.LoadModuleByName("validate");

/// <summary>
/// 增加客户端 Tooltip 方法
Expand Down
10 changes: 3 additions & 7 deletions src/BootstrapBlazor/Components/WebSpeech/WebSpeechService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace BootstrapBlazor.Components;
/// <summary>
/// Web Speech 服务
/// </summary>
public class WebSpeechService(IJSRuntime runtime, IComponentIdGenerator ComponentIdGenerator, ILogger<WebSpeechService> logger)
public class WebSpeechService(IJSRuntime runtime, IComponentIdGenerator ComponentIdGenerator)
{
private JSModule? SynthesisModule { get; set; }

Expand All @@ -24,9 +24,7 @@ public async Task<WebSpeechSynthesizer> CreateSynthesizerAsync()
{
if (SynthesisModule == null)
{
var moduleName = "./_content/BootstrapBlazor/modules/synthesis.js";
logger.LogInformation("load module {moduleName}", moduleName);
SynthesisModule = await runtime.LoadModule(moduleName);
SynthesisModule = await runtime.LoadModuleByName("synthesis");
}
return new WebSpeechSynthesizer(SynthesisModule, ComponentIdGenerator);
}
Expand All @@ -39,9 +37,7 @@ public async Task<WebSpeechRecognition> CreateRecognitionAsync()
{
if (RecognitionModule == null)
{
var moduleName = "./_content/BootstrapBlazor/modules/recognition.js";
logger.LogInformation("load module {moduleName}", moduleName);
RecognitionModule = await runtime.LoadModule(moduleName);
RecognitionModule = await runtime.LoadModuleByName("recognition");
}
return new WebSpeechRecognition(RecognitionModule, ComponentIdGenerator);
}
Expand Down
8 changes: 7 additions & 1 deletion src/BootstrapBlazor/Extensions/JSModuleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ public static class JSModuleExtensions
/// <param name="jsRuntime"></param>
/// <param name="version"></param>
/// <returns>A <see cref="Task"/><![CDATA[<]]><see cref="JSModule"/><![CDATA[>]]> 模块加载器</returns>
public static Task<JSModule> LoadUtility(this IJSRuntime jsRuntime, string? version = null) => LoadModule(jsRuntime, "./_content/BootstrapBlazor/modules/utility.js", version);
public static Task<JSModule> LoadUtility(this IJSRuntime jsRuntime, string? version = null) => LoadModuleByName(jsRuntime, "utility", version);

internal static Task<JSModule> LoadModuleByName(this IJSRuntime jsRuntime, string moduleName, string? version = null)
{
var fileName = $"./_content/BootstrapBlazor/modules/{moduleName}.js";
return LoadModule(jsRuntime, fileName, version);
}

/// <summary>
/// IJSRuntime 扩展方法 动态加载脚本 脚本目录为 modules
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Services/AjaxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AjaxService(IJSRuntime jSRuntime)
[NotNull]
private JSModule? _module = null;

private Task<JSModule> LoadModule() => jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/ajax.js");
private Task<JSModule> LoadModule() => jSRuntime.LoadModuleByName("ajax");

/// <summary>
/// 调用Ajax方法发送请求
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Services/Bluetooth/DefaultBluetooth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public DefaultBluetooth(IJSRuntime jsRuntime)

private async Task<JSModule> LoadModule()
{
var module = await _runtime.LoadModule("./_content/BootstrapBlazor/modules/bt.js");
var module = await _runtime.LoadModuleByName("bt");

IsSupport = await module.InvokeAsync<bool>("init");
return module;
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Services/ClipboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ClipboardService(IJSRuntime jSRuntime)
[NotNull]
private JSModule? _module = null;

private Task<JSModule> LoadModule() => jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/utility.js");
private Task<JSModule> LoadModule() => jSRuntime.LoadUtility();

/// <summary>
/// 获取剪切板数据方法
Expand Down
4 changes: 1 addition & 3 deletions src/BootstrapBlazor/Services/DefaultBrowserFingerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ class DefaultBrowserFingerService(IJSRuntime jSRuntime) : IBrowserFingerService
[NotNull]
private JSModule? _module = null;

private Task<JSModule> LoadModule() => jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/utility.js");

/// <summary>
/// 获取剪切板数据方法
/// </summary>
public async Task<string?> GetFingerCodeAsync(CancellationToken token = default)
{
_module ??= await LoadModule();
_module ??= await jSRuntime.LoadUtility();
return await _module.InvokeAsync<string?>("getFingerCode", token);
}
}
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Services/DefaultGeoLocationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DefaultGeoLocationService(IJSRuntime jsRuntime)
Interop = DotNetObjectReference.Create(this);
}

private Task<JSModule> LoadModule() => JSRuntime.LoadModule("./_content/BootstrapBlazor/modules/geo.js");
private Task<JSModule> LoadModule() => JSRuntime.LoadModuleByName("geo");

/// <summary>
/// get the current position of the device
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Services/EyeDropperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class EyeDropperService(IJSRuntime jSRuntime)
/// <returns></returns>
public async Task<string?> PickAsync(CancellationToken token = default)
{
_module ??= await jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/eye-dropper.js");
_module ??= await jSRuntime.LoadModuleByName("eye-dropper");
return await _module.InvokeAsync<string?>("open", token);
}
}
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Services/FullScreenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FullScreenService(IJSRuntime jSRuntime)
/// <returns></returns>
public async Task Toggle(FullScreenOption? option = null, CancellationToken token = default)
{
_module ??= await jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/fullscreen.js");
_module ??= await jSRuntime.LoadModuleByName("fullscreen");
await _module.InvokeVoidAsync("toggle", token, option);
}
}
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Services/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public NotificationService(IJSRuntime runtime, ICacheManager cache)
Interop = DotNetObjectReference.Create(this);
}

private Task<JSModule> LoadModule() => JSRuntime.LoadModule("./_content/BootstrapBlazor/modules/noti.js");
private Task<JSModule> LoadModule() => JSRuntime.LoadModuleByName("noti");

/// <summary>
/// 检查浏览器通知权限状态
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DefaultSerialService(IJSRuntime jsRuntime)

private async Task<JSModule> LoadModule()
{
var module = await _runtime.LoadModule("./_content/BootstrapBlazor/modules/serial.js");
var module = await _runtime.LoadModuleByName("serial");

IsSupport = await module.InvokeAsync<bool>("init", _serialPortId);
return module;
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Services/TitleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TitleService(IJSRuntime jSRuntime)
/// <returns></returns>
public async Task SetTitle(string title, CancellationToken token = default)
{
_module ??= await jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/utility.js");
_module ??= await jSRuntime.LoadUtility();
await _module.InvokeVoidAsync("setTitle", token, title);
}
}
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Services/WebClientService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task<ClientInfo> GetClientInfo()

try
{
_jsModule ??= await runtime.LoadModule("./_content/BootstrapBlazor/modules/client.js");
_jsModule ??= await runtime.LoadModuleByName("client");
_interop ??= DotNetObjectReference.Create(this);
await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData));

Expand Down