Documentation
¶
Overview ¶
Package plugui renders the HTML pages a CPA plugin exposes to management clients.
CPA turns every entry registered through `management.register` into a menu entry, and CPA-Manager-Plus renders each menu as a page containing a same-origin iframe pointed at that route (see the CPAMP proxy allowlist for `/v0/resource/plugins/...`). CPAMP additionally injects a stylesheet into the iframe <head> that defines the host theme as CSS custom properties, so a page only has to consume those variables to look native in both light and dark themes — no JavaScript, no build step, no asset pipeline.
The variables the host guarantees are:
--bg-primary --bg-secondary --bg-tertiary --bg-hover --text-primary --text-secondary --text-tertiary --border-color --border-hover --primary-color --primary-hover --primary-active --primary-contrast --success-color --warning-color --danger-color --app-surface --app-surface-muted --app-border --app-text-* --app-input-bg --app-input-bg-focus --app-radius-sm --app-radius-md --focus-bg --focus-border --focus-inset
Index ¶
- Constants
- func Badge(tone, label string) template.HTML
- func Card(title string, body template.HTML, actions ...Action) template.HTML
- func Document(heading string, body ...template.HTML) []byte
- func DocumentWithRefresh(seconds int, heading string, body ...template.HTML) []byte
- func Fields(pairs ...Field) template.HTML
- func Group(fragments ...template.HTML) template.HTML
- func HTML(heading string, body ...template.HTML) pluginapi.ManagementResponse
- func HTMLWithRefresh(seconds int, heading string, body ...template.HTML) pluginapi.ManagementResponse
- func Image(dataURL, alt string, size int) template.HTML
- func IsAddAccountRequest(request pluginapi.ManagementRequest) bool
- func Notice(tone, message string) template.HTML
- type Action
- type Field
Constants ¶
const AddAccountNotice = "本次登录用于新增账号,已有账号的凭据不受影响。"
AddAccountNotice is the one-line caveat a login page shows when it was reached through AddAccountQuery. It is the only place the distinction is explained; the action itself is labelled 新建账号.
const AddAccountQuery = "add=1"
AddAccountQuery is the query a status page appends to the login link when the user asked for an ADDITIONAL account instead of a re-login.
Every provider derives its credential file name from the account's own identity (`defaultAuthFileName`), so a second account lands in a second file and the first one is left untouched. The query exists only so the login page can say that out loud: the login flow itself is the same one, deliberately — there is no second code path that could behave differently.
Variables ¶
This section is empty.
Functions ¶
func DocumentWithRefresh ¶ added in v0.2.0
DocumentWithRefresh renders a page that reloads itself every seconds seconds.
A resource route is dispatched as GET only, so a page that has to follow a long-running flow has exactly two form-free ways to ask for the next step: a link the user clicks, or `<meta http-equiv="refresh">`. The second one is what a QR page uses — each load performs one server-side poll and re-renders, with no form and no JavaScript involved.
func HTML ¶
func HTML(heading string, body ...template.HTML) pluginapi.ManagementResponse
HTML renders a page and wraps it as a management API response.
func HTMLWithRefresh ¶ added in v0.2.0
func HTMLWithRefresh(seconds int, heading string, body ...template.HTML) pluginapi.ManagementResponse
HTMLWithRefresh renders a self-refreshing page as a management API response.
func Image ¶ added in v0.2.0
Image renders a base64 data: URL image inline, so the page needs no second request and no external host.
size is the rendered square edge in CSS pixels (a QR needs enough of them to stay scannable); a non-positive value falls back to 220. A value that is not a base64 image data URL renders a readable placeholder instead of a broken image, which is what an upstream error page would otherwise look like.
func IsAddAccountRequest ¶ added in v0.2.0
func IsAddAccountRequest(request pluginapi.ManagementRequest) bool
IsAddAccountRequest reports whether a page was opened to add another account.
Types ¶
type Action ¶
type Action struct {
Label string
// Path is an optional relative target route, for example "status". When it
// is empty the action targets the current route.
Path string
// Query is appended to the target, for example "action=checkin".
Query string
// Kind is "" for a neutral button, "primary" for the accented one.
Kind string
}
Action is a link that performs a management action by reloading the current route with an extra query string.
Actions are navigations rather than form submissions on purpose: the host dispatches the resource route that management clients embed (`/v0/resource/ plugins/<id>/...`) as GET only, so a POST form would silently never reach the plugin from inside the UI.