예제 #1
0
 internal Gamepad(JSInvoker jsInvoker, string id, int index, bool connected)
 {
     this.JSInvoker  = jsInvoker;
     this.Id         = id;
     this.Index      = index;
     this._Connected = connected;
 }
예제 #2
0
        private async ValueTask <JSInvoker> GetJSInvokerAsync()
        {
            if (this.JSInvoker != null)
            {
                return(this.JSInvoker);
            }

            await this.Syncer.WaitAsync();

            try
            {
                if (this.JSInvoker != null)
                {
                    return(this.JSInvoker);
                }

                var version = this.GetVersionText();
#if ENABLE_JSMODULE
                if (!this.Options.DisableClientScriptAutoInjection)
                {
                    var scriptPath = $"./_content/Toolbelt.Blazor.Gamepad/script.module.min.js?v={version}";
                    this.JSModule = await this.JSRuntime.InvokeAsync <IJSObjectReference>("import", scriptPath);

                    this.JSInvoker = new JSInvoker(this.JSRuntime, this.JSModule);
                }
                else
                {
                    try { await this.JSRuntime.InvokeVoidAsync("Toolbelt.Blazor.Gamepad.ready"); } catch { }
                    this.JSInvoker = new JSInvoker(this.JSRuntime, null);
                }
#else
                if (!this.Options.DisableClientScriptAutoInjection)
                {
                    const string scriptPath = "_content/Toolbelt.Blazor.Gamepad/script.min.js";
                    await this.JSRuntime.InvokeVoidAsync("eval", "new Promise(r=>((d,t,s,v)=>(h=>h.querySelector(t+`[src^=\"${s}\"]`)?r():(e=>(e.src=(s+v),e.onload=r,h.appendChild(e)))(d.createElement(t)))(d.head))(document,'script','" + scriptPath + "','?v=" + version + "'))");
                }
                try { await this.JSRuntime.InvokeVoidAsync("Toolbelt.Blazor.Gamepad.ready"); } catch { }
                this.JSInvoker = this.JSRuntime;
#endif
            }
            catch (Exception) { }
            finally { this.Syncer.Release(); }

            return(this.JSInvoker);
        }
 public ClientStorageService(Microsoft.JSInterop.IJSRuntime JSRuntimeContext)
 {
     this.JSRuntime          = JSRuntimeContext;
     this.JSInProcessRuntime = JSRuntimeContext as Microsoft.JSInterop.IJSInProcessRuntime;
 }
예제 #4
0
 /// <summary>
 /// Should this be called in the property set of the model?
 /// </summary>
 /// <param name="jSRuntime"></param>
 /// <param name="categories"></param>
 /// <returns></returns>
 public static void SetCategories(this Microsoft.JSInterop.IJSRuntime jSRuntime, string[] categories)
 {
     jSRuntime.InvokeAsync <string>("SetCategories", new object[] { categories });
 }
예제 #5
0
 public static async Task <string> ConfirmAsync(this Microsoft.JSInterop.IJSRuntime jSRuntime, string message)
 {
     return(await jSRuntime.InvokeAsync <string>("Confirm", new object[] { message }));
 }
예제 #6
0
 public DocumentService(HttpClient httpClient, IJSRuntime js)
 {
     this.httpClient = httpClient;
     this.JS         = js;
 }
예제 #7
0
 public ExampleJsInterop(Microsoft.JSInterop.IJSRuntime jsRuntime)
 {
     moduleTask =
         new(() => jsRuntime.InvokeAsync <Microsoft.JSInterop.IJSObjectReference>
                 ("import", "./_content/Dtx.Razor/exampleJsInterop.js").AsTask());
 }
예제 #8
0
 public RenderingContext(ElementReference refCanv, IJSRuntime js)
 {
     Canvas     = refCanv;
     _jsRuntime = js;
 }
예제 #9
0
 public async static Task <bool> Confirm(this Microsoft.JSInterop.IJSRuntime js, string titulo, string mensaje, TipoMensajeSweetAlert tipoMensajeSweetAlert)
 {
     return(await js.InvokeAsync <bool>("CustomConfirm", titulo, mensaje, tipoMensajeSweetAlert.ToString()));
 }
예제 #10
0
 public static Task MostrarMensaje(this Microsoft.JSInterop.IJSRuntime js, string titulo, string mensaje, TipoMensajeSweetAlert tipoMensajeSweetAlert)
 {
     return(js.InvokeAsync <object>("Swal.fire", titulo, mensaje, tipoMensajeSweetAlert.ToString()));
 }
예제 #11
0
 public static Task MostrarMensaje(this Microsoft.JSInterop.IJSRuntime js, string mensaje)
 {
     return(js.InvokeAsync <object>("Swal.fire", mensaje));
 }
예제 #12
0
 public static Task GuadarComo(this Microsoft.JSInterop.IJSRuntime js, string nombreArchivo, byte[] archivo)
 {
     return(js.InvokeAsync <object>("saveAsFile",
                                    nombreArchivo,
                                    Convert.ToBase64String(archivo)));
 }