headless flag usage tweak

pull/5/head
Daniel Lauzon 5 years ago
parent 727e7e4eb9
commit 0cb5122e33

@ -61,6 +61,10 @@ func main() {
log.Print("-start only allowed in dev mode") log.Print("-start only allowed in dev mode")
return return
} }
if !*devFlag && *headlessFlag {
log.Print("-headless only allowed in dev mode")
return
}
s, err := NewSession() s, err := NewSession()
if err != nil { if err != nil {
log.Print(err) log.Print(err)
@ -225,6 +229,9 @@ func (s *Session) login(ctx context.Context) error {
if location == "https://photos.google.com/" { if location == "https://photos.google.com/" {
return nil return nil
} }
if *headlessFlag {
return errors.New("You cannot authenticate in -headless mode")
}
if *verboseFlag { if *verboseFlag {
log.Printf("Not yet authenticated, at: %v", location) log.Printf("Not yet authenticated, at: %v", location)
} }
@ -260,7 +267,6 @@ func (s *Session) firstNav(ctx context.Context) error {
if err := navToEnd(ctx); err != nil { if err := navToEnd(ctx); err != nil {
return err return err
} }
log.Printf("Nav to end- DONE")
if err := navToLast(ctx); err != nil { if err := navToLast(ctx); err != nil {
return err return err
@ -321,11 +327,9 @@ func navToEnd(ctx context.Context) error {
// new page. It then sends the right arrow key event until we've reached the very // new page. It then sends the right arrow key event until we've reached the very
// last item. // last item.
func navToLast(ctx context.Context) error { func navToLast(ctx context.Context) error {
log.Printf("Nav to last- START")
var location, prevLocation string var location, prevLocation string
ready := false ready := false
for { for {
log.Printf("Nav to last...")
chromedp.KeyEvent(kb.ArrowRight).Do(ctx) chromedp.KeyEvent(kb.ArrowRight).Do(ctx)
time.Sleep(tick) time.Sleep(tick)
if !ready { if !ready {
@ -368,7 +372,9 @@ func doRun(filePath string) error {
// navLeft navigates to the next item to the left // navLeft navigates to the next item to the left
func navLeft(ctx context.Context) error { func navLeft(ctx context.Context) error {
chromedp.KeyEvent(kb.ArrowLeft).Do(ctx) chromedp.KeyEvent(kb.ArrowLeft).Do(ctx)
chromedp.WaitReady("body", chromedp.ByQuery) // Could wait for the location to change instead of this Sleep.
time.Sleep(200 * time.Millisecond)
return nil return nil
} }

Loading…
Cancel
Save