Documentation
¶
Overview ¶
Package feedback is the apps' in-app feedback: what the user writes, screenshots and a screen recording, and diagnostics (this Mac, the app, the newest log lines and the last crash, redacted), sent to the site that serves the app — actnow.dev, or refto.one for Refto — over the feedback protocol (docs/feedback.md of the sites), and the user's own history of feedback with the replies.
Like updates and licence, the package has no UI: the app draws Settings → Feedback with the Manager's state and the reference texts (Text*).
fb, err := feedback.New(feedback.Config{
App: "dicta", Version: version, Channel: "beta",
BaseURL: "https://actnow.dev",
Dir: filepath.Join(dataDir, "feedback"),
LicenceToken: func() string {
if t := lic.Status().Token; t != nil {
return t.Raw
}
return ""
},
DeviceID: func() string { id, _ := licence.DeviceID(salt); return id },
Collect: feedback.CollectConfig{LogDir: logDir, Logs: []feedback.LogSpec{{Name: "dicta.log"}}},
})
fb.Subscribe(func(st feedback.State) { /* redraw */ })
go fb.Resume(ctx) // a submission left by the last run
who, _ := fb.Identity(ctx) // is the email optional?
problems := fb.Validate(draft, who) // before Submit
fb.Submit(ctx, draft) // prepares, saves, sends
fb.Refresh(ctx) // the history's statuses
The protocol (v1), every request a POST of JSON to <BaseURL>/api/feedback/v1/<endpoint>, every error {"error": code, "message": …, "details": …} with a 4xx status:
- identity {app, licenceToken?} → {linked, emailHint?}: whether the site knows an address to answer (the licence code's owner).
- create {app, version, build, channel, locale, kind, body, email?, licenceToken?, deviceId?, system, attachments: [{ref, role, name, mime, bytes, sha256}]} → {id, number, viewToken, webUrl, uploads: [{ref, attachmentId, method, url, headers, expiresAt, fallbackUrl}]}. Errors: email_required, invalid_email, invalid_body, attachment_too_large, attachment_type, too_many_attachments, rate_limited (details.retryAfter), disabled.
- each file: PUT url with headers (straight to the storage bucket); on a network failure PUT fallbackUrl with "Authorization: Feedback <viewToken>" (through the site).
- uploads {id, viewToken} → {uploads}: new URLs for the files not yet stored (the first ones expired).
- complete {id, viewToken} → {id, number, status, webUrl}; error upload_missing (details.missing: attachment ids).
- list {items: [{id, viewToken}]} → {items: Item}.
- get {id, viewToken} → Thread; reply {id, viewToken, body} → Message.
Nothing is uploaded before the user submits. Submit copies what will be sent (images re-encoded: at most MaxImages of MaxImageBytes, their metadata gone; a video of MaxVideoBytes, compressed with macOS's avconvert when larger; diagnostics.json) into Dir/outbox/<local id>/, so a send that fails or is cut by quitting resumes later (Resume, Retry).
Index ¶
- Constants
- Variables
- func ChecksumHeader(hexSum string) string
- func KindText(k Kind) family.Text
- func ProblemText(p Problem) family.Text
- func StatusText(s Status) family.Text
- func Summary(body string, n int) string
- func Thumbnail(ctx context.Context, conv Converter, path string, px int) (image.Image, error)
- func ValidEmail(s string) bool
- func VideoDuration(path string) (time.Duration, error)
- type APIError
- type AppInfo
- type Attachment
- type AttachmentMeta
- type Client
- func (c *Client) Complete(ctx context.Context, id, viewToken string) (CompleteAnswer, error)
- func (c *Client) Create(ctx context.Context, r CreateRequest) (CreateAnswer, error)
- func (c *Client) Get(ctx context.Context, r Ref) (Thread, error)
- func (c *Client) Identity(ctx context.Context, licenceToken string) (Identity, error)
- func (c *Client) List(ctx context.Context, refs []Ref) ([]Item, error)
- func (c *Client) Put(ctx context.Context, u Upload, viewToken, path string, f File, ...) error
- func (c *Client) Reply(ctx context.Context, r Ref, body string) (Message, error)
- func (c *Client) Uploads(ctx context.Context, id, viewToken string) ([]Upload, error)
- type CollectConfig
- type CompleteAnswer
- type Config
- type Context
- type Converter
- type CreateAnswer
- type CreateRequest
- type Diagnostics
- type Draft
- type ErrorContext
- type File
- type HistoryEntry
- type Identity
- type Item
- type Kind
- type LogSpec
- type LogTail
- type Manager
- func (m *Manager) Capture(ec ErrorContext) (*Report, error)
- func (m *Manager) Client() *Client
- func (m *Manager) Diagnostics(email string) Diagnostics
- func (m *Manager) Discard(localID string) error
- func (m *Manager) Forget(id string) error
- func (m *Manager) ForgetIdentity()
- func (m *Manager) History() []HistoryEntry
- func (m *Manager) Identity(ctx context.Context) (Identity, error)
- func (m *Manager) LoadReport(id string) (*Report, error)
- func (m *Manager) Pending() []Submission
- func (m *Manager) Refresh(ctx context.Context) ([]HistoryEntry, error)
- func (m *Manager) Reply(ctx context.Context, id, body string) (Message, error)
- func (m *Manager) Reset()
- func (m *Manager) Resume(ctx context.Context)
- func (m *Manager) Retry(ctx context.Context, localID string) error
- func (m *Manager) State() State
- func (m *Manager) Step(name string)
- func (m *Manager) Steps() []Step
- func (m *Manager) Submit(ctx context.Context, d Draft) (*Submission, error)
- func (m *Manager) Subscribe(fn func(State)) (unsubscribe func())
- func (m *Manager) Thread(ctx context.Context, id string) (Thread, error)
- func (m *Manager) Unread() int
- func (m *Manager) WebURL() string
- type Message
- type Phase
- type Prefill
- type Problem
- type Ref
- type Report
- type Role
- type SendState
- type State
- type Status
- type Step
- type Submission
- type System
- type Thread
- type Upload
- type VideoThumbnailer
Constants ¶
const ( SubmissionKind = "feedback-submission" HistoryKind = "feedback-history" )
Schemas of the files in Config.Dir.
const ( MaxSteps = 30 ReportLogLines = 40 ReportMaxAge = 7 * 24 * time.Hour MaxReports = 50 )
Limits of reports and steps.
const ( MaxImages = 3 MaxImageBytes = 5 << 20 MaxVideos = 1 MaxVideoBytes = 20 << 20 MaxDiagnosticsBytes = 2 << 20 // MaxBodyRunes and MinBodyRunes bound what the user writes. MaxBodyRunes = 10000 MinBodyRunes = 5 MaxEmailLen = 254 // MaxImageSide is the longest side images are scaled to. MaxImageSide = 3840 // Inputs larger than these are refused before any work. MaxImageInputBytes = 64 << 20 MaxVideoInputBytes = 1 << 30 )
Limits of the protocol (the sites enforce the same).
const DiagnosticsSchema = "actnow.feedback-diagnostics/1"
DiagnosticsSchema of diagnostics.json.
const MaxHistory = 200
MaxHistory entries are kept (the newest).
const OutboxMaxAge = 7 * 24 * time.Hour
OutboxMaxAge: a submission not sent after this long is dropped.
const ReportKind = "feedback-report"
ReportKind is the schema kind of a report file.
Variables ¶
var ( ErrUnsupported = errors.New("feedback: this file type cannot be converted on this system") ErrTooLarge = errors.New("feedback: the file stays too large") ErrNotImage = errors.New("feedback: not an image") ErrNotVideo = errors.New("feedback: not an MP4 or QuickTime movie") )
Errors of the preparation of attachments.
var ( TextSection = family.Text{EN: "Feedback", ZH: "反馈"} TextNew = family.Text{EN: "New feedback", ZH: "新反馈"} TextMenuItem = family.Text{EN: "Send Feedback…", ZH: "发送反馈…"} TextHistory = family.Text{EN: "Your feedback", ZH: "我的反馈"} TextOnTheWeb = family.Text{EN: "Send feedback on the web", ZH: "在网页上反馈"} TextViewOnWeb = family.Text{EN: "View on {site}", ZH: "在 {site} 上查看"} TextKind = family.Text{EN: "Type", ZH: "类型"} TextKindBug = family.Text{EN: "Problem", ZH: "问题"} TextKindIdea = family.Text{EN: "Suggestion", ZH: "建议"} TextKindQuestion = family.Text{EN: "Question", ZH: "提问"} TextKindOther = family.Text{EN: "Other", ZH: "其他"} TextBody = family.Text{EN: "Description", ZH: "描述"} TextBodyPlaceholder = family.Text{ EN: "What happened, and what did you expect? Steps to reproduce help.", ZH: "发生了什么?你期望的结果是什么?附上复现步骤会更快定位。", } TextEmail = family.Text{EN: "Email", ZH: "邮箱"} TextEmailPlaceholder = family.Text{EN: "So we can reply", ZH: "用于接收回复"} TextEmailLinked = family.Text{ EN: "We'll reply to {email}, the address of your licence. Enter another to use it instead.", ZH: "回复会发到授权邮箱 {email};也可以填写其他邮箱。", } TextAttachments = family.Text{EN: "Attachments", ZH: "附件"} TextAddImages = family.Text{EN: "Add screenshots…", ZH: "添加截图…"} TextAddVideo = family.Text{EN: "Add a screen recording…", ZH: "添加录屏…"} TextAttachHint = family.Text{ EN: "Up to 3 images (made smaller to 5 MB each) and one video up to 20 MB (larger ones are compressed). Uploaded only when you send.", ZH: "最多 3 张图片(每张自动压缩到 5 MB 以内)和 1 段 20 MB 以内的视频(更大的会自动压缩)。只在提交时上传。", } TextDiagnostics = family.Text{EN: "Include diagnostics", ZH: "附上诊断信息"} TextDiagnosticsHint = family.Text{ EN: "This Mac's model and macOS version, {app}'s version and settings, and its recent log lines and last crash, with keys, passwords, names, email and IP addresses removed.", ZH: "包括这台 Mac 的型号和 macOS 版本、{app} 的版本和设置、最近的日志和最后一次崩溃记录;密钥、密码、姓名、邮箱和 IP 地址已去除。", } TextPreview = family.Text{EN: "See what is sent…", ZH: "查看将发送的内容…"} TextPrivacy = family.Text{ EN: "Your feedback goes to {site} and is used only to answer you and improve {app}.", ZH: "反馈会发送到 {site},只用于回复你和改进 {app}。", } TextPrivacyLink = family.Text{EN: "Privacy policy", ZH: "隐私政策"} TextSend = family.Text{EN: "Send", ZH: "提交"} TextPreparing = family.Text{EN: "Preparing attachments…", ZH: "正在处理附件…"} TextSending = family.Text{EN: "Sending… {size}", ZH: "正在发送… {size}"} TextSent = family.Text{ EN: "Thanks! Your feedback {number} was sent. We'll reply by email and here.", ZH: "感谢反馈!编号 {number} 已提交,我们会通过邮件和这里回复你。", } TextFailed = family.Text{ EN: "Your feedback could not be sent. It is kept on this Mac and sent when you're online again.", ZH: "反馈未能发送,已保存在这台 Mac 上,联网后会自动重新发送。", } TextRetry = family.Text{EN: "Try again", ZH: "重试"} TextDiscard = family.Text{EN: "Discard", ZH: "放弃"} TextPending = family.Text{EN: "Waiting to send", ZH: "等待发送"} TextNoHistory = family.Text{EN: "Feedback you send from this Mac appears here.", ZH: "在这台 Mac 上提交的反馈会显示在这里。"} TextReply = family.Text{EN: "Reply", ZH: "回复"} TextSupport = family.Text{EN: "Support", ZH: "客服"} TextYou = family.Text{EN: "You", ZH: "你"} TextNewReply = family.Text{EN: "New reply", ZH: "有新回复"} TextStatusNew = family.Text{EN: "Received", ZH: "已收到"} TextStatusTriaged = family.Text{EN: "Being looked at", ZH: "处理中"} TextStatusInProgress = family.Text{EN: "In progress", ZH: "处理中"} TextStatusWaitingUser = family.Text{EN: "Waiting for you", ZH: "等待你的回复"} TextStatusResolved = family.Text{EN: "Resolved", ZH: "已解决"} TextStatusClosed = family.Text{EN: "Closed", ZH: "已关闭"} TextProblemBodyShort = family.Text{EN: "Write a few words about it.", ZH: "请简单描述一下。"} TextProblemBodyLong = family.Text{EN: "At most {max} characters.", ZH: "最多 {max} 个字符。"} TextProblemEmailRequired = family.Text{EN: "Enter an email so we can reply.", ZH: "请填写邮箱,以便我们回复。"} TextProblemEmailInvalid = family.Text{EN: "This email doesn't look right.", ZH: "邮箱格式不正确。"} TextProblemTooManyImages = family.Text{EN: "At most {max} images.", ZH: "最多 {max} 张图片。"} TextProblemImage = family.Text{EN: "This image cannot be used (missing, too large or not an image).", ZH: "这张图片无法使用(文件不存在、过大或不是图片)。"} TextProblemVideo = family.Text{EN: "This video cannot be used: an MP4 or MOV file up to 1 GB.", ZH: "这段视频无法使用:仅支持 1 GB 以内的 MP4 或 MOV。"} TextProblemVideoTooLarge = family.Text{EN: "The video is still over 20 MB after compressing: trim it and try again.", ZH: "视频压缩后仍超过 20 MB,请剪短后再试。"} TextRateLimited = family.Text{EN: "Too much feedback from this Mac for now: it will be sent later.", ZH: "短时间内提交过多,稍后会自动发送。"} )
Reference texts of Settings → Feedback, in English and Simplified Chinese. actnowkit does no i18n: apps copy them into their catalogues. Placeholders: {app}, {number}, {email}, {count}, {max}, {size}, {site}.
var ( TextWindowTitle = family.Text{EN: "Send Feedback", ZH: "发送反馈"} TextWindowSub = family.Text{EN: "to the {app} team · {site}", ZH: "发给 {app} 团队 · {site}"} TextReportTitle = family.Text{EN: "Report this problem", ZH: "报告此问题"} TextReportLink = family.Text{EN: "Report this problem…", ZH: "报告此问题…"} TextIncludeReport = family.Text{ EN: "Include this error report and its {count} log lines", ZH: "附上这份错误报告和相关的 {count} 行日志", } TextContextError = family.Text{EN: "Error", ZH: "错误"} TextContextWhere = family.Text{EN: "Where", ZH: "位置"} TextContextWhen = family.Text{EN: "When", ZH: "时间"} TextContextSteps = family.Text{EN: "Steps", ZH: "最近操作"} TextContextReport = family.Text{EN: "Report", ZH: "错误报告"} TextAdd = family.Text{EN: "Add", ZH: "添加"} TextAddSub = family.Text{EN: "images or a video", ZH: "图片或视频"} TextAttachCount = family.Text{EN: "{images} of 3 images · {videos} of 1 video", ZH: "图片 {images}/3 · 视频 {videos}/1"} TextRemove = family.Text{EN: "Remove", ZH: "移除"} TextOpenWith = family.Text{EN: "Open in QuickTime Player", ZH: "用 QuickTime Player 打开"} TextHistoryCount = family.Text{EN: "Your feedback ({count})", ZH: "我的反馈({count})"} TextCancel = family.Text{EN: "Cancel", ZH: "取消"} TextClose = family.Text{EN: "Close", ZH: "关闭"} TextViewIt = family.Text{EN: "View it", ZH: "查看"} TextSentTitle = family.Text{EN: "Thanks — feedback sent", ZH: "感谢反馈"} TextSentBody = family.Text{ EN: "Your feedback {number} is with us. We reply by email and in Your feedback.", ZH: "反馈 {number} 已收到,我们会通过邮件和“我的反馈”回复你。", } TextOpenWindow = family.Text{EN: "Open the feedback window", ZH: "打开反馈窗口"} TextOptional = family.Text{EN: "Optional", ZH: "选填"} TextEmailNeeded = family.Text{EN: "We reply to this address.", ZH: "我们会回复到这个邮箱。"} TextSeeWhatIsSent = family.Text{EN: "See what is sent", ZH: "查看将发送的内容"} TextWhatIsSent = family.Text{EN: "What is sent", ZH: "将发送的内容"} TextWhatIsSentDiagnostics = family.Text{ EN: "diagnostics.json, attached to your feedback when Include diagnostics is on.", ZH: "diagnostics.json,开启“附上诊断信息”时随反馈发送。", } TextWhatIsSentReport = family.Text{ EN: "The error report, sent in diagnostics.json when it is included.", ZH: "错误报告,勾选附上时放在 diagnostics.json 里发送。", } TextAddFiles = family.Text{EN: "Add images or a video", ZH: "添加图片或视频"} TextCopy = family.Text{EN: "Copy", ZH: "复制"} TextCopied = family.Text{EN: "Copied", ZH: "已复制"} TextDone = family.Text{EN: "Done", ZH: "完成"} TextPrevious = family.Text{EN: "Previous", ZH: "上一个"} TextNext = family.Text{EN: "Next", ZH: "下一个"} TextBack = family.Text{EN: "Back", ZH: "返回"} TextRefresh = family.Text{EN: "Refresh", ZH: "刷新"} TextLoading = family.Text{EN: "Loading…", ZH: "正在加载…"} TextUnreachable = family.Text{EN: "Could not reach {site}: {error}", ZH: "无法连接 {site}:{error}"} TextYourReply = family.Text{EN: "Your reply", ZH: "你的回复"} TextImageOf = family.Text{EN: "Image {n} of {count} · {name} · {size}", ZH: "图片 {n}/{count} · {name} · {size}"} TextVideoOf = family.Text{EN: "Video · {name} · {size}", ZH: "视频 · {name} · {size}"} TextReportLines = family.Text{EN: "{id} ({count} log lines)", ZH: "{id}({count} 行日志)"} TextToday = family.Text{EN: "Today", ZH: "今天"} TextSendFailed = family.Text{EN: "Not sent: {error}", ZH: "发送失败:{error}"} )
The feedback window (feedbackui) and the "Report this problem" link.
var ErrNetwork = errors.New("feedback: cannot reach the site")
ErrNetwork wraps failures to reach the site (offline, timeouts, 5xx).
var ErrNoReport = errors.New("feedback: no such error report")
ErrNoReport: Prefill names a report this Mac no longer has.
var Kinds = []Kind{KindBug, KindIdea, KindQuestion, KindOther}
Kinds in the order a form lists them.
var VideoPresets = []string{"PresetHEVC1920x1080", "Preset1280x720", "Preset960x540", "PresetLowQuality"}
VideoPresets are tried in order until the movie fits MaxVideoBytes.
Functions ¶
func ChecksumHeader ¶
ChecksumHeader is the S3 header carrying a file's SHA-256 (base64), as the site signs it into the upload URL.
func ProblemText ¶
ProblemText is the reference text of a form problem ({max} filled).
func StatusText ¶
StatusText is the reference text of a status.
func Thumbnail ¶ added in v0.22.0
Thumbnail is a picture of an image or a video for the attachment grid, its longest side at most px: images decoded here (HEIC and the others through conv), videos through conv's VideoThumbnail (macOS: Quick Look).
func ValidEmail ¶
ValidEmail reports whether s looks like one plain address.
Types ¶
type APIError ¶
type APIError struct {
HTTPStatus int
Code string
Message string
Details json.RawMessage
}
APIError is an error answer of the feedback API.
type AppInfo ¶
type AppInfo struct {
ID string `json:"id"`
Version string `json:"version"`
Build string `json:"build,omitempty"`
Channel string `json:"channel,omitempty"`
Go string `json:"go"`
Licensed string `json:"licence,omitempty"` // edition and state, never the code
}
AppInfo is the app part of Diagnostics.
type Attachment ¶
type Attachment struct {
ID string `json:"id"`
Role Role `json:"role"`
Name string `json:"name"`
MIME string `json:"mime"`
Bytes int64 `json:"bytes"`
}
Attachment as the site lists it in a thread.
type AttachmentMeta ¶
type AttachmentMeta struct {
Ref string `json:"ref"`
Role Role `json:"role"`
Name string `json:"name"`
MIME string `json:"mime"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
}
AttachmentMeta is a file in the create request.
type Client ¶
type Client struct {
// BaseURL: "https://actnow.dev" or "https://refto.one" (http only on
// loopback, for tests).
BaseURL string
App string
Version string
HTTP *http.Client
}
Client speaks the feedback protocol (see the package doc).
func (*Client) Create ¶
func (c *Client) Create(ctx context.Context, r CreateRequest) (CreateAnswer, error)
Create files the feedback; its files are uploaded next.
func (*Client) Identity ¶
Identity asks whether the site can answer the holder of licenceToken ("" for none) without an email.
func (*Client) Put ¶
func (c *Client) Put(ctx context.Context, u Upload, viewToken, path string, f File, progress func(sent int64)) error
Put uploads the file at path to u (direct, then the fallback through the site on a network failure). progress gets the bytes sent (it may go back to 0 when the fallback starts again).
type CollectConfig ¶
type CollectConfig struct {
// LogDir is the app's logs folder (mygo.PathLogs).
LogDir string
// Logs to include, the app's main log first. Every rotated copy of
// them is also searched for warnings and errors (ProblemLines).
Logs []LogSpec
// CrashFile in LogDir ("crash.log"; "" for none): its last report.
CrashFile string
// CrashFiles: more crash files in LogDir (a helper's
// "crash-helper.log"); each one's last report is added under its name.
CrashFiles []string
// ProblemDays: how far back the warnings and errors go (0: 7).
ProblemDays int
// ProblemLines: at most this many of them (0: 300).
ProblemLines int
// Settings returns the app's settings as JSON, already without
// secrets and the user's own words (the apps' diagnostic bundle has
// it). Optional. Settings and Extra are called from the goroutine
// running Submit or Diagnostics, not the UI thread: an app whose state
// lives on the UI thread hands them a snapshot.
Settings func() json.RawMessage
// Extra returns lines the app adds ("Engine": "1.2 (ready)",
// "Loaded models": …). Optional.
Extra func() map[string]string
// Scrub is the app's own redaction of a log line (the tails, the
// problems, the crash), after redact.Text and redact.Personal
// (Inboxly: subjects; Dicta: transcript text). Settings and Extra do
// not go through it.
Scrub func(string) string
// Personal: who to mask (redact.ThisUser() when zero).
Personal *redact.Personal
}
CollectConfig says what Collect gathers.
type CompleteAnswer ¶
type CompleteAnswer struct {
ID string `json:"id"`
Number string `json:"number"`
Status Status `json:"status"`
WebURL string `json:"webUrl"`
}
CompleteAnswer is the answer of complete.
type Config ¶
type Config struct {
// App is the family id ("dicta"); Version, Build (commit) and Channel
// ("release", "beta") of the running app.
App, Version, Build, Channel string
// BaseURL of the site the app belongs to: "https://actnow.dev", or
// "https://refto.one" for Refto.
BaseURL string
// WebPath of the site's feedback form ("" = "/feedback"; Refto:
// "/app/feedback").
WebPath string
// Dir holds the outbox and the history (the app's data folder +
// "/feedback"); created 0700.
Dir string
// HTTPClient: the app's client to its site (its proxy rule); nil = a
// default client.
HTTPClient *http.Client
// LicenceToken returns the licence token of this Mac ("" for none):
// the site answers its code's owner. Optional.
LicenceToken func() string
// DeviceID returns this Mac's device ID for the app (licence.DeviceID).
// Optional.
DeviceID func() string
// Locale returns the app's language ("zh-Hans", "en"). Optional.
Locale func() string
// LicenceSummary returns the licence's edition and state for the
// diagnostics ("paid, valid"); never the code. Optional.
LicenceSummary func() string
// Collect says what the diagnostics include.
Collect CollectConfig
// Converter for images and videos (nil: SystemConverter()).
Converter Converter
// Log receives one line per step and every failure. Optional.
Log func(string)
// Now and Sleep (tests).
Now func() time.Time
Sleep func(context.Context, time.Duration) error
}
Config of a Manager.
type Context ¶ added in v0.22.0
type Context struct {
Title string `json:"title,omitempty"`
Code string `json:"code,omitempty"`
Kind string `json:"kind,omitempty"`
Where string `json:"where,omitempty"`
At time.Time `json:"at,omitzero"`
ReportID string `json:"reportId,omitempty"`
Steps []string `json:"steps,omitempty"`
}
Context is the part of a Report the site stores in its columns (the panel's filters and "common errors"); the rest goes in diagnostics.json.
type Converter ¶
type Converter interface {
// ToPNG converts an image to a PNG file.
ToPNG(ctx context.Context, src, dst string) error
// CompressVideo re-encodes a movie with an AVFoundation preset name
// ("PresetHEVC1920x1080", "Preset1280x720", …), dropping its
// privacy-sensitive metadata (location).
CompressVideo(ctx context.Context, src, dst, preset string) error
}
Converter does what pure Go cannot: decoding HEIC, WebP, TIFF and BMP images, and compressing videos. SystemConverter is macOS's sips and avconvert.
func SystemConverter ¶
func SystemConverter() Converter
SystemConverter converts nothing outside macOS: HEIC, WebP, TIFF and BMP images and videos over MaxVideoBytes are refused (ErrUnsupported).
type CreateAnswer ¶
type CreateAnswer struct {
ID string `json:"id"`
Number string `json:"number"`
ViewToken string `json:"viewToken"`
WebURL string `json:"webUrl"`
Uploads []Upload `json:"uploads"`
}
CreateAnswer is the answer of create.
type CreateRequest ¶
type CreateRequest struct {
App string `json:"app"`
Version string `json:"version"`
Build string `json:"build,omitempty"`
Channel string `json:"channel,omitempty"`
Locale string `json:"locale,omitempty"`
Kind Kind `json:"kind"`
Body string `json:"body"`
Email string `json:"email,omitempty"`
LicenceToken string `json:"licenceToken,omitempty"`
DeviceID string `json:"deviceId,omitempty"`
Source string `json:"source"` // "app"
System System `json:"system"`
Context *Context `json:"context,omitempty"`
Attachments []AttachmentMeta `json:"attachments"`
}
CreateRequest is the body of create.
type Diagnostics ¶
type Diagnostics struct {
Schema string `json:"schema"`
CollectedAt time.Time `json:"collectedAt"`
App AppInfo `json:"app"`
System System `json:"system"`
Extra map[string]string `json:"extra,omitempty"`
Settings json.RawMessage `json:"settings,omitempty"`
// Problems: the warnings and errors of the last ProblemDays, oldest
// first, from every log and its rotated copies.
Problems []string `json:"problems,omitempty"`
Logs []LogTail `json:"logs,omitempty"`
Crash string `json:"crash,omitempty"`
// Report: the error report the feedback was opened with.
Report *Report `json:"report,omitempty"`
}
Diagnostics is diagnostics.json.
func Collect ¶
func Collect(cfg CollectConfig, app AppInfo, now time.Time) Diagnostics
Collect gathers the diagnostics. Every line goes through redact.Text, then redact.Personal, then cfg.Scrub; what it cannot read it leaves out. The result fits MaxDiagnosticsBytes (the logs are cut first).
func (Diagnostics) Preview ¶
func (d Diagnostics) Preview() string
Preview is diagnostics.json as the user reads it before sending: the JSON indented.
type Draft ¶
type Draft struct {
Kind Kind
Body string
Email string
// Images are the files the user picked (originals: Submit re-encodes
// them), at most MaxImages.
Images []string
// Video is a file the user picked ("" for none).
Video string
// Diagnostics: send diagnostics.json (the form's switch, on by default).
Diagnostics bool
// Report: the error report the window was opened with (a "Report this
// problem" link); IncludeReport sends it (on by default; the user may
// untick it). It goes in diagnostics.json and the request's context.
Report *Report
IncludeReport bool
}
Draft is what the form holds.
type ErrorContext ¶ added in v0.22.0
type ErrorContext struct {
// Title for people ("Transcription failed").
Title string
// Code: the app's stable error code ("E-ASR-0042").
Code string
// Kind: machine-readable ("engine_out_of_memory").
Kind string
// Where in the app, without the user's content: "Meetings ›
// Transcribe", not the meeting's name (it is scrubbed anyway).
Where string
// Err: the error; its text goes through redact and the app's Scrub.
Err error
}
ErrorContext is what an app knows where something failed, for the "Report this problem" link: Capture turns it into a Report.
type File ¶
type File struct {
// Ref names the file in the create request ("image-1", "video",
// "diagnostics").
Ref string `json:"ref"`
Role Role `json:"role"`
Name string `json:"name"` // the file in the outbox directory
MIME string `json:"mime"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256"` // hex
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
// Original is the picked file's base name (for the site's list).
Original string `json:"original,omitempty"`
// AttachmentID once the site created it, Stored once uploaded.
AttachmentID string `json:"attachmentId,omitempty"`
Stored bool `json:"stored,omitempty"`
}
File is a prepared attachment in the outbox.
func PrepareImage ¶
PrepareImage writes src re-encoded into dir as <name>.png or .jpg: its orientation applied, scaled to MaxImageSide, every metadata (EXIF, location) gone, at most MaxImageBytes. A PNG or GIF stays a PNG when it fits (screenshots keep their sharp text); otherwise JPEG at falling quality, then smaller.
func PrepareVideo ¶
PrepareVideo copies src into dir as <name>.mp4/.mov when it fits MaxVideoBytes; a larger one is compressed with VideoPresets in turn (conv; macOS's avconvert drops the location and other private metadata) until it fits, or ErrTooLarge.
type HistoryEntry ¶
type HistoryEntry struct {
Item
ViewToken string `json:"viewToken"`
// SeenMessages: how many of the thread's messages the user has seen
// (Unread compares).
SeenMessages int `json:"seenMessages,omitempty"`
}
HistoryEntry is a feedback this Mac sent: the site's item and the token that lets this Mac read it (it grants nothing else).
func (HistoryEntry) Unread ¶
func (e HistoryEntry) Unread() bool
Unread: the thread has messages the user has not opened.
type Identity ¶
type Identity struct {
// Linked: the site has an address to answer (the licence code's
// owner); the email is optional.
Linked bool `json:"linked"`
// EmailHint is that address masked ("r***@gmail.com").
EmailHint string `json:"emailHint,omitempty"`
// Known: the answer came from the site (false when it could not be
// asked: the email is then required).
Known bool `json:"-"`
}
Identity is what the site knows of the sender.
type Item ¶
type Item struct {
ID string `json:"id"`
Number string `json:"number"`
App string `json:"app"`
Kind Kind `json:"kind"`
Status Status `json:"status"`
Summary string `json:"summary"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
// Messages counts the thread's messages (the replies and the user's).
Messages int `json:"messages"`
LastReplyAt time.Time `json:"lastReplyAt,omitzero"`
WebURL string `json:"webUrl,omitempty"`
}
Item is a feedback of the history, as the site lists it.
type LogSpec ¶
type LogSpec struct {
// Name of the current file ("dicta.log"); rotated copies are Name.1,
// Name.2… (the apps' logs package).
Name string
// Lines: the newest lines to include (0: 1000 for the first spec, 200
// for the others), within MaxBytes (0: 256 KB).
Lines int
MaxBytes int
}
LogSpec names a log of the app's logs folder to include.
type LogTail ¶
type LogTail struct {
File string `json:"file"`
Lines []string `json:"lines"`
Truncated bool `json:"truncated,omitempty"`
}
LogTail is the newest lines of one log.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager prepares, sends and remembers feedback.
func (*Manager) Capture ¶ added in v0.22.0
func (m *Manager) Capture(ec ErrorContext) (*Report, error)
Capture makes an error report now: the context (its title, where and error through redact.Text, redact.Personal and the app's Scrub), the recent steps and the newest ReportLogLines of the main log, saved on this Mac. Call it where the app shows the error, then show "Report this problem" with the report.
func (*Manager) Diagnostics ¶
func (m *Manager) Diagnostics(email string) Diagnostics
Diagnostics collects what a submission's diagnostics.json would hold now (the form's "See what is sent"); email is the address typed in the form, left unmasked.
func (*Manager) ForgetIdentity ¶
func (m *Manager) ForgetIdentity()
ForgetIdentity drops the cached answer: call it when the licence changes (activated, removed), else the old answer stays for the Manager's life.
func (*Manager) History ¶
func (m *Manager) History() []HistoryEntry
History is this Mac's feedback, newest first, as last refreshed (from memory after the first read: cheap enough for the UI thread).
func (*Manager) Identity ¶
Identity asks the site whether the email is optional (cached for the Manager's life after a successful answer). On a failure the answer is Identity{} (the email is required) and the error.
func (*Manager) LoadReport ¶ added in v0.22.0
LoadReport reads a report Capture saved.
func (*Manager) Pending ¶
func (m *Manager) Pending() []Submission
Pending is the outbox now (read from disk: call it to fill the UI before Resume has run; State.Pending follows afterwards).
func (*Manager) Refresh ¶
func (m *Manager) Refresh(ctx context.Context) ([]HistoryEntry, error)
Refresh asks the site for the statuses and messages of the history.
func (*Manager) Reset ¶
func (m *Manager) Reset()
Reset returns the state to Idle after Sent or Failed (a new form).
func (*Manager) Resume ¶
Resume sends the submissions a previous run left (not the rejected ones). Call it at start-up (in a goroutine) and when the network comes back.
func (*Manager) Retry ¶
Retry sends one submission of the outbox again (a rejected one too: the site may accept it now).
func (*Manager) Step ¶ added in v0.22.0
Step records a user action (an action's name, never what it acted on): the newest MaxSteps go with error reports. Cheap; any goroutine.
func (*Manager) Submit ¶
Submit prepares the draft (re-encodes the images, fits the video, collects the diagnostics), saves it to the outbox and sends it. It blocks until sent or failed: run it off the UI thread. A failed send stays in the outbox (State.Pending) for Retry or Resume.
func (*Manager) Subscribe ¶
Subscribe calls fn on every change, from the goroutine making it, in order (an older state is never delivered after a newer one); fn must not call back into the Manager's setters.
func (*Manager) Thread ¶
Thread reads one feedback of the history with its messages, and marks them seen.
type Message ¶
type Message struct {
ID string `json:"id"`
// Author: "user" or "support".
Author string `json:"author"`
Body string `json:"body"`
CreatedAt time.Time `json:"createdAt"`
}
Message of a thread.
type Prefill ¶ added in v0.22.0
Prefill is what opens the feedback window filled in: from Settings or the Help menu (zero), from a "Report this problem" link (Kind bug and the Report), or with files the app already has (a screenshot).
type Problem ¶
type Problem string
Problem is a reason the form cannot be sent yet; the app shows the matching text (ProblemText) beside the field.
const ( ProblemKind Problem = "kind" ProblemBodyShort Problem = "body_short" ProblemBodyLong Problem = "body_long" ProblemEmailRequired Problem = "email_required" ProblemEmailInvalid Problem = "email_invalid" ProblemTooManyImages Problem = "too_many_images" ProblemImageMissing Problem = "image_missing" ProblemImageTooLarge Problem = "image_too_large" ProblemImageType Problem = "image_type" ProblemVideoMissing Problem = "video_missing" ProblemVideoTooLarge Problem = "video_too_large" ProblemVideoType Problem = "video_type" )
func CheckImage ¶
CheckImage is the check of a picked image (when it is picked): it exists, is not over MaxImageInputBytes and looks like an image.
func CheckVideo ¶
CheckVideo is the check of a picked video: it exists, is not over MaxVideoInputBytes and is an MP4 or QuickTime movie.
type Report ¶ added in v0.22.0
type Report struct {
Schema string `json:"schema"`
ID string `json:"id"`
At time.Time `json:"at"`
Version string `json:"version,omitempty"`
Title string `json:"title"`
Code string `json:"code,omitempty"`
Kind string `json:"kind,omitempty"`
Where string `json:"where,omitempty"`
Error string `json:"error,omitempty"`
Steps []Step `json:"steps,omitempty"`
// Logs: the newest lines of the main log at the time (ReportLogLines).
Logs []string `json:"logs,omitempty"`
}
Report is an error report: the context, the recent actions and the log lines at the time of the error. Capture keeps it on this Mac (Dir/reports/<ID>.json); it is sent only when the user sends feedback with it (diagnostics.json's "report", and the create request's context).
type State ¶
type State struct {
Phase Phase
// Current: the submission being prepared or sent (or just sent, or
// failed).
Current *Submission
// Sent and Total bytes while Sending.
SentBytes, TotalBytes int64
// Step: "prepare", "create", "upload", "complete".
Step string
Err error
// Pending: submissions of the outbox not sent (failed ones too).
Pending []Submission
}
State is what the feedback UI shows.
type Status ¶
type Status string
Status of a feedback item on the site. Spam is shown to its sender as closed.
type Submission ¶
type Submission struct {
Schema string `json:"schema"`
LocalID string `json:"localId"`
CreatedAt time.Time `json:"createdAt"`
App string `json:"app"`
Version string `json:"version"`
Build string `json:"build,omitempty"`
Channel string `json:"channel,omitempty"`
Locale string `json:"locale,omitempty"`
Kind Kind `json:"kind"`
Body string `json:"body"`
Email string `json:"email,omitempty"`
Files []File `json:"files,omitempty"`
System System `json:"system"`
Context *Context `json:"context,omitempty"`
// The site's answer to create.
ID string `json:"id,omitempty"`
Number string `json:"number,omitempty"`
ViewToken string `json:"viewToken,omitempty"`
WebURL string `json:"webUrl,omitempty"`
State SendState `json:"state"`
Attempts int `json:"attempts,omitempty"`
LastError string `json:"lastError,omitempty"`
// Rejected: the site refused it (ErrorCode says why).
Rejected bool `json:"rejected,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
}
Submission is one feedback on its way: the outbox entry (Dir/outbox/<LocalID>/submission.json).
func (*Submission) Bytes ¶
func (s *Submission) Bytes() (total, stored int64)
Bytes is the size of the files to upload.
type System ¶
type System struct {
OS string `json:"os,omitempty"` // "macOS 15.4.1"
OSBuild string `json:"osBuild,omitempty"` // "24E263"
Model string `json:"model,omitempty"` // "Mac15,12"
Chip string `json:"chip,omitempty"` // "Apple M3"
Arch string `json:"arch,omitempty"` // "arm64"
CPUs int `json:"cpus,omitempty"`
MemoryGB int `json:"memoryGB,omitempty"`
// FreeDiskGB on the volume of the home folder, rounded.
FreeDiskGB int `json:"freeDiskGB,omitempty"`
Locale string `json:"locale,omitempty"` // the app's language
// TZOffset: minutes east of UTC (to read the log times).
TZOffset int `json:"tzOffset"`
}
System is this Mac, as diagnostics and the create request tell it: no names, serial numbers or addresses.
type Thread ¶
type Thread struct {
Item Item `json:"item"`
Body string `json:"body"`
Messages []Message `json:"messages"`
Attachments []Attachment `json:"attachments"`
}
Thread is one feedback with its messages.
type Upload ¶
type Upload struct {
Ref string `json:"ref"`
AttachmentID string `json:"attachmentId"`
Method string `json:"method"`
URL string `json:"url"`
Headers map[string]string `json:"headers"`
ExpiresAt time.Time `json:"expiresAt"`
// FallbackURL takes the file through the site when URL cannot be
// reached (Authorization: Feedback <viewToken>).
FallbackURL string `json:"fallbackUrl"`
}
Upload is where one file goes.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package feedbacktest is the feedback protocol of actnow.dev and refto.one in memory, for the tests of apps and of feedbackui: a Site on an httptest server that takes feedback, its uploads and replies.
|
Package feedbacktest is the feedback protocol of actnow.dev and refto.one in memory, for the tests of apps and of feedbackui: a Site on an httptest server that takes feedback, its uploads and replies. |