Skip to content

Commit

Permalink
Add mac logic for specifying absolute chrome binary path
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniils Petrovs committed Jul 31, 2023
1 parent 9e71feb commit d3f896d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/atoss_cli/atoss.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

(def update-btn {:css ".z-toolbarbutton:nth-of-type(1)"})
(def date-input {:css ".z-datebox-input"})
(def timepair-table {:css "div.slick-pane.slick-pane-top.slick-pane-left > div.slick-viewport.slick-viewport-top.slick-viewport-left"})
(def time-pair-row {:css "div.slick-row"})
(def add-time-pair-btn {:css "ul.z-menupopup-content > li.z-menuitem > a.z-menuitem-content:first-of-type"})

(defprotocol TimeSheetDay
(fmt-row [day]))
Expand Down Expand Up @@ -75,9 +78,9 @@

(defn setup-driver
"Create a default driver instance to be used for interacting with ATOSS. Headless by default."
([] (setup-driver true))
([headless?]
(let [driver (api/chrome {:headless headless?})]
([] (setup-driver {:headless true}))
([opts]
(let [driver (api/chrome opts)]
(api/set-window-size driver 1200 800)
driver)))

Expand Down
22 changes: 17 additions & 5 deletions src/atoss_cli/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
(:import (java.util Collection))
(:gen-class))


(def mac-chrome-path "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")

(defn -maybe-inject-mac-chrome-path
"Inject the path to the Chrome binary on macOS if the current OS is macOS."
[opts]
(let [os-name (System/getProperty "os.name")]
(if (re-find #"Mac OS X" os-name)
(assoc opts :path-browser mac-chrome-path)
opts)))

(defn log-time
"Log a time pair for a given date."
[{opts :options}]
(let [driver (atoss/setup-driver)
(let [driver (atoss/setup-driver (-maybe-inject-mac-chrome-path {:headless true}))
config (config/load-in)
{date :date} opts
session-opts (merge opts config)]
Expand All @@ -31,17 +42,18 @@
(green "Logged time for date: " date))
(shutdown-agents))

(catch Exception e
(catch Exception e
(-> e
(.getMessage)
(red)
(println))
(.getMessage)
(red)
(println))
(atoss/end driver)))))

(defn web
"Open in web browser."
[]
(let [config (config/load-in)]
(println (System/getenv "PATH"))
(atoss/browse config)))

;; FIXME: very brittle so disabled for now
Expand Down

0 comments on commit d3f896d

Please sign in to comment.