github.com/kelleygo/clashcore@v1.0.2/rules/common/process.go (about) 1 package common 2 3 import ( 4 "strings" 5 6 C "github.com/kelleygo/clashcore/constant" 7 ) 8 9 type Process struct { 10 *Base 11 adapter string 12 process string 13 nameOnly bool 14 } 15 16 func (ps *Process) RuleType() C.RuleType { 17 if ps.nameOnly { 18 return C.Process 19 } 20 21 return C.ProcessPath 22 } 23 24 func (ps *Process) Match(metadata *C.Metadata) (bool, string) { 25 if ps.nameOnly { 26 return strings.EqualFold(metadata.Process, ps.process), ps.adapter 27 } 28 29 return strings.EqualFold(metadata.ProcessPath, ps.process), ps.adapter 30 } 31 32 func (ps *Process) Adapter() string { 33 return ps.adapter 34 } 35 36 func (ps *Process) Payload() string { 37 return ps.process 38 } 39 40 func (ps *Process) ShouldFindProcess() bool { 41 return true 42 } 43 44 func NewProcess(process string, adapter string, nameOnly bool) (*Process, error) { 45 return &Process{ 46 Base: &Base{}, 47 adapter: adapter, 48 process: process, 49 nameOnly: nameOnly, 50 }, nil 51 }