|
8 | 8 | [reitit.frontend.easy :as rfe] |
9 | 9 | [reitit.frontend.controllers :as rfc] |
10 | 10 | [cljs.core.async :refer [go <!]] |
11 | | - [cljs.core.async.interop :refer-macros [<p!]] |
12 | | - [re-pressed.core :as rp]) |
| 11 | + [cljs.core.async.interop :refer-macros [<p!]]) |
13 | 12 | (:require ["spotify-web-api-js" :as SpotifyWebApi] |
14 | 13 | [cljs.spec.alpha :as s])) |
15 | 14 |
|
|
95 | 94 |
|
96 | 95 | ;; Initialization ---------------------------------------- |
97 | 96 |
|
98 | | -(def space-key-code 32) |
99 | | -(def p-key-code 80) |
100 | | -(def enter-key-code 13) |
101 | | -(def mac-enter-key-code 3) |
102 | | -(def left-key-code 37) |
103 | | -(def right-key-code 39) |
104 | | -(def up-key-code 38) |
105 | | -(def down-key-code 40) |
106 | | - |
107 | | -(def keypress-looper-step-ms 10) |
108 | | - |
109 | 97 | (rf/reg-event-fx |
110 | 98 | ::initialize-app |
111 | 99 | [inject-store |
|
121 | 109 | init-looper-page (when is-authorized |
122 | 110 | [:dispatch [::initialize-looper-page]])] |
123 | 111 | {:db db |
124 | | - :fx [[:dispatch [::rp/add-keyboard-event-listener "keydown"]] |
125 | | - [:dispatch [::rp/add-keyboard-event-listener "keyup"]] |
126 | | - init-looper-page |
127 | | - [:dispatch [::rp/set-keyup-rules {:event-keys [[[::reset-looper nil] |
128 | | - [{:keyCode left-key-code}] |
129 | | - [{:keyCode right-key-code}] |
130 | | - [{:keyCode up-key-code}] |
131 | | - [{:keyCode down-key-code}]]] |
132 | | - :always-listen-keys [{:keyCode left-key-code} |
133 | | - {:keyCode right-key-code} |
134 | | - {:keyCode up-key-code} |
135 | | - {:keyCode down-key-code}]}]] |
136 | | - [:dispatch [::rp/set-keydown-rules {:event-keys [[[::toggle-play] |
137 | | - [{:keyCode space-key-code}] |
138 | | - [{:keyCode p-key-code}]] |
139 | | - |
140 | | - [[::reset-looper nil] |
141 | | - [{:keyCode enter-key-code}] |
142 | | - [{:keyCode mac-enter-key-code}]] |
143 | | - |
144 | | - [[::attempt-increment-loop-start (- keypress-looper-step-ms)] |
145 | | - [{:keyCode left-key-code}]] |
146 | | - [[::attempt-increment-loop-start keypress-looper-step-ms] |
147 | | - [{:keyCode right-key-code}]] |
148 | | - [[::attempt-increment-loop-end (- keypress-looper-step-ms)] |
149 | | - [{:keyCode down-key-code}]] |
150 | | - [[::attempt-increment-loop-end keypress-looper-step-ms] |
151 | | - [{:keyCode up-key-code}]] |
152 | | - ,] |
153 | | - :always-listen-keys [{:keyCode space-key-code} |
154 | | - {:keyCode p-key-code} |
155 | | - {:keyCode enter-key-code} |
156 | | - {:keyCode mac-enter-key-code} |
157 | | - {:keyCode left-key-code} |
158 | | - {:keyCode right-key-code} |
159 | | - {:keyCode up-key-code} |
160 | | - {:keyCode down-key-code}] |
161 | | - :prevent-default-keys [{:keyCode space-key-code} |
162 | | - {:keyCode p-key-code} |
163 | | - {:keyCode enter-key-code} |
164 | | - {:keyCode mac-enter-key-code} |
165 | | - {:keyCode left-key-code} |
166 | | - {:keyCode right-key-code} |
167 | | - {:keyCode up-key-code} |
168 | | - {:keyCode down-key-code}]}]]]}))) |
| 112 | + :fx [init-looper-page |
| 113 | + [:dispatch [:practaid.hotkeys/register-hotkeys]]]}))) |
169 | 114 |
|
170 | 115 | (rf/reg-event-fx |
171 | 116 | ::reset-app-completely |
|
174 | 119 | check-store-spec-interceptor] |
175 | 120 | (fn [_ _] |
176 | 121 | {:fx [[:store {}] |
177 | | - [::reload-page nil]]})) |
178 | | - |
179 | | - |
180 | | - |
181 | | -;; Routing ----------------------------------------------- |
182 | | - |
183 | | -(rf/reg-event-fx |
184 | | - ::navigate |
185 | | - [check-db-spec-interceptor] |
186 | | - (fn [_cofx [_ route]] |
187 | | - {::navigate! route})) |
| 122 | + [:practaid.routes/reload-page nil]]})) |
188 | 123 |
|
189 | | -(rf/reg-event-db |
190 | | - ::navigated |
191 | | - [check-db-spec-interceptor] |
192 | | - (fn [db [_ new-match]] |
193 | | - (let [old-match (:current-route db) |
194 | | - controllers (rfc/apply-controllers (:controllers old-match) new-match)] |
195 | | - (assoc db :current-route (assoc new-match :controllers controllers))))) |
196 | | - |
197 | | -(rf/reg-fx |
198 | | - ::navigate! |
199 | | - (fn [route] |
200 | | - (rfe/push-state route))) |
201 | | - |
202 | | -;; For foreign-domain routes |
203 | | -(rf/reg-fx |
204 | | - ::assign-url |
205 | | - (fn [url] |
206 | | - (-> js/window |
207 | | - (.-location) |
208 | | - (.assign url)))) |
209 | | - |
210 | | -(rf/reg-fx |
211 | | - ::reload-page |
212 | | - (fn [_] |
213 | | - (.reload js/location))) |
214 | 124 |
|
215 | 125 |
|
216 | 126 |
|
|
344 | 254 | [check-db-spec-interceptor] |
345 | 255 | (fn [_ _] |
346 | 256 | {:fx [ |
347 | | - ;[:dispatch [::navigate :routes/looper]] |
348 | 257 | [:practaid.player/initialize-spotify-sdk nil] |
349 | 258 | ;; TODO: store the outcome ID |
350 | 259 | [::set-interval {:f #(rf/dispatch [::refresh-playback-state]) |
|
0 commit comments