diff --git a/main.go b/main.go index 1774e8d..a5dda15 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,8 @@ import ( "log" "net/http" "os" + "os/exec" + "strings" ) var ( @@ -32,6 +34,8 @@ func main() { http.HandleFunc("/", pageIndex) http.HandleFunc("/css/main.css", pageCSS) + http.HandleFunc("/browser/start", actionBrowserStart) + http.HandleFunc("/start", actionStart) http.HandleFunc("/stop/{uuid}", actionStop) http.HandleFunc("/sites", actionSites) @@ -40,6 +44,20 @@ func main() { http.ListenAndServe("[::]:5123", nil) } +func replaceTilde(str string) string {// {{{ + homedir, err := os.UserHomeDir() + if err != nil { + log.Println(err) + return str + } + + if str[0] == '~' { + str = strings.Replace(str, "~", homedir, 1) + } + + return str +}// }}} + func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{ var tmpl *template.Template var err error @@ -76,6 +94,17 @@ func actionSites(w http.ResponseWriter, r *http.Request) { // {{{ w.Write(j) } // }}} +func actionBrowserStart(w http.ResponseWriter, r *http.Request) {// {{{ + body, _ := io.ReadAll(r.Body) + userDataDir := replaceTilde(string(body)) + browser := exec.Command("google-chrome", "--user-data-dir="+string(userDataDir), "--remote-debugging-port=9222") + err := browser.Start() + if err != nil { + log.Println(err) + } else { + go browser.Wait() + } +}// }}} func actionStart(w http.ResponseWriter, r *http.Request) { // {{{ var req struct { URL string @@ -97,7 +126,8 @@ func actionStart(w http.ResponseWriter, r *http.Request) { // {{{ } var site Site - site, err = NewSite(flagWsURL, req.URL, req.Watch) + expandedWatch := replaceTilde(req.Watch) + site, err = NewSite(flagWsURL, req.URL, expandedWatch) if err != nil { log.Println(err) } diff --git a/static/css/main.css b/static/css/main.css index 23014e8..5462b71 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -7,15 +7,20 @@ input { font-size: 1em; } +.browser { + input { + width: 350px; + } +} + .new { - width: 400px; + width: 350px; } .sites { display: grid; grid-template-columns: repeat(3, min-content); grid-gap: 8px 16px; - margin-top: 32px; div { white-space: nowrap; diff --git a/static/html/index.html b/static/html/index.html index 3418ceb..11ac911 100644 --- a/static/html/index.html +++ b/static/html/index.html @@ -7,9 +7,23 @@
- - - +