maa

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: LGPL-3.0 Imports: 9 Imported by: 1

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.

Installation

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

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

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"

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

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:

Platform-Specific Notes

Windows

On Windows, the default location for MaaFramework is C:\maa. Ensure that MaaFramework is installed in this directory for the binding to work out of the box.

If you need to specify a custom installation path, refer to the Custom Environment section.

Linux and macOS

On Linux and macOS, you will need to create a pkg-config file named maa.pc. This file should correctly point to the locations of the MaaFramework headers and libraries. Place this file in a directory where pkg-config can find it (e.g., /usr/lib/pkgconfig).

A sample maa.pc file might look like this:

prefix=/path/to/maafw
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: MaaFramework
Description: MaaFramework library
Version: 1.0
Libs: -L${libdir} -lMaaFramework -lMaaToolkit
Cflags: -I${includedir}

If you need to specify a custom environment, refer to the Custom Environment section.

Custom Environment

If you need to specify a custom installation path for MaaFramework, you can disable the default location using the -tags customenv build tag. Then, set the necessary environment variables CGO_CFLAGS and CGO_LDFLAGS.

go build -tags customenv

Set the environment variables as follows:

export CGO_CFLAGS="-I[path to maafw include directory]"
export CGO_LDFLAGS="-L[path to maafw lib directory] -lMaaFramework -lMaaToolkit"

Replace [path to maafw include directory] with the actual path to the MaaFramework include directory and [path to maafw lib directory] with the actual path to the MaaFramework library directory.

Examples

Quirk start

See quirk-start for details.

Here is a basic example to get you started:

package main

import (
	"fmt"
	"github.com/MaaXYZ/maa-framework-go"
	"os"
)

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.PostPath("./resource").Wait()
	tasker.BindResource(res)
	if tasker.Initialized() {
		fmt.Println("Failed to init MAA.")
		os.Exit(1)
	}

	detail := tasker.PostPipeline("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"
	"github.com/MaaXYZ/maa-framework-go"
	"os"
)

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.PostPath("./resource").Wait()
	tasker.BindResource(res)
	if tasker.Initialized() {
		fmt.Println("Failed to init MAA.")
		os.Exit(1)
	}

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

	detail := tasker.PostPipeline("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.RunPipeline("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"
	"github.com/MaaXYZ/maa-framework-go"
	"os"
)

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.PostPath("./resource").Wait()
	tasker.BindResource(res)
	if tasker.Initialized() {
		fmt.Println("Failed to init MAA.")
		os.Exit(1)
	}

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

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

type MyAct struct{}

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

PI CLI

See pi-cli for details.

Here is a basic example of using PI CLI:

package main

import (
	"github.com/MaaXYZ/maa-framework-go"
)

func main() {
	toolkit := maa.NewToolkit()
	toolkit.RegisterPICustomAction(0, "MyAct", &MyAct{})
	toolkit.RunCli(0, "./resource", "./", false, nil)
}

type MyAct struct{}

func (m MyAct) Run(ctx *maa.Context, arg *maa.CustomActionArg) bool {
	ctx.OverrideNext(arg.CurrentTaskName, []string{"TaskA", "TaskB"})

	img := ctx.GetTasker().GetController().CacheImage()
	ctx.GetTasker().GetController().PostClick(100, 100).Wait()

	ctx.RunRecognition("Cat", img, maa.J{
		"recognition": "OCR",
		"expected":    "cat",
	})
	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

This section is empty.

Variables

This section is empty.

Functions

func SetDebugMode added in v1.1.0

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 SetShowHitDraw

func SetShowHitDraw(enabled bool) bool

SetShowHitDraw sets whether to show hit draw.

func SetStdoutLevel

func SetStdoutLevel(level LoggingLevel) bool

SetStdoutLevel sets the level of log output to stdout.

func Version added in v0.5.0

func Version() string

Version returns the version of the maa framework.

Types

type AdbDevice added in v1.0.1

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 added in v1.0.0

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

type AdbScreencapMethod added in v1.0.0

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 & (^AdbScreencapMethodMinicapDirect) & (^AdbScreencapMethodMinicapStream)
)

AdbScreencapMethod

type Context added in v1.0.0

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

func (*Context) Clone added in v1.0.0

func (ctx *Context) Clone() *Context

Clone clones current Context.

func (*Context) GetTaskJob added in v1.0.0

func (ctx *Context) GetTaskJob() *TaskJob

GetTaskJob returns current task job.

func (*Context) GetTasker added in v1.0.0

func (ctx *Context) GetTasker() *Tasker

GetTasker return current Tasker.

func (*Context) OverrideNext added in v1.0.0

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

OverrideNext overrides the next list of task by name.

func (*Context) OverridePipeline added in v1.0.0

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 added in v1.0.0

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

RunAction run an action and return it detail. `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 (*Context) RunPipeline added in v1.0.0

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

RunPipeline runs a pipeline and return it detail. `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 (*Context) RunRecognition added in v1.0.0

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

RunRecognition run a recognition and return it detail. `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.

type Controller

type Controller interface {
	Destroy()
	Handle() unsafe.Pointer

	SetScreenshotTargetLongSide(targetLongSide int) bool
	SetScreenshotTargetShortSide(targetShortSide int) bool
	SetRecording(recording 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 added in v1.1.0

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 added in v1.0.1

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() unsafe.Pointer
	Destroy()
}

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 added in v0.2.0

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

func NewCustomControllerHandler added in v0.2.0

func NewCustomControllerHandler() CustomControllerHandler

func (CustomControllerHandler) Destroy added in v0.2.0

func (c CustomControllerHandler) Destroy()

func (CustomControllerHandler) Handle added in v0.2.0

type CustomRecognition added in v1.1.0

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

type CustomRecognitionArg added in v1.1.0

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

type CustomRecognitionResult added in v1.1.0

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

type DesktopWindow added in v1.0.1

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

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

type J added in v1.0.0

type J map[string]any

type Job added in v0.4.0

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

func NewJob added in v0.4.0

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

func (*Job) Done added in v0.4.0

func (j *Job) Done() bool

func (*Job) Failure added in v0.4.0

func (j *Job) Failure() bool

func (*Job) Invalid added in v0.4.0

func (j *Job) Invalid() bool

func (*Job) Pending added in v0.4.0

func (j *Job) Pending() bool

func (*Job) Running added in v0.4.0

func (j *Job) Running() bool

func (*Job) Status added in v0.4.0

func (j *Job) Status() Status

func (*Job) Success added in v0.4.0

func (j *Job) Success() bool

func (*Job) Wait added in v0.4.0

func (j *Job) Wait() *Job

type LoggingLevel

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

LoggingLevel

type NodeDetail

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

type Notification added in v1.1.0

type Notification interface {
	OnResourceLoading(notifyType NotificationType, detail ResourceLoadingDetail)
	OnControllerAction(notifyType NotificationType, detail ControllerActionDetail)
	OnTaskerTask(notifyType NotificationType, detail TaskerTaskDetail)
	OnTaskNextList(notifyType NotificationType, detail TaskNextListDetail)
	OnTaskRecognition(notifyType NotificationType, detail TaskRecognitionDetail)
	OnTaskAction(notifyType NotificationType, detail TaskActionDetail)
	OnRawNotification(msg, detailsJSON string)
	OnUnknownNotification(msg, detailsJSON string)
}

type NotificationHandler added in v1.1.0

type NotificationHandler struct{}

func (*NotificationHandler) OnControllerAction added in v1.1.0

func (n *NotificationHandler) OnControllerAction(_ NotificationType, _ ControllerActionDetail)

func (*NotificationHandler) OnRawNotification added in v1.1.0

func (n *NotificationHandler) OnRawNotification(msg, detailsJSON string)

func (*NotificationHandler) OnResourceLoading added in v1.1.0

func (n *NotificationHandler) OnResourceLoading(_ NotificationType, _ ResourceLoadingDetail)

func (*NotificationHandler) OnTaskAction added in v1.1.0

func (*NotificationHandler) OnTaskNextList added in v1.1.0

func (*NotificationHandler) OnTaskRecognition added in v1.1.0

func (n *NotificationHandler) OnTaskRecognition(_ NotificationType, _ TaskRecognitionDetail)

func (*NotificationHandler) OnTaskerTask added in v1.1.0

func (*NotificationHandler) OnUnknownNotification added in v1.1.0

func (n *NotificationHandler) OnUnknownNotification(_, _ string)

type NotificationType added in v1.1.0

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 added in v0.3.0

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 added in v1.0.0

func (r *Resource) ClearCustomAction() bool

ClearCustomAction clears all custom actions registered from the resource.

func (*Resource) ClearCustomRecognition added in v1.1.0

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) GetTaskList

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

GetTaskList returns the task list of the resource.

func (*Resource) Handle added in v1.0.0

func (r *Resource) Handle() unsafe.Pointer

func (*Resource) Loaded

func (r *Resource) Loaded() bool

Loaded checks if resources are loaded.

func (*Resource) PostPath

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

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

func (*Resource) RegisterCustomAction added in v1.0.0

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

RegisterCustomAction registers a custom action to the resource.

func (*Resource) RegisterCustomRecognition added in v1.1.0

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

RegisterCustomRecognition registers a custom recognition to the resource.

func (*Resource) SetGpuID added in v1.2.0

func (r *Resource) SetGpuID(id int) bool

func (*Resource) UnregisterCustomAction added in v1.0.0

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

UnregisterCustomAction unregisters a custom action from the resource.

func (*Resource) UnregisterCustomRecognition added in v1.1.0

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

UnregisterCustomRecognition unregisters a custom recognition from the resource.

type ResourceLoadingDetail added in v1.1.0

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 added in v0.4.0

func (status Status) Done() bool

func (Status) Failure added in v0.4.0

func (status Status) Failure() bool

func (Status) Invalid added in v0.4.0

func (status Status) Invalid() bool

func (Status) Pending added in v0.4.0

func (status Status) Pending() bool

func (Status) Running added in v0.4.0

func (status Status) Running() bool

func (Status) Success added in v0.4.0

func (status Status) Success() bool

type TaskActionDetail added in v1.1.0

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

type TaskDetail

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

type TaskJob added in v0.4.0

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

func NewTaskJob added in v0.4.0

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

func (*TaskJob) GetDetail added in v0.4.0

func (j *TaskJob) GetDetail() *TaskDetail

func (*TaskJob) Wait added in v0.4.0

func (j *TaskJob) Wait() *TaskJob

type TaskNextListDetail added in v1.1.0

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

type TaskRecognitionDetail added in v1.1.0

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

type Tasker added in v1.0.0

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

func NewTasker added in v1.0.0

func NewTasker(notify Notification) *Tasker

NewTasker creates an new tasker.

func (*Tasker) BindController added in v1.0.0

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

BindController binds the tasker to an initialized controller.

func (*Tasker) BindResource added in v1.0.0

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

BindResource binds the tasker to an initialized resource.

func (*Tasker) ClearCache added in v1.0.0

func (t *Tasker) ClearCache() bool

ClearCache clears runtime cache.

func (*Tasker) Destroy added in v1.0.0

func (t *Tasker) Destroy()

Destroy free the tasker.

func (*Tasker) GetController added in v1.0.0

func (t *Tasker) GetController() Controller

GetController returns the controller handle of the tasker.

func (*Tasker) GetLatestNode added in v1.0.0

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

GetLatestNode returns latest node id.

func (*Tasker) GetResource added in v1.0.0

func (t *Tasker) GetResource() *Resource

GetResource returns the resource handle of the tasker.

func (*Tasker) Handle added in v1.0.0

func (t *Tasker) Handle() unsafe.Pointer

Handle returns the tasker handle.

func (*Tasker) Initialized added in v1.1.0

func (t *Tasker) Initialized() bool

Initialized checks if the tasker is initialized.

func (*Tasker) PostPipeline added in v1.0.0

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

PostPipeline 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) PostStop added in v1.0.0

func (t *Tasker) PostStop() bool

PostStop posts a stop signal to the tasker.

func (*Tasker) Running added in v1.0.0

func (t *Tasker) Running() bool

Running checks if the instance running.

type TaskerTaskDetail added in v1.1.0

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

type Toolkit added in v1.0.1

type Toolkit struct{}

func NewToolkit added in v1.0.1

func NewToolkit() *Toolkit

NewToolkit creates a new toolkit instance.

func (*Toolkit) ClearPICustom added in v1.0.1

func (t *Toolkit) ClearPICustom(instId uint64)

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

func (*Toolkit) ConfigInitOption added in v1.0.1

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

ConfigInitOption inits the toolkit config option.

func (*Toolkit) FindAdbDevices added in v1.0.1

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

FindAdbDevices finds adb devices.

func (*Toolkit) FindDesktopWindows added in v1.0.1

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

FindDesktopWindows finds desktop windows.

func (*Toolkit) RegisterPICustomAction added in v1.0.1

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

RegisterPICustomAction registers a custom action.

func (*Toolkit) RegisterPICustomRecognition added in v1.1.0

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

RegisterPICustomRecognition registers a custom recognizer.

func (*Toolkit) RunCli added in v1.0.1

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

RunCli runs the PI CLI.

type Win32InputMethod added in v1.0.0

type Win32InputMethod uint64

Win32InputMethod

No bitwise OR, just set it.

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

Win32InputMethod

type Win32ScreencapMethod added in v1.0.0

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

Directories

Path Synopsis
examples
internal

Jump to

Keyboard shortcuts

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