maa

package module
v2.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2025 License: LGPL-3.0 Imports: 12 Imported by: 0

README

LOGO

MaaFramework Golang Binding

license go reference maa framework

English | 简体中文

This is the Go binding for MaaFramework, providing Go developers with a simple and effective way to use MaaFramework's features within their Go applications.

No Cgo required!

Installation

To install the MaaFramework Go binding, run the following command in your terminal:

go get github.com/MaaXYZ/maa-framework-go/v2

In addition, please download the Release package for MaaFramework to get the necessary dynamic library files.

Usage

To use MaaFramework in your Go project, import the package as you would with any other Go package:

import "github.com/MaaXYZ/maa-framework-go/v2"

Then, you can use the functionalities provided by MaaFramework. For detailed usage, refer to the documentation and examples provided in the repository.

Note: Programs built with maa-framework-go rely on the dynamic libraries of MaaFramework. Please ensure one of the following conditions is met:

  1. The program's working directory contains the MaaFramework dynamic libraries.
  2. Environment variables (such as LD_LIBRARY_PATH or PATH) are set to include the path to the dynamic libraries.

Otherwise, the program may not run correctly.

Documentation

Currently, there is not much detailed documentation available. Please refer to the source code and compare it with the interfaces in the original MaaFramework project to understand how to use the bindings. We are actively working on adding more comments and documentation to the source code.

Here are some documents from the maa framework that might help you:

Examples

Quirk start

See quirk-start for details.

Here is a basic example to get you started:

package main

import (
    "fmt"
    "os"

    "github.com/MaaXYZ/maa-framework-go/v2"
)

func main() {
    toolkit := maa.NewToolkit()
    toolkit.ConfigInitOption("./", "{}")
    tasker := maa.NewTasker(nil)
    defer tasker.Destroy()

    device := toolkit.FindAdbDevices()[0]
    ctrl := maa.NewAdbController(
        device.AdbPath,
        device.Address,
        device.ScreencapMethod,
        device.InputMethod,
        device.Config,
        "path/to/MaaAgentBinary",
        nil,
    )
    defer ctrl.Destroy()
    ctrl.PostConnect().Wait()
    tasker.BindController(ctrl)

    res := maa.NewResource(nil)
    defer res.Destroy()
    res.PostBundle("./resource").Wait()
    tasker.BindResource(res)
    if !tasker.Initialized() {
        fmt.Println("Failed to init MAA.")
        os.Exit(1)
    }

    detail := tasker.PostTask("Startup").Wait().GetDetail()
    fmt.Println(detail)
}

Custom Recognition

See custom-recognition for details.

Here is a basic example to implement your custom recognition:

package main

import (
    "fmt"
    "os"

    "github.com/MaaXYZ/maa-framework-go/v2"
)

func main() {
    toolkit := maa.NewToolkit()
    toolkit.ConfigInitOption("./", "{}")
    tasker := maa.NewTasker(nil)
    defer tasker.Destroy()

    device := toolkit.FindAdbDevices()[0]
    ctrl := maa.NewAdbController(
        device.AdbPath,
        device.Address,
        device.ScreencapMethod,
        device.InputMethod,
        device.Config,
        "path/to/MaaAgentBinary",
        nil,
    )
    defer ctrl.Destroy()
    ctrl.PostConnect().Wait()
    tasker.BindController(ctrl)

    res := maa.NewResource(nil)
    defer res.Destroy()
    res.PostBundle("./resource").Wait()
    tasker.BindResource(res)
    if !tasker.Initialized() {
        fmt.Println("Failed to init MAA.")
        os.Exit(1)
    }

    res.RegisterCustomRecognition("MyRec", &MyRec{})

    detail := tasker.PostTask("Startup").Wait().GetDetail()
    fmt.Println(detail)
}

type MyRec struct{}

func (r *MyRec) Run(ctx *maa.Context, arg *maa.CustomRecognitionArg) (*maa.CustomRecognitionResult, bool) {
    ctx.RunRecognition("MyCustomOCR", arg.Img, maa.J{
        "MyCustomOCR": maa.J{
            "roi": []int{100, 100, 200, 300},
        },
    })

    ctx.OverridePipeline(maa.J{
        "MyCustomOCR": maa.J{
            "roi": []int{1, 1, 114, 514},
        },
    })

    newContext := ctx.Clone()
    newContext.OverridePipeline(maa.J{
        "MyCustomOCR": maa.J{
            "roi": []int{100, 200, 300, 400},
        },
    })
    newContext.RunTask("MyCustomOCR", arg.Img)

    clickJob := ctx.GetTasker().GetController().PostClick(10, 20)
    clickJob.Wait()

    ctx.OverrideNext(arg.CurrentTaskName, []string{"TaskA", "TaskB"})

    return &maa.CustomRecognitionResult{
        Box:    maa.Rect{0, 0, 100, 100},
        Detail: "Hello World!",
    }, true
}

Custom Action

See custom-action for details.

Here is a basic example to implement your custom action:

package main

import (
    "fmt"
    "os"

    "github.com/MaaXYZ/maa-framework-go/v2"
)

func main() {
    toolkit := maa.NewToolkit()
    toolkit.ConfigInitOption("./", "{}")
    tasker := maa.NewTasker(nil)
    defer tasker.Destroy()

    device := toolkit.FindAdbDevices()[0]
    ctrl := maa.NewAdbController(
        device.AdbPath,
        device.Address,
        device.ScreencapMethod,
        device.InputMethod,
        device.Config,
        "path/to/MaaAgentBinary",
        nil,
    )
    defer ctrl.Destroy()
    ctrl.PostConnect().Wait()
    tasker.BindController(ctrl)

    res := maa.NewResource(nil)
    defer res.Destroy()
    res.PostBundle("./resource").Wait()
    tasker.BindResource(res)
    if !tasker.Initialized() {
        fmt.Println("Failed to init MAA.")
        os.Exit(1)
    }

    res.RegisterCustomAction("MyAct", &MyAct{})

    detail := tasker.PostTask("Startup").Wait().GetDetail()
    fmt.Println(detail)
}

type MyAct struct{}

func (a *MyAct) Run(_ *maa.Context, _ *maa.CustomActionArg) bool {
    return true
}

Contributing

We welcome contributions to the MaaFramework Go binding. If you find a bug or have a feature request, please open an issue on the GitHub repository. If you want to contribute code, feel free to fork the repository and submit a pull request.

License

This project is licensed under the LGPL-3.0 License. See the LICENSE file for details.

Discussion

QQ Group: 595990173

Documentation

Index

Constants

View Source
const (
	AdbScreencapMethodEncodeToFileAndPullValue = "EncodeToFileAndPull"
	AdbScreencapMethodEncodeValue              = "Encode"
	AdbScreencapMethodRawWithGzipValue         = "RawWithGzip"
	AdbScreencapMethodRawByNetcatValue         = "RawByNetcat"
	AdbScreencapMethodMinicapDirectValue       = "MinicapDirect"
	AdbScreencapMethodMinicapStreamValue       = "MinicapStream"
	AdbScreencapMethodEmulatorExtrasValue      = "EmulatorExtras"
	AdbScreencapMethodAllValue                 = "All"
	AdbScreencapMethodDefaultValue             = "Default"

	AdbInputMethodAdbShellValue           = "AdbShell"
	AdbInputMethodMinitouchAndAdbKeyValue = "MinitouchAndAdbKey"
	AdbInputMethodMaatouchValue           = "Maatouch"
	AdbInputMethodEmulatorExtrasValue     = "EmulatorExtras"
	AdbInputMethodAllValue                = "All"
	AdbInputMethodDefaultValue            = "Default"

	Win32ScreencapMethodGDIValue            = "GDI"
	Win32ScreencapMethodFramePoolValue      = "FramePool"
	Win32ScreencapMethodDXGIDesktopDupValue = "DXGIDesktopDup"

	Win32InputMethodSeizeValue       = "Seize"
	Win32InputMethodSendMessageValue = "SendMessage"

	DbgControllerTypeCarouselImageValue   = "CarouselImage"
	DbgControllerTypeReplayRecordingValue = "ReplayRecording"
)
View Source
const (
	InterenceDeviceAuto int32 = -1
	InferenceDevice0    int32 = 0
	InferenceDevice1    int32 = 1
)

Variables

This section is empty.

Functions

func AgentServerDetach added in v2.2.0

func AgentServerDetach()

func AgentServerJoin added in v2.2.0

func AgentServerJoin()

func AgentServerRegisterCustomAction added in v2.2.0

func AgentServerRegisterCustomAction(name string, action CustomAction) bool

func AgentServerRegisterCustomRecognition added in v2.2.0

func AgentServerRegisterCustomRecognition(name string, recognition CustomRecognition) bool

func AgentServerShutDown added in v2.2.0

func AgentServerShutDown()

func AgentServerStartUp added in v2.2.0

func AgentServerStartUp(identifier string) bool

func SetDebugMode

func SetDebugMode(enabled bool) bool

SetDebugMode sets whether to enable debug mode.

func SetLogDir

func SetLogDir(path string) bool

SetLogDir sets the log directory.

func SetRecording

func SetRecording(enabled bool) bool

SetRecording sets whether to dump all screenshots and actions.

func SetSaveDraw

func SetSaveDraw(enabled bool) bool

SetSaveDraw sets whether to save draw.

func SetStdoutLevel

func SetStdoutLevel(level LoggingLevel) bool

SetStdoutLevel sets the level of log output to stdout.

func Version

func Version() string

Version returns the version of the maa framework.

Types

type AdbDevice

type AdbDevice struct {
	Name            string
	AdbPath         string
	Address         string
	ScreencapMethod AdbScreencapMethod
	InputMethod     AdbInputMethod
	Config          string
}

AdbDevice represents a single ADB device with various properties about its information.

type AdbInputMethod

type AdbInputMethod uint64

AdbInputMethod

Use bitwise OR to set the method you need, MaaFramework will select the available ones according to priority. The priority is: EmulatorExtras > Maatouch > MinitouchAndAdbKey > AdbShell

const (
	AdbInputMethodNone               AdbInputMethod = 0
	AdbInputMethodAdbShell           AdbInputMethod = 1
	AdbInputMethodMinitouchAndAdbKey AdbInputMethod = 1 << 1
	AdbInputMethodMaatouch           AdbInputMethod = 1 << 2
	AdbInputMethodEmulatorExtras     AdbInputMethod = 1 << 3

	AdbInputMethodAll     = ^AdbInputMethodNone
	AdbInputMethodDefault = AdbInputMethodAll & (^AdbInputMethodEmulatorExtras)
)

AdbInputMethod

func ParseAdbInputMethod added in v2.1.0

func ParseAdbInputMethod(methodStr string) (AdbInputMethod, error)

func (AdbInputMethod) String added in v2.1.0

func (m AdbInputMethod) String() string

type AdbScreencapMethod

type AdbScreencapMethod uint64

AdbScreencapMethod

Use bitwise OR to set the method you need, MaaFramework will test their speed and use the fastest one.

const (
	AdbScreencapMethodNone                AdbScreencapMethod = 0
	AdbScreencapMethodEncodeToFileAndPull AdbScreencapMethod = 1
	AdbScreencapMethodEncode              AdbScreencapMethod = 1 << 1
	AdbScreencapMethodRawWithGzip         AdbScreencapMethod = 1 << 2
	AdbScreencapMethodRawByNetcat         AdbScreencapMethod = 1 << 3
	AdbScreencapMethodMinicapDirect       AdbScreencapMethod = 1 << 4
	AdbScreencapMethodMinicapStream       AdbScreencapMethod = 1 << 5
	AdbScreencapMethodEmulatorExtras      AdbScreencapMethod = 1 << 6

	AdbScreencapMethodAll     = ^AdbScreencapMethodNone
	AdbScreencapMethodDefault = AdbScreencapMethodAll & (^AdbScreencapMethodRawByNetcat) & (^AdbScreencapMethodMinicapDirect) & (^AdbScreencapMethodMinicapStream)
)

AdbScreencapMethod

func ParseAdbScreencapMethod added in v2.1.0

func ParseAdbScreencapMethod(methodStr string) (AdbScreencapMethod, error)

func (AdbScreencapMethod) String added in v2.1.0

func (m AdbScreencapMethod) String() string

type AgentClient added in v2.2.0

type AgentClient struct {
	// contains filtered or unexported fields
}

func NewAgentClient added in v2.2.0

func NewAgentClient() *AgentClient

NewAgentClient creates and initializes a new Agent client instance

func (*AgentClient) BindResource added in v2.2.0

func (ac *AgentClient) BindResource(res *Resource) bool

BindResource binds a resource object to the client

func (*AgentClient) Connect added in v2.2.0

func (ac *AgentClient) Connect() bool

Connect attempts to establish connection with Agent service

func (*AgentClient) CreateSocket added in v2.2.0

func (ac *AgentClient) CreateSocket(identifier string) bool

CreateSocket creates a socket connection with specified identifier

func (*AgentClient) Destroy added in v2.2.0

func (ac *AgentClient) Destroy()

Destroy releases underlying resources

func (*AgentClient) Disconnect added in v2.2.0

func (ac *AgentClient) Disconnect() bool

Disconnect actively terminates current connection

type Context

type Context struct {
	// contains filtered or unexported fields
}

func (*Context) Clone

func (ctx *Context) Clone() *Context

Clone clones current Context.

func (*Context) GetNodeJSON added in v2.3.0

func (ctx *Context) GetNodeJSON(name string) (bool, string)

GetNodeJSON gets the node JSON by name.

func (*Context) GetTaskJob

func (ctx *Context) GetTaskJob() *TaskJob

GetTaskJob returns current task job.

func (*Context) GetTasker

func (ctx *Context) GetTasker() *Tasker

GetTasker return current Tasker.

func (*Context) OverrideNext

func (ctx *Context) OverrideNext(name string, nextList []string) bool

OverrideNext overrides the next list of task by name.

func (*Context) OverridePipeline

func (ctx *Context) OverridePipeline(override any) bool

OverridePipeline overrides pipeline. The `override` parameter can be a JSON string or any data type that can be marshaled to JSON.

func (*Context) RunAction

func (ctx *Context) RunAction(entry string, box Rect, recognitionDetail string, override ...any) *NodeDetail

RunAction run an action and return its detail. It accepts an entry string and an optional override parameter which can be a JSON string or any data type that can be marshaled to JSON. If multiple overrides are provided, only the first one will be used.

Example 1:

ctx.RunAction("Task", `{"Task":{"action":"Click","target":[100, 200, 100, 100]}}`)

Example 2:

ctx.RunAction("Task", map[string]interface{}{
    "Task": map[string]interface{}{
        "action": "Click",
        "target": []int{100, 200, 100, 100},
	}
})

func (*Context) RunRecognition

func (ctx *Context) RunRecognition(entry string, img image.Image, override ...any) *RecognitionDetail

RunRecognition run a recognition and return its detail. It accepts an entry string and an optional override parameter which can be a JSON string or any data type that can be marshaled to JSON. If multiple overrides are provided, only the first one will be used.

Example 1:

ctx.RunRecognition("Task", `{"Task":{"recognition":"OCR","expected":"Hello"}}`)

Example 2:

ctx.RunRecognition("Task", map[string]interface{}{
    "Task": map[string]interface{}{
        "recognition": "OCR",
        "expected": "Hello",
	}
})

func (*Context) RunTask

func (ctx *Context) RunTask(entry string, override ...any) *TaskDetail

RunTask runs a task and returns its detail. It accepts an entry string and an optional override parameter which can be a JSON string or any data type that can be marshaled to JSON. If multiple overrides are provided, only the first one will be used.

Example 1:

ctx.RunTask("Task", `{"Task":{"action":"Click","target":[100, 200, 100, 100]}}`)

Example 2:

ctx.RunTask("Task", map[string]interface{}{
    "Task": map[string]interface{}{
        "action": "Click",
        "target": []int{100, 200, 100, 100},
	}
})

type Controller

type Controller interface {
	Destroy()
	Handle() uintptr

	SetScreenshotTargetLongSide(targetLongSide int32) bool
	SetScreenshotTargetShortSide(targetShortSide int32) bool
	SetScreenshotUseRawSize(enabled bool) bool
	SetRecording(enabled bool) bool

	PostConnect() *Job
	PostClick(x, y int32) *Job
	PostSwipe(x1, y1, x2, y2 int32, duration time.Duration) *Job
	PostPressKey(keycode int32) *Job
	PostInputText(text string) *Job
	PostStartApp(intent string) *Job
	PostStopApp(intent string) *Job
	PostTouchDown(contact, x, y, pressure int32) *Job
	PostTouchMove(contact, x, y, pressure int32) *Job
	PostTouchUp(contact int32) *Job
	PostScreencap() *Job

	Connected() bool
	CacheImage() image.Image
	GetUUID() (string, bool)
}

Controller is an interface that defines various methods for MAA controller.

func NewAdbController

func NewAdbController(
	adbPath, address string,
	screencapMethod AdbScreencapMethod,
	inputMethod AdbInputMethod,
	config, agentPath string,
	notify Notification,
) Controller

NewAdbController creates an ADB controller instance.

func NewCustomController

func NewCustomController(
	ctrl CustomController,
	notify Notification,
) Controller

NewCustomController creates a custom controller instance.

func NewDbgController

func NewDbgController(
	readPath, writePath string,
	dbgCtrlType DbgControllerType,
	config string,
	notify Notification,
) Controller

NewDbgController creates a DBG controller instance.

func NewWin32Controller

func NewWin32Controller(
	hWnd unsafe.Pointer,
	screencapMethod Win32ScreencapMethod,
	inputMethod Win32InputMethod,
	notify Notification,
) Controller

NewWin32Controller creates a win32 controller instance.

type ControllerActionDetail

type ControllerActionDetail struct {
	CtrlID uint64 `json:"ctrl_id"`
	UUID   string `json:"uuid"`
	Action string `json:"action"`
}

type CustomAction

type CustomAction interface {
	Run(ctx *Context, arg *CustomActionArg) bool
}

type CustomActionArg

type CustomActionArg struct {
	TaskDetail        *TaskDetail
	CurrentTaskName   string
	CustomActionName  string
	CustomActionParam string
	RecognitionDetail *RecognitionDetail
	Box               Rect
}

type CustomController

type CustomController interface {
	Connect() bool
	RequestUUID() (string, bool)
	StartApp(intent string) bool
	StopApp(intent string) bool
	Screencap() (image.Image, bool)
	Click(x, y int32) bool
	Swipe(x1, y1, x2, y2, duration int32) bool
	TouchDown(contact, x, y, pressure int32) bool
	TouchMove(contact, x, y, pressure int32) bool
	TouchUp(contact int32) bool
	PressKey(keycode int32) bool
	InputText(text string) bool

	Handle() uintptr
}

CustomController defines an interface for custom controller. Implementers of this interface must embed a CustomControllerHandler struct and provide implementations for the following methods: Connect, RequestUUID, StartApp, StopApp, Screencap, Click, Swipe, TouchDown, TouchMove, TouchUp, PressKey and InputText.

type CustomControllerHandler

type CustomControllerHandler struct {
	// contains filtered or unexported fields
}

func NewCustomControllerHandler

func NewCustomControllerHandler() CustomControllerHandler

func (CustomControllerHandler) Handle

func (c CustomControllerHandler) Handle() uintptr

type CustomRecognition

type CustomRecognition interface {
	Run(ctx *Context, arg *CustomRecognitionArg) (*CustomRecognitionResult, bool)
}

type CustomRecognitionArg

type CustomRecognitionArg struct {
	TaskDetail             *TaskDetail
	CurrentTaskName        string
	CustomRecognitionName  string
	CustomRecognitionParam string
	Img                    image.Image
	Roi                    Rect
}

type CustomRecognitionResult

type CustomRecognitionResult struct {
	Box    Rect
	Detail string
}

type DbgControllerType

type DbgControllerType uint64

DbgControllerType

No bitwise OR, just set it.

const (
	DbgControllerTypeNone            DbgControllerType = 0
	DbgControllerTypeCarouselImage   DbgControllerType = 1
	DbgControllerTypeReplayRecording DbgControllerType = 1 << 1
)

DbgControllerType

func ParseDbgControllerType added in v2.1.0

func ParseDbgControllerType(typeStr string) (DbgControllerType, error)

func (DbgControllerType) String added in v2.1.0

func (t DbgControllerType) String() string

type DesktopWindow

type DesktopWindow struct {
	Handle     unsafe.Pointer
	ClassName  string
	WindowName string
}

DesktopWindow represents a single desktop window with various properties about its information.

type InterenceDevice

type InterenceDevice = maa.MaaInferenceDevice

type J

type J map[string]any

type Job

type Job struct {
	// contains filtered or unexported fields
}

func NewJob

func NewJob(id int64, statusFunc func(id int64) Status, waitFunc func(id int64) Status) *Job

func (*Job) Done

func (j *Job) Done() bool

func (*Job) Failure

func (j *Job) Failure() bool

func (*Job) Invalid

func (j *Job) Invalid() bool

func (*Job) Pending

func (j *Job) Pending() bool

func (*Job) Running

func (j *Job) Running() bool

func (*Job) Status

func (j *Job) Status() Status

func (*Job) Success

func (j *Job) Success() bool

func (*Job) Wait

func (j *Job) Wait() *Job

type LoggingLevel

type LoggingLevel int32
const (
	LoggingLevelOff LoggingLevel = iota
	LoggingLevelFatal
	LoggingLevelError
	LoggingLevelWarn
	LoggingLevelInfo
	LoggingLevelDebug
	LoggingLevelTrace
	LoggingLevelAll
)

LoggingLevel

type NodeActionDetail

type NodeActionDetail struct {
	TaskID uint64 `json:"task_id"`
	NodeID uint64 `json:"node_id"`
	Name   string `json:"name"`
}

type NodeDetail

type NodeDetail struct {
	ID           int64
	Name         string
	Recognition  *RecognitionDetail
	RunCompleted bool
}

type NodeNextListDetail

type NodeNextListDetail struct {
	TaskID   uint64   `json:"task_id"`
	Name     string   `json:"name"`
	NextList []string `json:"next_list"`
}

type NodeRecognitionDetail

type NodeRecognitionDetail struct {
	TaskID uint64 `json:"task_id"`
	RecID  uint64 `json:"reco_id"`
	Name   string `json:"name"`
}

type Notification

type Notification interface {
	OnResourceLoading(notifyType NotificationType, detail ResourceLoadingDetail)
	OnControllerAction(notifyType NotificationType, detail ControllerActionDetail)
	OnTaskerTask(notifyType NotificationType, detail TaskerTaskDetail)
	OnTaskNextList(notifyType NotificationType, detail NodeNextListDetail)
	OnTaskRecognition(notifyType NotificationType, detail NodeRecognitionDetail)
	OnTaskAction(notifyType NotificationType, detail NodeActionDetail)
	OnUnknownNotification(msg, detailsJSON string)
}

type NotificationType

type NotificationType int
const (
	NotificationTypeUnknown NotificationType = iota
	NotificationTypeStarting
	NotificationTypeSucceeded
	NotificationTypeFailed
)

NotificationType

type RecognitionDetail

type RecognitionDetail struct {
	ID         int64
	Name       string
	Algorithm  string
	Hit        bool
	Box        Rect
	DetailJson string
	Raw        image.Image
	Draws      []image.Image
}

type Rect

type Rect = buffer.Rect

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

func NewResource

func NewResource(notify Notification) *Resource

NewResource creates a new resource.

func (*Resource) Clear

func (r *Resource) Clear() bool

Clear clears the resource loading paths.

func (*Resource) ClearCustomAction

func (r *Resource) ClearCustomAction() bool

ClearCustomAction clears all custom actions registered from the resource.

func (*Resource) ClearCustomRecognition

func (r *Resource) ClearCustomRecognition() bool

ClearCustomRecognition clears all custom recognitions registered from the resource.

func (*Resource) Destroy

func (r *Resource) Destroy()

Destroy frees the resource.

func (*Resource) GetHash

func (r *Resource) GetHash() (string, bool)

GetHash returns the hash of the resource.

func (*Resource) GetNodeJSON added in v2.3.0

func (r *Resource) GetNodeJSON(name string) (bool, string)

GetNodeJSON gets the node JSON by name.

func (*Resource) GetNodeList

func (r *Resource) GetNodeList() ([]string, bool)

GetNodeList returns the node list of the resource.

func (*Resource) Loaded

func (r *Resource) Loaded() bool

Loaded checks if resources are loaded.

func (*Resource) OverrideNext added in v2.3.0

func (r *Resource) OverrideNext(name string, nextList []string) bool

OverrideNext overrides the next list of task by name.

func (*Resource) OverridePipeline added in v2.3.0

func (r *Resource) OverridePipeline(override any) bool

OverridePipeline overrides pipeline. The `override` parameter can be a JSON string or any data type that can be marshaled to JSON.

func (*Resource) PostBundle

func (r *Resource) PostBundle(path string) *Job

PostBundle adds a path to the resource loading paths. Return id of the resource.

func (*Resource) RegisterCustomAction

func (r *Resource) RegisterCustomAction(name string, action CustomAction) bool

RegisterCustomAction registers a custom action to the resource.

func (*Resource) RegisterCustomRecognition

func (r *Resource) RegisterCustomRecognition(name string, recognition CustomRecognition) bool

RegisterCustomRecognition registers a custom recognition to the resource.

func (*Resource) UnregisterCustomAction

func (r *Resource) UnregisterCustomAction(name string) bool

UnregisterCustomAction unregisters a custom action from the resource.

func (*Resource) UnregisterCustomRecognition

func (r *Resource) UnregisterCustomRecognition(name string) bool

UnregisterCustomRecognition unregisters a custom recognition from the resource.

func (*Resource) UseAutoExecutionProvider

func (r *Resource) UseAutoExecutionProvider() bool

UseAutoExecutionProvider

func (*Resource) UseCPU

func (r *Resource) UseCPU() bool

UseCPU

func (*Resource) UseCoreml

func (r *Resource) UseCoreml(coremlFlag InterenceDevice) bool

UseCoreml

func (*Resource) UseDirectml

func (r *Resource) UseDirectml(deviceID InterenceDevice) bool

UseDirectml

type ResourceLoadingDetail

type ResourceLoadingDetail struct {
	ResID uint64 `json:"res_id"`
	Hash  string `json:"hash"`
	Path  string `json:"path"`
}

type Status

type Status int32
const (
	StatusInvalid Status = 0
	StatusPending Status = 1000
	StatusRunning Status = 2000
	StatusSuccess Status = 3000
	StatusFailure Status = 4000
)

func (Status) Done

func (status Status) Done() bool

func (Status) Failure

func (status Status) Failure() bool

func (Status) Invalid

func (status Status) Invalid() bool

func (Status) Pending

func (status Status) Pending() bool

func (Status) Running

func (status Status) Running() bool

func (Status) Success

func (status Status) Success() bool

type TaskDetail

type TaskDetail struct {
	ID          int64
	Entry       string
	NodeDetails []*NodeDetail
	Status      Status
}

type TaskJob

type TaskJob struct {
	*Job
	// contains filtered or unexported fields
}

func NewTaskJob

func NewTaskJob(
	id int64,
	statusFunc func(id int64) Status,
	waitFunc func(id int64) Status,
	getTaskDetailFunc func(id int64) *TaskDetail,
) *TaskJob

func (*TaskJob) GetDetail

func (j *TaskJob) GetDetail() *TaskDetail

func (*TaskJob) Wait

func (j *TaskJob) Wait() *TaskJob

type Tasker

type Tasker struct {
	// contains filtered or unexported fields
}

func NewTasker

func NewTasker(notify Notification) *Tasker

NewTasker creates an new tasker.

func (*Tasker) BindController

func (t *Tasker) BindController(ctrl Controller) bool

BindController binds the tasker to an initialized controller.

func (*Tasker) BindResource

func (t *Tasker) BindResource(res *Resource) bool

BindResource binds the tasker to an initialized resource.

func (*Tasker) ClearCache

func (t *Tasker) ClearCache() bool

ClearCache clears runtime cache.

func (*Tasker) Destroy

func (t *Tasker) Destroy()

Destroy free the tasker.

func (*Tasker) GetController

func (t *Tasker) GetController() Controller

GetController returns the controller handle of the tasker.

func (*Tasker) GetLatestNode

func (t *Tasker) GetLatestNode(taskName string) *NodeDetail

GetLatestNode returns latest node id.

func (*Tasker) GetResource

func (t *Tasker) GetResource() *Resource

GetResource returns the resource handle of the tasker.

func (*Tasker) Initialized

func (t *Tasker) Initialized() bool

Initialized checks if the tasker is initialized.

func (*Tasker) PostStop

func (t *Tasker) PostStop() *TaskJob

PostStop posts a stop signal to the tasker.

func (*Tasker) PostTask

func (t *Tasker) PostTask(entry string, override ...any) *TaskJob

PostTask posts a task to the tasker. `override` is an optional parameter. If provided, it should be a single value that can be a JSON string or any data type that can be marshaled to JSON. If multiple values are provided, only the first one will be used.

func (*Tasker) Running

func (t *Tasker) Running() bool

Running checks if the instance running.

func (*Tasker) Stopping added in v2.2.0

func (t *Tasker) Stopping() bool

Stopping checks whether the tasker is stopping.

type TaskerTaskDetail

type TaskerTaskDetail struct {
	TaskID uint64 `json:"task_id"`
	Entry  string `json:"entry"`
	UUID   string `json:"uuid"`
	Hash   string `json:"hash"`
}

type Toolkit

type Toolkit struct{}

func NewToolkit

func NewToolkit() *Toolkit

NewToolkit creates a new toolkit instance.

func (*Toolkit) ClearPICustom

func (t *Toolkit) ClearPICustom(instId uint64)

ClearPICustom unregisters all custom recognitions and actions for a given instance.

func (*Toolkit) ConfigInitOption

func (t *Toolkit) ConfigInitOption(userPath, defaultJson string) bool

ConfigInitOption inits the toolkit config option.

func (*Toolkit) FindAdbDevices

func (t *Toolkit) FindAdbDevices(specifiedAdb ...string) []*AdbDevice

FindAdbDevices finds adb devices.

func (*Toolkit) FindDesktopWindows

func (t *Toolkit) FindDesktopWindows() []*DesktopWindow

FindDesktopWindows finds desktop windows.

func (*Toolkit) RegisterPICustomAction

func (t *Toolkit) RegisterPICustomAction(instId uint64, name string, action CustomAction)

RegisterPICustomAction registers a custom action.

func (*Toolkit) RegisterPICustomRecognition

func (t *Toolkit) RegisterPICustomRecognition(instId uint64, name string, recognition CustomRecognition)

RegisterPICustomRecognition registers a custom recognizer.

func (*Toolkit) RunCli

func (t *Toolkit) RunCli(instId uint64, resourcePath, userPath string, directly bool, notify Notification) bool

RunCli runs the PI CLI.

type Win32InputMethod

type Win32InputMethod uint64

Win32InputMethod

No bitwise OR, just set it.

const (
	Win32InputMethodNone        Win32InputMethod = 0
	Win32InputMethodSeize       Win32InputMethod = 1
	Win32InputMethodSendMessage Win32InputMethod = 1 << 1
)

Win32InputMethod

func ParseWin32InputMethod added in v2.1.0

func ParseWin32InputMethod(methodStr string) (Win32InputMethod, error)

func (Win32InputMethod) String added in v2.1.0

func (m Win32InputMethod) String() string

type Win32ScreencapMethod

type Win32ScreencapMethod uint64

Win32ScreencapMethod

No bitwise OR, just set it.

const (
	Win32ScreencapMethodNone           Win32ScreencapMethod = 0
	Win32ScreencapMethodGDI            Win32ScreencapMethod = 1
	Win32ScreencapMethodFramePool      Win32ScreencapMethod = 1 << 1
	Win32ScreencapMethodDXGIDesktopDup Win32ScreencapMethod = 1 << 2
)

Win32ScreencapMethod

func ParseWin32ScreencapMethod added in v2.1.0

func ParseWin32ScreencapMethod(methodStr string) (Win32ScreencapMethod, error)

func (Win32ScreencapMethod) String added in v2.1.0

func (m Win32ScreencapMethod) String() string

Directories

Path Synopsis
examples
internal
maa

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL