Skip to content

Commit a825b9d

Browse files
committed
feat: start a new pomodoro every time we clawe-reload
I don't reload often, so this might be a nice boon. I suspect we'll have to be careful about the sometimes-end-pomodoro datas, but i think going loosey goosey on the data will free up more opportunities than holding back on the data at this point. Really this should be a smart-pomo-toggle helper that can get called whenever. One step closer to automagic-pomodoros and 'modes' (in this case, break-vs-working ui modes).
1 parent 599c9e9 commit a825b9d

File tree

6 files changed

+66
-8
lines changed

6 files changed

+66
-8
lines changed

src/api/pomodoros.clj

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
first)]
2323
{:current current :last last}))
2424

25-
(defn start-new []
25+
(defn start-if-break []
2626
(let [current (:current (get-state))]
2727
(if current
2828
(log/warn "Attempted to start-new pomodoro when current exists, doing nothing")
@@ -35,6 +35,21 @@
3535
(notify/notify "Starting new pomodoro")))
3636
(get-state)))
3737

38+
;; TODO write some kind of 'smart-toggle' logic in here
39+
;; e.g. if we're on a break, start the pomorodo
40+
;; e.g. if we're beyond 2x our 'break' time, stop the pomodoro
41+
;; e.g. if we're beyond 4/5x our 'break' time, start another one
42+
(defn start-pomodoro
43+
"Starts a pomodoro regardless of the current state."
44+
[]
45+
(-> {:doctor/type :type/pomodoro
46+
:pomodoro/started-at (dt/now)
47+
:pomodoro/is-current true
48+
:pomodoro/id (random-uuid)}
49+
(db/transact))
50+
(notify/notify "Starting new pomodoro")
51+
(get-state))
52+
3853
(defn end-current []
3954
(let [{:keys [current]} (get-state)]
4055
(when current
@@ -47,10 +62,12 @@
4762

4863
(comment
4964
(get-state)
50-
(start-new)
65+
(start-if-break)
66+
(start-pomodoro)
5167
(end-current))
5268

5369

70+
5471
(defn clean-up-pomodoros []
5572
(->> (db/query '[:find (pull ?e [*])
5673
:where [?e :pomodoro/id _]])

src/clawe/doctor.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
(defn update-screenshots []
2020
(slurp (str (clawe.config/doctor-base-url) "/screenshots/update")))
2121

22+
(defn start-pomodoro []
23+
(slurp (str (clawe.config/doctor-base-url) "/pomodoros/start")))
24+
2225
(defn rebuild-blog
2326
([] (rebuild-blog nil))
2427
([_] (slurp (str (clawe.config/doctor-base-url) "/blog/rebuild"))))

src/clawe/restart.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@
133133
(install-zsh-tab-completion))
134134

135135
;; Doom env refresh - probably a race-case here....
136-
(tmux/fire {:tmux.fire/cmd "doom env"
137-
:tmux.fire/session "dotfiles"
136+
(tmux/fire {:tmux.fire/cmd "doom env"
137+
:tmux.fire/session "dotfiles"
138138
:tmux.fire/directory "~/dotfiles"
139139
})
140140
(emacs/fire "(doom/reload-env)")
141141

142142
(clawe.doctor/update-topbar)
143+
144+
;; TODO move to 'smart-toggle' (or some other name)
145+
(clawe.doctor/start-pomodoro)
146+
143147
(log "Reload complete")
144148

145149
(check-unit-tests)))

src/dates/tick.cljc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,25 @@
186186
(duration-since (parse-time-string "2022-02-26_15:47:52-0500")))
187187

188188
(defn an-x-ago-ms
189-
"Returns duration-ago as milliseconds."
189+
"Returns duration-ago as milliseconds.
190+
NOTE only useful for per-day units, not less than 1 day.
191+
"
190192
[duration]
191193
(-> (t/today)
192194
(t/at (t/midnight))
193195
(t/<< duration)
194196
t/inst
195197
inst-ms))
196198

199+
;; TODO support and update note above
200+
;; (defn an-hour-ago-ms
201+
;; "Returns an-hour-ago as milliseconds."
202+
;; []
203+
;; (an-x-ago-ms (t/new-duration 1 :hours)))
204+
205+
;; (comment
206+
;; (an-hour-ago-ms))
207+
197208
(defn a-week-ago-ms
198209
"Returns a-week-ago as milliseconds."
199210
[]

src/doctor/api.clj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
(string/starts-with? "/api/pomodoros" uri)
2525
(pomodoros/route req)
2626

27+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28+
;; clawe
29+
2730
(= uri "/reload")
2831
(do
2932
(clawe.restart/reload)
@@ -35,6 +38,9 @@
3538
(topbar/push-topbar-metadata)
3639
{:status 200 :body "updated topbar"})
3740

41+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42+
;; screenshots/clips
43+
3844
(= uri "/screenshots/update")
3945
(do
4046
(screenshots/ingest-screenshots)
@@ -45,11 +51,22 @@
4551
(clips/ingest-clips)
4652
{:status 200 :body "updated clips"})
4753

54+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55+
;; pomodoros/todos
56+
57+
(= uri "/pomodoros/start")
58+
(do
59+
(pomodoros/start-pomodoro)
60+
{:status 200 :body "starting new pomodoro"})
61+
4862
(= uri "/todos/update")
4963
(do
5064
(todos/reingest-todos)
5165
{:status 200 :body "updated todos"})
5266

67+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68+
;; blog
69+
5370
(= uri "/blog/rebuild")
5471
(do
5572
;; TODO perhaps this should be non-blocking?
@@ -71,6 +88,9 @@
7188
(blog/restart-systems)
7289
{:status 200 :body "restarted blog systems"})
7390

91+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
92+
;; clawe rofi/mx
93+
7494
(= uri "/clawe-mx")
7595
(do
7696
(clawe.mx/mx)
@@ -91,6 +111,9 @@
91111
(clawe.mx/mx-open)
92112
{:status 200})
93113

114+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
115+
;; clawe toggle
116+
94117
(= uri "/clawe-toggle")
95118
(do
96119
;; TODO handle query params/body

src/doctor/ui/handlers.cljc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@
161161
;; pomodoros
162162
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
163163

164-
(defhandler pomodoro-start-new []
165-
(api.pomodoros/start-new)
164+
(defhandler pomodoro-start-if-break []
165+
(api.pomodoros/start-if-break)
166166
:ok)
167167

168168
(defhandler pomodoro-end-current []
@@ -177,7 +177,7 @@
177177
:action/on-click #(pomodoro-end-current)
178178
:action/icon octicons/stop16}
179179
{:action/label "Start"
180-
:action/on-click #(pomodoro-start-new)
180+
:action/on-click #(pomodoro-start-if-break)
181181
:action/icon octicons/play16})])))
182182

183183
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)