[hammerspoon] little firefox
diff --git a/.hammerspoon/init.fnl b/.hammerspoon/init.fnl
index 08185d0c..b67f1b92 100644
--- a/.hammerspoon/init.fnl
+++ b/.hammerspoon/init.fnl
@@ -15,9 +15,10 @@
(local {: mash : smash : modal-bind} (require :hotkey))
(local {: chomp : paste : replace-selection : run} (require :utils))
+(local little-ff (require :little-ff))
;; debugging
-; (hotkey.bind mash "d" #(hs.notify.show (: (hs.window.frontmostWindow) :title) "" ""))
+; (hotkey.bind mash :d #(little-ff.open "https://google.com"))
;; ⌘⌥V - defeat paste blocking
(hotkey.bind [:cmd :alt] :v #(eventtap.keyStrokes (pasteboard.getContents)))
@@ -84,7 +85,7 @@
["^https://(.*%.?)bulletin.com/?" handlers.safari]
["^https://(.*%.?)store.apple.com/?" handlers.safari]
["^https://(.*%.?)goodluckbread.com/?" handlers.safari]
- ["^https://accounts.google.com/?" handlers.arc]
+ ; ["^https://accounts.google.com/?" handlers.arc]
["^https://(.*%.?)fidelityinvestments.com/?"
handlers.safari]
["^https://mychartwa.providence.org/?" handlers.safari]
@@ -101,10 +102,13 @@
"https://sci-hub.st/%1"]]]
(Install:andUse :URLDispatcher {:config {:url_patterns url-patterns
:url_redir_decoders url-redir-decoders
- :default_handler handlers.firefox-dev
+ :default_handler little-ff.open
:set_system_handler true}
:start true}))
+; Reopen what's in Little Firefox in the main window
+(hotkey.bind mash :o little-ff.rehome)
+
(Install:andUse :ReloadConfiguration {:start true})
;; Local overrides
diff --git a/.hammerspoon/little-ff.fnl b/.hammerspoon/little-ff.fnl
new file mode 100644
index 00000000..f0a07d73
--- /dev/null
+++ b/.hammerspoon/little-ff.fnl
@@ -0,0 +1,69 @@
+(local log (hs.logger.new :init :info))
+
+(local ff-bin
+ "/Applications/Firefox\\ Developer\\ Edition.app/Contents/MacOS/firefox")
+
+(local ff-bundle-id :org.mozilla.firefoxdeveloperedition)
+
+(λ is-ff-focused []
+ (let [win (hs.window.focusedWindow)
+ bundle-id (-> win
+ (: :application)
+ (: :bundleID))]
+ (if (= bundle-id ff-bundle-id)
+ win)))
+
+(λ check-ff [cb]
+ (let [win (is-ff-focused)]
+ (if win (cb win) (log:w "Firefox not focused"))))
+
+; https://github.com/Hammerspoon/hammerspoon/issues/3224#issuecomment-1294359070
+(λ with-ax-hotfix [app cb]
+ (let [ax-app (hs.axuielement.applicationElement app)
+ prev-val ax-app.AXEnhancedUserInterface]
+ (set ax-app.AXEnhancedUserInterface false)
+ (cb)
+ (set ax-app.AXEnhancedUserInterface prev-val)))
+
+(λ resize-little-ff []
+ (check-ff (fn [win]
+ (with-ax-hotfix (win:application)
+ #(win:moveToUnit "[20,10,80,90]"))
+ ;; hide sidebar
+ (hs.eventtap.keyStroke [:ctrl] :z))))
+
+(λ wait-for-little-ff [cb]
+ (let [timer (hs.timer.waitUntil is-ff-focused cb 0.05)]
+ (hs.timer.doAfter 1 #(timer:stop))))
+
+(λ open [url]
+ (hs.execute (table.concat [ff-bin :--new-window url] " "))
+ (wait-for-little-ff resize-little-ff))
+
+(λ rehome []
+ (let [win (is-ff-focused)
+ num-windows (-?> win
+ (: :application)
+ (: :allWindows)
+ (length))]
+ (when (< 1 num-windows)
+ (hs.eventtap.keyStroke [] :escape)
+ (hs.eventtap.keyStrokes :yy)
+ (hs.pasteboard.callbackWhenChanged #(do
+ (win:close)
+ (hs.eventtap.keyStroke [:shift] :p)
+ ;; TODO figure out how to move the tab to
+ ;; the back - this doesn't seem to work,
+ ;; maybe create a custom tridactyl bind?
+ ;;
+ ;; (hs.eventtap.keyStroke [] :escape)
+ ;; (hs.eventtap.keyStrokes ":tabmove $")
+ ;; (hs.eventtap.keyStroke [] :enter)
+ ;;
+ ;; TODO figure out how to focus the main
+ ;; ff window - aerospace doesn't seem to
+ ;; handle the programmatic closing of the
+ ;; little ff window all that well
+ )))))
+
+{: open : rehome}