/
flowimpl-headless.go
67 lines (53 loc) · 1.4 KB
/
flowimpl-headless.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"github.com/chromedp/chromedp"
"github.com/jinzhu/copier"
"reflect"
"strings"
)
type FlowImplHeadless FlowImplBase
func (impl *FlowImplHeadless) Type() FlowImplType {
return FlowImplTypeFlag
}
func (impl *FlowImplHeadless) Usage() string {
return impl.Name() + " <true|false> Set headless flag to chromedp, default is true means don't show browser window"
}
func (impl *FlowImplHeadless) Do(args...interface{}) error {
if len(args) == 0 {
return nil
}
opt := args[0].(*chromedp.ExecAllocatorOption)
if len(impl.command.Fields) == 0 {
*opt = chromedp.Flag("headless", true)
}
switch impl.command.Fields[0].ToString() {
case "true":
*opt = chromedp.Flag("headless", true)
case "false":
*opt = chromedp.Flag("headless", false)
}
return nil
}
//go:generate make IMPL_TYPE=FlowImplHeadless gen-impl
func init() {
flowImpl := func() IFlowImpl {
return &FlowImplHeadless{}
}()
registerFlow(flowImpl)
}
func (impl *FlowImplHeadless) Name() string {
interfaceName := reflect.TypeOf(impl).String()
commandName := strings.Split(interfaceName, "FlowImpl")[1]
return strings.ToLower(commandName)
}
func (impl *FlowImplHeadless) SetCommand(command *FlowCommand) {
impl.command = command
}
func (impl *FlowImplHeadless) Command() *FlowCommand {
return impl.command
}
func (impl *FlowImplHeadless) Clone() IFlowImpl {
c := &FlowImplHeadless{}
_ = copier.Copy(c, impl)
return c
}