From 1195777036055d1f8a5efd0462024676b6ebef3d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 23 Mar 2020 15:28:12 +0100 Subject: [PATCH] :tada: Add clipboard related functions to webapi utils. --- frontend/src/uxbox/util/webapi.cljs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/frontend/src/uxbox/util/webapi.cljs b/frontend/src/uxbox/util/webapi.cljs index e079e75e6..29f605e52 100644 --- a/frontend/src/uxbox/util/webapi.cljs +++ b/frontend/src/uxbox/util/webapi.cljs @@ -7,8 +7,10 @@ (ns uxbox.util.webapi "HTML5 web api helpers." (:require + [promesa.core :as p] [beicon.core :as rx] - [cuerdas.core :as str])) + [cuerdas.core :as str] + [uxbox.util.transit :as t])) (defn read-file-as-text [file] @@ -65,4 +67,19 @@ ;; (rx/create on-subscribe))) +(defn write-to-clipboard + [data] + (let [cboard (unchecked-get js/navigator "clipboard")] + (.writeText cboard (uxbox.util.transit/encode data)))) + +(defn- read-from-clipboard + [] + (let [cboard (unchecked-get js/navigator "clipboard")] + (-> (.readText cboard) + (p/then (fn [data] + (try + (t/decode data) + (catch :default e + nil))))))) +