< Summary

Class:Clipboard
Assembly:Clipboard
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Clipboard/Clipboard.cs
Covered lines:17
Uncovered lines:1
Coverable lines:18
Total lines:63
Line coverage:94.4% (17 of 18)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Clipboard(...)0%110100%
Create()0%110100%
WriteText(...)0%6200%
ReadText()0%220100%
OnReadText(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Clipboard/Clipboard.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4
 5public class Clipboard : IClipboard
 6{
 6677    private readonly Queue<Promise<string>> promises = new Queue<Promise<string>>();
 8    private readonly IClipboardHandler handler = null;
 9
 10    /// <summary>
 11    /// Create a platform specific instance of Clipboard
 12    /// </summary>
 13    /// <returns>Clipboard instance</returns>
 14    public static Clipboard Create()
 15    {
 16#if UNITY_WEBGL && !UNITY_EDITOR
 17        return new Clipboard(ClipboardWebGL.i);
 18#else
 66619        return new Clipboard(new ClipboardStandalone());
 20#endif
 21    }
 22
 23    /// <summary>
 24    /// Push a string value to the clipboard
 25    /// </summary>
 26    /// <param name="text">string to store</param>
 027    public void WriteText(string text) { handler?.RequestWriteText(text); }
 28
 29    /// <summary>
 30    /// Request the string stored at the clipboard
 31    /// </summary>
 32    /// <returns>Promise of the string value stored at clipboard</returns>
 33    [Obsolete("Firefox not supported")]
 34    public Promise<string> ReadText()
 35    {
 236        Promise<string> promise = new Promise<string>();
 237        promises.Enqueue(promise);
 238        handler?.RequestGetText();
 239        return promise;
 40    }
 41
 66742    public Clipboard(IClipboardHandler handler)
 43    {
 66744        this.handler = handler;
 66745        handler.Initialize(OnReadText);
 66746    }
 47
 48    private void OnReadText(string text, bool error)
 49    {
 450        while (promises.Count > 0)
 51        {
 252            var promise = promises.Dequeue();
 253            if (error)
 54            {
 155                promise.Reject(text);
 156            }
 57            else
 58            {
 159                promise.Resolve(text);
 60            }
 61        }
 262    }
 63}