(ns lt.objs.platform
  (:require [lt.object :as object]
            [lt.util.dom :as dom])
  (:require-macros [lt.macros :refer [behavior]]))

(def atom-shell true)

(def clipboard (js/require "clipboard"))
(def shell (js/require "shell"))

(defn get-data-path []
  (.getDataPath (.require (js/require "remote") "app")))

(defn normalize [plat]
  (condp = plat
    "win32" :windows
    "linux" :linux
    "darwin" :mac))

(defn open [path]
  (.openItem shell path))

(defn open-url [path]
  (.openExternal shell path))

(defn show-item [path]
  (.showItemInFolder shell path))

(defn copy
  "Copies given text to platform's clipboard"
  [text]
  (.writeText clipboard text))

(defn paste
  "Returns text of last copy to platform's clipboard"
  []
  (.readText clipboard))

(def platform (normalize (.-platform js/process)))

(defn mac? []
  (= platform :mac))

(defn win? []
  (= platform :windows))

(defn linux? []
  (= platform :linux))

(ns lt.objs.platform
  (:require [lt.object :as object]
            [lt.util.dom :as dom])
  (:require-macros [lt.macros :refer [behavior]]))

(def atom-shell true)

(def fs (js/require "fs"))
(def clipboard (js/require "clipboard"))
(def shell (js/require "shell"))

(defn get-data-path []
  (.getDataPath (.require (js/require "remote") "app")))

(defn normalize [plat]
  (condp = plat
    "win32" :windows
    "linux" :linux
    "darwin" :mac))

(defn open-url [path]
  (.openExternal shell path))

(defn open
  "If the given path exists, open it with the desktop's default manner.
  Otherwise, open it as an external protocol e.g. a url."
  [path]
  (if (.existsSync fs path)
    (.openItem shell path)
    (open-url path)))

(defn show-item [path]
  (.showItemInFolder shell path))

(defn copy
  "Copies given text to platform's clipboard"
  [text]
  (.writeText clipboard text))

(defn paste
  "Returns text of last copy to platform's clipboard"
  []
  (.readText clipboard))

(def platform (normalize (.-platform js/process)))

(defn mac? []
  (= platform :mac))

(defn win? []
  (= platform :windows))

(defn linux? []
  (= platform :linux))

Update open to be backwards compatible for urls
Update open to be backwards compatible for urls

A number of plugins rely on platform/open to open urls -
https://github.com/search?p=3&q=objs.platform+open+language%3Aclojure&ref=searchresults&type=Code&utf8=%E2%9C%93.
Also couldn't use files in platform for exists check since that created
a circular dependency

kolya-ay/LightTable,craftybones/LightTable,kausdev/LightTable,craftybones/LightTable,bruno-oliveira/LightTable,EasonYi/LightTable,pkdevbox/LightTable,masptj/LightTable,youprofit/LightTable,Bost/LightTable,kausdev/LightTable,nagyistoce/LightTable,youprofit/LightTable,hiredgunhouse/LightTable,windyuuy/LightTable,brabadu/LightTable,mrwizard82d1/LightTable,fdserr/LightTable,craftybones/LightTable,ashneo76/LightTable,kenny-evitt/LightTable,Bost/LightTable,nagyistoce/LightTable,hiredgunhouse/LightTable,brabadu/LightTable,fdserr/LightTable,ashneo76/LightTable,mpdatx/LightTable,pkdevbox/LightTable,LightTable/LightTable,mpdatx/LightTable,fdserr/LightTable,kolya-ay/LightTable,kausdev/LightTable,LightTable/LightTable,EasonYi/LightTable,rundis/LightTable,sbauer322/LightTable,masptj/LightTable,masptj/LightTable,bruno-oliveira/LightTable,kolya-ay/LightTable,bruno-oliveira/LightTable,kenny-evitt/LightTable,EasonYi/LightTable,Bost/LightTable,kenny-evitt/LightTable,pkdevbox/LightTable,0x90sled/LightTable,youprofit/LightTable,rundis/LightTable,0x90sled/LightTable,LightTable/LightTable,sbauer322/LightTable,sbauer322/LightTable,ashneo76/LightTable,mpdatx/LightTable,mrwizard82d1/LightTable,BenjaminVanRyseghem/LightTable,0x90sled/LightTable,brabadu/LightTable,rundis/LightTable,BenjaminVanRyseghem/LightTable,mrwizard82d1/LightTable,windyuuy/LightTable,hiredgunhouse/LightTable,BenjaminVanRyseghem/LightTable,nagyistoce/LightTable,windyuuy/LightTable