Skip to content

Commit

Permalink
Fix server behavior for callback
Browse files Browse the repository at this point in the history
  • Loading branch information
sheelc committed Jul 27, 2017
1 parent 784496e commit 79ec2b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"spot/spotify"
)

func setupComplete(action string) bool {
func skipForcedSetup(action string) bool {
return spotify.IsDataSet(spotify.ClientId) &&
spotify.IsDataSet(spotify.ClientSecret) &&
(spotify.IsDataSet(spotify.Token) || action == "auth")
(action == "server" || (spotify.IsDataSet(spotify.Token) || action == "auth"))
}

func main() {
Expand All @@ -24,7 +24,7 @@ func main() {

args := flag.Args()

if !setupComplete(*actionPtr) {
if !skipForcedSetup(*actionPtr) {
err := setup.Creds(args)
if err != nil {
log.Fatal(err)
Expand Down
15 changes: 11 additions & 4 deletions setup/setup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package setup

import (
"fmt"
"io"
"net/http"
"os"
Expand All @@ -19,9 +18,12 @@ func LaunchAuth() error {

url := auth.AuthURL("state")

workflowData := os.Getenv("alfred_workflow_data")
daemon := exec.Command("/bin/bash", "-c", fmt.Sprintf("alfred_workflow_data=%s ./spot --action=server & last_pid=$!; sleep 600; kill -9 $last_pid", workflowData))
daemon.Start()
daemon := exec.Command("./spot", "--action=server")
daemon.Env = os.Environ()
err = daemon.Start()
if err != nil {
return err
}

time.Sleep(1 * time.Second)

Expand Down Expand Up @@ -98,6 +100,11 @@ func Creds(args []string) error {
}

func Server() error {
go func() {
time.Sleep(5 * time.Minute)
os.Exit(0)
}()

http.HandleFunc("/callback", callbackHandler)
return http.ListenAndServe(":11075", nil)
}
Expand Down

0 comments on commit 79ec2b9

Please sign in to comment.