Exemple #1
0
        private async ValueTask OnIsolationChangeCallback()
        {
            Isolated = await JsRuntime.GetInstanceProperty <bool>(JsObjectRef, "isolated")
                       .ConfigureAwait(false);

            OnIsolationChange?.Invoke(this, EventArgs.Empty);
        }
Exemple #2
0
        /// <summary>
        ///  listen for dispatched messages send by PostMessage
        /// </summary>
        /// <param name="todo"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public async ValueTask <IAsyncDisposable> OnMessage <T>(Func <MessageEvent <T>, ValueTask> todo)
        {
            return(await JsRuntime.AddEventListener(
                       JsObjectRef,
                       "",
                       "message",
                       CallBackInteropWrapper.Create <JsRuntimeObjectRef>(
                           async payload =>
            {
                var eventPayload = new MessageEvent <T>
                {
                    Data = await JsRuntime.GetInstanceProperty <T>(payload, "data").ConfigureAwait(false),
                    Origin = await JsRuntime.GetInstanceProperty <string>(payload, "origin")
                             .ConfigureAwait(false),
                    Source = await JsRuntime.GetInstanceProperty <WindowInterop>(payload, "source",
                                                                                 SerializationSpec).ConfigureAwait(false)
                };
                eventPayload.Source.SetJsRuntime(JsRuntime,
                                                 await JsRuntime.GetInstancePropertyRef(payload, "source").ConfigureAwait(false));

                await todo.Invoke(eventPayload).ConfigureAwait(false);
            },
                           getJsObjectRef: true
                           )).ConfigureAwait(false));
        }
Exemple #3
0
 /// <summary>
 /// dispatched on devices when a user is about to be prompted to "install" a web application. Its associated event may be saved for later and used to prompt the user at a more suitable time.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnBeforeInstallPrompt(
     Func <BeforeInstallPromptEvent, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(
                JsObjectRef, "",
                "beforeinstallprompt",
                CallBackInteropWrapper.Create <JsRuntimeObjectRef>(
                    async jsObjectRef =>
     {
         var beforeInstallPromptEvent = new BeforeInstallPromptEvent
         {
             Platforms = await JsRuntime.GetInstanceProperty <string[]>(jsObjectRef, "platforms")
         };
         beforeInstallPromptEvent.SetJsRuntime(JsRuntime, jsObjectRef);
         await callback.Invoke(beforeInstallPromptEvent);
     },
                    getJsObjectRef: true,
                    serializationSpec: false
                    )
                ));
 }
 /// <summary>
 /// Returns the user choice
 /// </summary>
 /// <returns></returns>
 public async ValueTask <bool> IsAccepted()
 {
     return(await JsRuntime.GetInstanceProperty <string>(JsObjectRef, "userChoice") == "accepted");
 }