hoist default handlers

pull/2/head
Alpha Chen 2 years ago
parent 2177a43827
commit c4873ec8b0
No known key found for this signature in database

@ -28,6 +28,11 @@
(fn open-with [app] (fn open-with [app]
(partial open-url app)) (partial open-url app))
(local default-handlers
[["^https://.*%.?zoom.us/j/%d+" (open-with :zoom)]
["^https://doi.org/"
#(open-with :default (.. "https://sci-hub.st/" $1))]])
(fn url->handler [url] (fn url->handler [url]
(accumulate [acc nil _ [pat handler] (ipairs handlers) &until acc] (accumulate [acc nil _ [pat handler] (ipairs handlers) &until acc]
(if (url:find pat) #(handler url) nil))) (if (url:find pat) #(handler url) nil)))
@ -37,12 +42,9 @@
(handler))) (handler)))
(fn setup [{:bundle-ids extra-bundle-ids :handlers extra-handlers}] (fn setup [{:bundle-ids extra-bundle-ids :handlers extra-handlers}]
(let [default-handlers [["^https://.*%.?zoom.us/j/%d+" (open-with :zoom)] (each [k v (pairs (or extra-bundle-ids {}))]
["^https://doi.org/" (tset bundle-ids k v))
#(open-url :default (.. "https://sci-hub.st/" $1))]]] (set handlers (hs.fnutils.concat extra-handlers default-handlers)))
(each [k v (pairs (or extra-bundle-ids {}))]
(tset bundle-ids k v))
(set handlers (hs.fnutils.concat extra-handlers default-handlers))))
(fn start [] (fn start []
(set hs.urlevent.httpCallback (set hs.urlevent.httpCallback

Loading…
Cancel
Save