/// <summary> /// Updates the web view with the current sketch data /// </summary> /// <returns>an async task</returns> public async Task UpdateWebViewAsync() { if (!_navigated) { return; } var sketchData = App.GetSketchData(); if (sketchData == null) { return; } await Task.Run(delegate { var base64 = InkRenderer.RenderImage(sketchData.Width, sketchData.Height, sketchData.InkStrokes, sketchData.BackgroundColor, 1024); var script = $"imageUpdated('{base64}');"; if (Dispatcher == null) { return; } Dispatcher.BeginInvokeOnMainThread(async delegate { try { if (Preview == null) { return; } await Preview.EvaluateJavaScriptAsync(script).ConfigureAwait(false); // There is a limit on the length of strings for the Preview.Eval() method. } catch (Exception e) { var properties = new Dictionary <string, string> { ["ScriptLength"] = script.Length.ToString(CultureInfo.InvariantCulture) }; Crashes.TrackError(e, properties); } }); GC.Collect(); }).ConfigureAwait(false); }
/// <summary> /// Gets the current zoom level /// </summary> /// <returns>an async task with the zoom level</returns> public async Task <double> GetZoomLevelAsync() { var value = await Preview.EvaluateJavaScriptAsync("getZoomLevel();").ConfigureAwait(true); return(double.Parse(value, CultureInfo.InvariantCulture)); }