Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
comment useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Dec 5, 2017
1 parent f17da43 commit 9623188
Showing 1 changed file with 53 additions and 62 deletions.
115 changes: 53 additions & 62 deletions uiautomator.go
Original file line number Diff line number Diff line change
@@ -1,64 +1,55 @@
package main

import (
"errors"
"log"
"os"
"os/exec"
"runtime"
"time"
)

type uiautomatorLauncher struct {
running bool
}

func (u *uiautomatorLauncher) Start() error {
if u.running {
return errors.New("uiautomator already started")
}
if runtime.GOOS == "windows" {
u.running = true
return nil
}
go u.safeRun()
return nil
}

func (u *uiautomatorLauncher) IsRunning() bool {
return u.running
}

func (u *uiautomatorLauncher) safeRun() {
u.running = true
retry := 5
for retry > 0 {
retry--
start := time.Now()
if err := u.runUiautomator(); err != nil {
log.Printf("uiautomator quit: %v", err)
}
if time.Since(start) > 1*time.Minute {
retry = 5
}
time.Sleep(2 * time.Second)
}
log.Println("uiautomator can not started")
u.running = false
}

func (u *uiautomatorLauncher) runUiautomator() error {
c := exec.Command("am", "instrument", "-w", "-r",
"-e", "debug", "false",
"-e", "class", "com.github.uiautomator.stub.Stub",
"com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner")
c.Stdout = os.Stdout
c.Stderr = os.Stderr
return c.Run()
}

var uiautomator uiautomatorLauncher

func safeRunUiautomator() error {
return uiautomator.Start()
}
// type uiautomatorLauncher struct {
// running bool
// }

// func (u *uiautomatorLauncher) Start() error {
// if u.running {
// return errors.New("uiautomator already started")
// }
// if runtime.GOOS == "windows" {
// u.running = true
// return nil
// }
// go u.safeRun()
// return nil
// }

// func (u *uiautomatorLauncher) IsRunning() bool {
// return u.running
// }

// func (u *uiautomatorLauncher) safeRun() {
// u.running = true
// retry := 5
// for retry > 0 {
// retry--
// start := time.Now()
// if err := u.runUiautomator(); err != nil {
// log.Printf("uiautomator quit: %v", err)
// }
// if time.Since(start) > 1*time.Minute {
// retry = 5
// }
// time.Sleep(2 * time.Second)
// }
// log.Println("uiautomator can not started")
// u.running = false
// }

// func (u *uiautomatorLauncher) runUiautomator() error {
// c := exec.Command("am", "instrument", "-w", "-r",
// "-e", "debug", "false",
// "-e", "class", "com.github.uiautomator.stub.Stub",
// "com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner")
// c.Stdout = os.Stdout
// c.Stderr = os.Stderr
// return c.Run()
// }

// var uiautomator uiautomatorLauncher

// func safeRunUiautomator() error {
// return uiautomator.Start()
// }

0 comments on commit 9623188

Please sign in to comment.