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
- Variables
- type Device
- type Options
- type Project
- type Tools
- func (t *Tools) Boot(ctx context.Context, d Device) error
- func (t *Tools) Button(ctx context.Context, d Device, name string) error
- func (t *Tools) Delete(ctx context.Context, d Device) error
- func (t *Tools) Devices(ctx context.Context) (devs []Device, notes []string, err error)
- func (t *Tools) Keyboard(ctx context.Context, d Device, show bool) error
- func (t *Tools) Shot(ctx context.Context, d Device, path string) error
- func (t *Tools) Shutdown(ctx context.Context, d Device) error
- func (t *Tools) Tap(ctx context.Context, d Device, x, y int) error
- func (t *Tools) Type(ctx context.Context, d Device, text string) error
- func (t *Tools) XcodeRun(ctx context.Context, dir string, d Device, scheme string, w io.Writer) (XcodeApp, error)
- type XcodeApp
Constants ¶
const ( StepStarting = "starting" // the simulator, when it is shut down StepBuilding = "building" StepInstalling = "installing" StepOpening = "opening" )
The steps of XcodeRun, as Tools.Step is told them. Conch.app reads them from conch preview run -status, so a name here is a promise.
Variables ¶
var Buttons = []string{"home", "back", "lock", "side"}
Buttons are the device buttons Button presses.
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.
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.
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
// Step, when set, is told each step of XcodeRun as it begins.
Step func(step string)
}
Tools are the programs the platforms ship, found once.
func FindWith ¶
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 ¶
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 ¶
Button presses home, back, lock or the side button. An iPhone has no back button, so that one is Android's alone; on an Android phone lock and side are both its power key.
func (*Tools) Delete ¶ added in v0.2.3
Delete removes an iOS simulator for good, stopping it first, since simctl will not delete one that is running. An Android emulator's image is Android Studio's to delete, with its own Device Manager.
func (*Tools) Devices ¶
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) Keyboard ¶ added in v0.2.3
Keyboard says whether an iOS simulator shows its own keyboard once it has seen a hardware one — the Simulator app's, or the one typing through AXe is — which by default it hides. The setting is the simulator's and stays; the notification is what makes a running app read it, at the next field touched, where the setting alone waits for a relaunch.
func (*Tools) Shutdown ¶ added in v0.2.3
Shutdown stops a running device: a simulator nobody is looking at keeps running, memory and all, until somebody stops it. An emulator is told through its console; a phone plugged in is the phone's to turn off.
func (*Tools) Tap ¶
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) 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.