(ns lt.objs.notifos
  (:require [lt.object :as object]
            [lt.objs.statusbar :as statusbar]
            [lt.objs.command :as cmd]
            [lt.util.js :refer [wait]]
            [crate.binding :refer [map-bound bound deref?]])
  (:require-macros [lt.macros :refer [behavior defui]]))

(def standard-timeout 10000)

(defn working [msg]
  (when msg
    (set-msg! msg))
  (statusbar/loader-inc))

(defn done-working
  ([]
   (statusbar/loader-dec))
  ([msg]
   (set-msg! msg)
   (statusbar/loader-dec)))

(defn msg* [m & [opts]]
  (let [m (if (string? m)
            m
            (pr-str m))]
    (object/merge! statusbar/statusbar-loader (merge {:message m :class ""} opts))))

(defn set-msg! [msg opts]
  (msg* msg opts)
  (js/clearTimeout cur-timeout)
  (set! cur-timeout (wait standard-timeout #(msg* ""))))

(cmd/command {:command :reset-working
              :desc "Statusbar: Reset working indicator"
              :exec (fn []
                      (statusbar/loader-set 0)
                      )})

(ns lt.objs.notifos
  (:require [lt.object :as object]
            [lt.objs.statusbar :as statusbar]
            [lt.objs.command :as cmd]
            [lt.util.js :refer [wait]]
            [crate.binding :refer [map-bound bound deref?]])
  (:require-macros [lt.macros :refer [behavior defui]]))

(def standard-timeout 10000)

(defn working [msg]
  (when msg
    (set-msg! msg))
  (statusbar/loader-inc))

(defn done-working
  ([]
   (statusbar/loader-dec))
  ([msg]
   (set-msg! msg)
   (statusbar/loader-dec)))

(defn msg* [m & [opts]]
  (let [m (if (string? m)
            m
            (pr-str m))]
    (object/merge! statusbar/statusbar-loader (merge {:message m :class ""} opts))))

(defn set-msg!
  ([msg]
   (msg* msg)
   (js/clearTimeout cur-timeout)
   (set! cur-timeout (wait standard-timeout #(msg* ""))))
  ([msg opts]
   (msg* msg opts)
   (js/clearTimeout cur-timeout)
   (set! cur-timeout (wait (or (:timeout opts)
                               standard-timeout) #(msg* "")))))

(cmd/command {:command :reset-working
              :desc "Statusbar: Reset working indicator"
              :exec (fn []
                      (statusbar/loader-set 0)
                      )})

Extend set-msg! with custom timeout
Extend set-msg! with custom timeout

The function notifos/set-msg! accepts a :timeout key/value pair in the opts map
to set a custom timeout.

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