Example #1
0
 /// <summary>
 /// queues a function to be called during a browser's idle periods. This enables developers to perform background and low priority work on the main event loop, without impacting latency-critical events such as animation and input response.
 /// </summary>
 /// <param name="callback">ells the browser that you wish to perform an animation and requests that the browser calls a specified function to update an animation before the next repaint. The method takes a callback as an argument to be invoked before the repaint.</param>
 /// <param name="options">Contains optional configuration parameters. Currently only one property is defined : timeout. If timeout is specified and has a positive value, and the callback has not already been called by the time timeout milliseconds have passed, the callback will be called during the next idle period, even if doing so risks causing a negative performance impact.
 /// </param>
 /// <returns>The request ID, can be used for cancelling it</returns>
 public async ValueTask <int> RequestIdleCallback(Func <IdleDeadline, ValueTask> callback,
                                                  RequestIdleCallbackOptions options = null)
 {
     return(await JsRuntime.InvokeInstanceMethod <int>(JsObjectRef, "requestIdleCallback",
                                                       CallBackInteropWrapper.Create <JsRuntimeObjectRef>(async jsRef =>
     {
         var idleDeadline = await JsRuntime.GetInstanceContent <IdleDeadline>(jsRef, true);
         idleDeadline.SetJsRuntime(JsRuntime, jsRef);
         await callback.Invoke(idleDeadline);
     }, getJsObjectRef: true), options));
 }
Example #2
0
        /// <summary>
        /// Lets web sites register their ability to open or handle particular URL schemes (aka protocols).
        ///
        /// For example, this API lets webmail sites open mailto: URLs, or VoIP sites open tel: URLs.
        /// </summary>
        /// <param name="protocol">A string containing the protocol the site wishes to handle. For example, you can register to handle SMS text message links by passing the "sms" scheme.</param>
        /// <param name="urlPattern">A string containing the URL of the handler. This URL must include %s, as a placeholder that will be replaced with the escaped URL to be handled.</param>
        /// <param name="title">A human-readable title string for the handler. This will be displayed to the user, such as prompting “Allow this site to handle [scheme] links?” or listing registered handlers in the browser’s settings.</param>
        /// <returns></returns>
#pragma warning disable CA1054
        public async ValueTask RegisterProtocolHandler(string protocol, string urlPattern, string title)
#pragma warning restore CA1054
        {
            if (string.IsNullOrEmpty(protocol))
            {
                throw new ArgumentNullException(nameof(protocol));
            }

            if (string.IsNullOrEmpty(urlPattern))
            {
                throw new ArgumentNullException(nameof(urlPattern));
            }

            if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException(nameof(title));
            }

            if (await JsRuntime.HasProperty(JsObjectRef, "registerProtocolHandler").ConfigureAwait(false))
            {
                await JsRuntime.InvokeInstanceMethod(JsObjectRef, "registerProtocolHandler", protocol, urlPattern,
                                                     title).ConfigureAwait(false);
            }
        }
Example #3
0
 /// <summary>
 /// Returns a DOMHighResTimeStamp, which is a floating-point value providing an estimate of the number of milliseconds remaining in the current idle period. If the idle period is over, the value is 0. Your callback can call this repeatedly to see if there's enough time left to do more work before returning.
 /// </summary>
 /// <returns></returns>
 public async ValueTask <TimeSpan> TimeRemaining()
 {
     return(TimeSpan.FromMilliseconds(
                await JsRuntime.InvokeInstanceMethod <double>(JsObjectRef, "timeRemaining").ConfigureAwait(false)));
 }
Example #4
0
 public async ValueTask <MediaTrackSettings> GetSettings()
 {
     return(await JsRuntime.InvokeInstanceMethod <MediaTrackSettings>(JsObjectRef, "getSettings")
            .ConfigureAwait(false));
 }
Example #5
0
 /// <summary>
 /// Returns false if the browser enables java
 /// </summary>
 /// <returns></returns>
 public async ValueTask <bool> JavaEnabled()
 {
     return(await JsRuntime.InvokeInstanceMethod <bool>(JsObjectRef, "javaEnabled").ConfigureAwait(false));
 }
Example #6
0
 /// <summary>
 /// Invokes the native sharing mechanism of the device.
 /// Use CanShare to check if this is allowed
 /// </summary>
 /// <returns></returns>
 public async ValueTask Share(ShareData shareData)
 {
     await JsRuntime.InvokeInstanceMethod <bool>(JsObjectRef, "share", shareData).ConfigureAwait(false);
 }
Example #7
0
 /// <summary>
 ///  stops further resource loading in the current browsing context, equivalent to the stop button in the browser.
 /// </summary>
 /// <returns></returns>
 public async ValueTask Stop()
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "stop");
 }
Example #8
0
 /// <summary>
 /// scrolls the document in the window by the given amount.
 /// </summary>
 /// <param name="xCoord">the pixel along the horizontal axis of the document that you want displayed in the upper left.</param>
 /// <param name="yCoord">the pixel along the vertical axis of the document that you want displayed in the upper left.</param>
 /// <returns></returns>
 public async ValueTask ScrollBy(int xCoord, int yCoord)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "scrollBy", xCoord, yCoord);
 }
Example #9
0
 /// <summary>
 /// moves the current window to the specified coordinates.
 /// </summary>
 /// <param name="x">the horizontal coordinate to be moved to.</param>
 /// <param name="y">the vertical coordinate to be moved to.</param>
 /// <returns></returns>
 public async ValueTask MoveTo(int x, int y)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "moveTo", x, y);
 }
Example #10
0
 /// <summary>
 /// moves the current window by a specified amount.
 /// </summary>
 /// <param name="deltaX">the amount of pixels to move the window horizontally. Positive values are to the right, while negative values are to the left.</param>
 /// <param name="deltaY">the amount of pixels to move the window vertically. Positive values are down, while negative values are up.</param>
 /// <returns></returns>
 public async ValueTask MoveBy(int deltaX, int deltaY)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "moveBy", deltaX, deltaY);
 }
Example #11
0
 /// <summary>
 /// Makes a request to bring the window to the front. It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.
 /// </summary>
 /// <returns></returns>
 public async ValueTask Focus()
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "focus");
 }
Example #12
0
 /// <summary>
 /// The Window.confirm() method displays a modal dialog with an optional message and two buttons: OK and Cancel.
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public async ValueTask <bool> Confirm(string message)
 {
     return(await JsRuntime.InvokeInstanceMethod <bool>(JsObjectRef, "confirm", message));
 }
Example #13
0
 /// <summary>
 /// Closes the current window.
 /// </summary>
 /// <returns></returns>
 public async ValueTask Close()
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "close");
 }
Example #14
0
 /// <summary>
 /// Shifts focus away from the window.
 /// </summary>
 /// <returns></returns>
 public async ValueTask Blur()
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "blur");
 }
Example #15
0
 /// <summary>
 /// A string you want to display in the alert dialog
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public async ValueTask Alert(string message)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "alert", message);
 }
Example #16
0
 /// <summary>
 ///  resizes the current window by a specified amount.
 /// </summary>
 /// <param name="xDelta">the number of pixels to grow the window horizontally.</param>
 /// <param name="yDelta"> the number of pixels to grow the window vertically.</param>
 /// <returns></returns>
 public async ValueTask ResizeBy(int xDelta, int yDelta)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "resizeBy", xDelta, yDelta);
 }
Example #17
0
 /// <summary>
 /// dynamically resizes the window.
 /// </summary>
 /// <param name="width">An integer representing the new outerWidth in pixels (including scroll bars, title bars, etc).</param>
 /// <param name="height">An integer value representing the new outerHeight in pixels (including scroll bars, title bars, etc).</param>
 /// <returns></returns>
 public async ValueTask ResizeTo(int width, int height)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "resizeTo", width, height);
 }
Example #18
0
 /// <summary>
 /// Safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
 /// </summary>
 /// <param name="message">The object that will be send to the other window </param>
 /// <param name="targetOrigin">Specifies what the origin of targetWindow must be for the event to be dispatched, either as the literal string "*" (indicating no preference) or as a URI. If at the time the event is scheduled to be dispatched the scheme, hostname, or port of targetWindow's document does not match that provided in targetOrigin, the event will not be dispatched; only if all three match will the event be dispatched.  </param>
 /// <returns></returns>
 public async ValueTask PostMessage(object message, string targetOrigin)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "postMessage", message, targetOrigin);
 }
Example #19
0
 /// <summary>
 /// scrolls the document in the window by the given amount.
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public async ValueTask ScrollBy(ScrollToOptions options)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "scrollBy", options);
 }
Example #20
0
 /// <summary>
 /// Opens the Print Dialog to print the current document.
 /// </summary>
 /// <returns></returns>
 public async ValueTask Print()
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "print");
 }
Example #21
0
 /// <summary>
 /// Returns true if a call to Share() would succeed.
 /// Returns false if it would fail or sharing is not supported
 /// </summary>
 /// <returns></returns>
 public async ValueTask <bool> CanShare(ShareData shareData)
 {
     return(await JsRuntime.HasProperty(JsObjectRef, "canShare").ConfigureAwait(false) &&
            await JsRuntime.InvokeInstanceMethod <bool>(JsObjectRef, "canShare", shareData).ConfigureAwait(false));
 }
Example #22
0
 /// <summary>
 /// displays a dialog with an optional message prompting the user to input some text.
 /// </summary>
 /// <param name="message">A string of text to display to the user. Can be omitted if there is nothing to show in the prompt window.</param>
 /// <param name="defaultValue">A string containing the default value displayed in the text input field. </param>
 /// <returns></returns>
 public async ValueTask <string> Prompt(string message, string defaultValue = null)
 {
     return(await JsRuntime.InvokeInstanceMethod <string>(JsObjectRef, "prompt", message, defaultValue));
 }
Example #23
0
 /// <summary>
 /// Sends a small amount of data over HTTP to a web server. Returns true if the method is supported and succeeds
 ///
 /// This method is for analytics and diagnostics that send data to a server before the document is unloaded, where sending the data any sooner may miss some possible data collection. For example, which link the user clicked before navigating away and unloading the page.
 /// Ensuring that data has been sent during the unloading of a document has traditionally been difficult, because user agents typically ignore asynchronous XMLHttpRequests made in an unload handler.
 /// See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
 /// </summary>
 /// <param name="url"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public async ValueTask <bool> SendBeacon(Uri url, object data)
 {
     return(await JsRuntime.HasProperty(JsObjectRef, "sendBeacon").ConfigureAwait(false) &&
            await JsRuntime.InvokeInstanceMethod <bool>(JsObjectRef, "sendBeacon", url, data).ConfigureAwait(false));
 }
Example #24
0
 /// <summary>
 /// Tells the browser that you wish to perform an animation and requests that the browser calls a specified function to update an animation before the next repaint. The method takes a callback as an argument to be invoked before the repaint.
 /// </summary>
 /// <param name="callback">ells the browser that you wish to perform an animation and requests that the browser calls a specified function to update an animation before the next repaint. The method takes a callback as an argument to be invoked before the repaint.</param>
 /// <returns>The request ID, can be used for cancelling it</returns>
 public async ValueTask <int> RequestAnimationFrame(Func <double, ValueTask> callback)
 {
     return(await JsRuntime.InvokeInstanceMethod <int>(JsObjectRef, "requestAnimationFrame",
                                                       CallBackInteropWrapper.Create(callback)));
 }
Example #25
0
 /// <summary>
 /// Pulses the vibration hardware on the device, if such hardware exists. If the device doesn't support vibration, this method has no effect. If a vibration pattern is already in progress when this method is called, the previous pattern is halted and the new one begins instead.
 /// </summary>
 /// <param name="pattern">Each value indicates a number of milliseconds to vibrate or pause, in alternation. An array of values to alternately vibrate, pause, then vibrate again.</param>
 /// <returns></returns>
 public async ValueTask Vibrate(IEnumerable <TimeSpan> pattern)
 {
     await JsRuntime.InvokeInstanceMethod <bool>(JsObjectRef, "vibrate",
                                                 pattern.Select(t => t.TotalMilliseconds).ToArray()).ConfigureAwait(false);
 }
Example #26
0
 /// <summary>
 /// cancels an animation frame request previously scheduled through a call to RequestAnimationFrame().
 /// </summary>
 /// <param name="id">Id returned by RequestAnimationFrame</param>
 /// <returns></returns>
 public async ValueTask CancelAnimationFrame(int id)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "cancelAnimationFrame", id);
 }
Example #27
0
 public async ValueTask Stop()
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "stop").ConfigureAwait(false);
 }
Example #28
0
 /// <summary>
 /// cancels a callback previously scheduled with RequestIdleCallback()
 /// </summary>
 /// <param name="id">Id returned by RequestIdleCallback</param>
 /// <returns></returns>
 public async ValueTask CancelIdleCallback(int id)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "cancelIdleCallback", id);
 }
Example #29
0
 public async ValueTask <MediaTrackCapabilities> GetCapabilities()
 {
     return(await JsRuntime.InvokeInstanceMethod <MediaTrackCapabilities>(JsObjectRef, "getCapabilities")
            .ConfigureAwait(false));
 }
Example #30
0
 /// <summary>
 /// scrolls the window to a particular place in the document.
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public async ValueTask Scroll(ScrollToOptions options)
 {
     await JsRuntime.InvokeInstanceMethod(JsObjectRef, "scroll", options).ConfigureAwait(false);
 }