plugui

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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 新建账号.

View Source
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 Badge

func Badge(tone, label string) template.HTML

Badge renders a small status pill.

func Card

func Card(title string, body template.HTML, actions ...Action) template.HTML

Card renders a titled section with optional action links.

func Document

func Document(heading string, body ...template.HTML) []byte

Document renders a complete page. body is composed from the helpers below.

func DocumentWithRefresh added in v0.2.0

func DocumentWithRefresh(seconds int, heading string, body ...template.HTML) []byte

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 Fields

func Fields(pairs ...Field) template.HTML

Fields renders label/value rows.

func Group

func Group(fragments ...template.HTML) template.HTML

Group concatenates several body fragments into the single body a Card takes.

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

func Image(dataURL, alt string, size int) template.HTML

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.

func Notice

func Notice(tone, message string) template.HTML

Notice renders an inline message. tone is "", "success", "warning" or "danger".

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.

type Field

type Field struct {
	Label string
	Value string
}

Field is one label/value row.

Jump to

Keyboard shortcuts

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