preview

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package preview reaches the phones a mobile developer runs their app on while an agent works on it: the iOS simulators Xcode installs and the Android emulators and devices adb sees. It lists them, starts one, takes a screenshot, taps, types and presses a button — the same few things whether Conch.app is drawing the phone beside the agent or the agent is looking at its own work with `conch preview shot`.

It is the real device, never a picture of a layout: what is shown is what the app does, crashes and all. Everything goes through the platforms' own tools (xcrun simctl, adb, emulator, and idb for touching an iOS simulator, which simctl cannot do), so a machine without them says which is missing rather than pretending there is nothing to show.

Index

Constants

This section is empty.

Variables

View Source
var Buttons = []string{"home", "back"}

Buttons are the device buttons Button presses.

View Source
var ErrNoTools = errors.New("no iOS simulator or Android tools found: install Xcode (for xcrun simctl) or Android Studio (for adb and emulator)")

ErrNoTools is what Devices says when neither platform's tools are here.

Functions

This section is empty.

Types

type Device

type Device struct {
	// ID is what every other call takes: a simulator's UDID, an adb
	// serial, or "avd:NAME" for an emulator that is not running yet.
	ID       string `json:"id"`
	Name     string `json:"name"`
	Platform string `json:"platform"` // ios, android
	Kind     string `json:"kind"`     // simulator, emulator, device
	OS       string `json:"os,omitempty"`
	// Type is a simulator's device type, which says its screen's scale.
	Type string `json:"type,omitempty"`
	// State is booted, shutdown, or what adb says of a device it cannot
	// use (offline, unauthorized).
	State string `json:"state"`
}

Device is a phone an app can be previewed on.

func Pick

func Pick(devs []Device, want string) (Device, error)

Pick finds the device a command means: by ID or by name (any case), else the first booted one. Nothing booted is an error that says how to start one, since that is the next thing to do.

func (Device) Booted

func (d Device) Booted() bool

Booted reports whether the device can be shown and touched now.

type Options

type Options struct {
	Xcode      string // Xcode.app, or its Contents/Developer folder
	AndroidSDK string
}

Options are the settings (preview in config.toml): where Xcode and the Android SDK are, when conch should not find them by itself.

type Project

type Project struct {
	Kind  string `json:"kind"`  // expo, react-native, flutter, xcode, android, "" for none found
	Label string `json:"label"` // as a person names it
	// Dev starts what reloads the app as files change; empty where the
	// platform's own IDE does that (Xcode).
	Dev string `json:"dev,omitempty"`
	// Platforms the app builds for, as Devices names them.
	Platforms []string `json:"platforms,omitempty"`
}

Project is what kind of mobile app a folder holds, and how its dev server is started — what a preview needs running before there is anything of the app's to show.

func Detect

func Detect(dir string) Project

Detect looks at a folder's own files, not its subfolders': a project is opened at its root, and walking node_modules would find every kind.

type Tools

type Tools struct {
	Xcrun    string // xcrun, for simctl
	Adb      string
	Emulator string
	Idb      string
	// Axe drives an iOS simulator (taps, typing, buttons), before idb.
	Axe string
	// DeveloperDir is the Xcode the programs are told to use
	// (DEVELOPER_DIR), when xcode-select's own choice would not reach the
	// simulators; "" leaves it to xcode-select.
	DeveloperDir string
	// XcodeProblem says why the Xcode in the settings was not used.
	XcodeProblem string
	// Run runs a program to its end and answers its standard output;
	// Start leaves one running (an emulator). Tests replace both.
	Run   func(ctx context.Context, name string, args ...string) ([]byte, error)
	Start func(name string, args ...string) error
	// Pipe runs a program to its end with everything it prints sent to w
	// as it prints it: a build somebody is watching in a terminal.
	Pipe func(ctx context.Context, w io.Writer, name string, args ...string) error
}

Tools are the programs the platforms ship, found once.

func Find

func Find(env []string) *Tools

Find is FindWith and no settings.

func FindWith

func FindWith(env []string, opt Options) *Tools

FindWith looks for the tools on PATH and where the Android SDK keeps its own (it is seldom on PATH: Android Studio installs it in the home folder), given the environment as KEY=VALUE pairs and the settings.

func (*Tools) Boot

func (t *Tools) Boot(ctx context.Context, d Device) error

Boot starts a device. A simulator boots in the background, with no Simulator window; an emulator is left running as its own program.

func (*Tools) Button

func (t *Tools) Button(ctx context.Context, d Device, name string) error

Button presses home or back. An iPhone has no back button, so that one is Android's alone.

func (*Tools) Devices

func (t *Tools) Devices(ctx context.Context) (devs []Device, notes []string, err error)

Devices lists every phone either platform offers, booted ones first. A platform whose tool fails is left out and said in notes, so an Android emulator still shows on a Mac whose Xcode is broken.

func (*Tools) Shot

func (t *Tools) Shot(ctx context.Context, d Device, path string) error

Shot writes a PNG of the device's screen to path, at its full pixels.

func (*Tools) Tap

func (t *Tools) Tap(ctx context.Context, d Device, x, y int) error

Tap touches the screen at x, y in the screenshot's pixels — the numbers an agent reads off the picture Shot gave it.

func (*Tools) Type

func (t *Tools) Type(ctx context.Context, d Device, text string) error

Type enters text into whatever field has the focus on the device.

func (*Tools) XcodeRun

func (t *Tools) XcodeRun(ctx context.Context, dir string, d Device, scheme string, w io.Writer) (XcodeApp, error)

XcodeRun builds the Xcode project in dir for the simulator d, installs it and opens it, the build printed to w as it goes. A simulator that is shut down is started first: the build is for it.

type XcodeApp

type XcodeApp struct {
	Container string // the .xcworkspace or .xcodeproj built
	Scheme    string
	Path      string // the built .app
	BundleID  string
}

XcodeApp is what a build of an Xcode project made, and how it is opened.

Jump to

Keyboard shortcuts

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