mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-16 11:37:36 +02:00
acf2f13dcb
* sync with MontFerret/ferret * fix --param handling When params is converted to map it uses strings.Split, which slices a string into all substrings separated by :. * remove impossible conditions nil != nil * delete ineffectual assignments * replace '+= 1' with '++' * remove useless comparison with nil * merge variable declarations * remove bool comparison * fix imports * fix imports * delete unused file * use copy instead of loop * delete unused DummyInterface * remove unnecassary break statements * tidy modules
73 lines
1.1 KiB
Go
73 lines
1.1 KiB
Go
package browser
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type Browser struct {
|
|
cmd *exec.Cmd
|
|
flags Flags
|
|
}
|
|
|
|
func (b *Browser) Flags() Flags {
|
|
return b.flags
|
|
}
|
|
|
|
func (b *Browser) DebuggingAddress() string {
|
|
if !b.Flags().Has("remote-debugging-address") {
|
|
b.Flags().Set("remote-debugging-address", "http://0.0.0.0:9222")
|
|
}
|
|
|
|
value, _ := b.Flags().Get("remote-debugging-address")
|
|
|
|
return value.(string)
|
|
}
|
|
|
|
func (b *Browser) DebuggingPort() int {
|
|
if !b.Flags().Has("remote-debugging-port") {
|
|
b.Flags().Set("remote-debugging-port", 9222)
|
|
}
|
|
|
|
value, _ := b.Flags().Get("remote-debugging-port")
|
|
|
|
return value.(int)
|
|
}
|
|
|
|
func (b *Browser) Close() error {
|
|
var err error
|
|
|
|
if runtime.GOOS != goosWindows {
|
|
err = b.cmd.Process.Signal(os.Interrupt)
|
|
} else {
|
|
err = b.cmd.Process.Kill()
|
|
}
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = b.cmd.Process.Wait()
|
|
|
|
if err != nil {
|
|
return errors.Wrap(err, "error waiting for process exit, result unknown")
|
|
}
|
|
|
|
tmpDir, err := b.flags.GetString("user-data-dir")
|
|
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
err = os.RemoveAll(tmpDir)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|