Files
winauth-go/internal/ui/entry_actions.go
T
iceking2nd b483360778 feat(ui): 主题切换 + 语言持久化 + About 对话框
- 新增 light/dark 主题调色板与 Windows 注册表系统主题探测
- 偏好设置对话框:主题三选一 + 语言下拉(en/zh-CN/de),即时生效
- 持久化 Language/Theme/AutoLockMinutes/MinimizeToTray 至 YAML 顶层
- 启动时按 config 中保存的语言初始化 i18n
- About 对话框展示 version/runtime/项目地址/许可证
- 全部硬编码颜色迁移到 themePalette,为深色模式做准备
2026-06-12 03:38:13 +08:00

56 lines
1.8 KiB
Go

package ui
import (
"image"
"gioui.org/app"
"gioui.org/layout"
"gioui.org/op/clip"
"gioui.org/op/paint"
"gioui.org/unit"
"gioui.org/widget/material"
"git.wxccs.org/iceking2nd/winauth-go/internal/global"
"git.wxccs.org/iceking2nd/winauth-go/internal/i18n"
"git.wxccs.org/iceking2nd/winauth-go/internal/win32"
)
// copyCodeToClipboard pushes the current OTP onto the system clipboard
// and pops a brief toast confirming the action. Errors are surfaced via
// the same toast so the user actually sees them.
func (st *appState) copyCodeToClipboard(en *entry, w *app.Window) {
const fn = "internal.ui.appState.copyCodeToClipboard"
if en == nil || en.Code == "" {
return
}
if err := win32.SetClipboardText(en.Code); err != nil {
global.Log.WithField("func", fn).WithError(err).Warn("clipboard copy failed")
st.toast.Show(i18n.T("msg_copy_failed"), w)
w.Invalidate()
return
}
st.toast.Show(i18n.T("msg_copied"), w)
w.Invalidate()
}
// drawEmptyPlaceholder paints the centered "no entries yet" hint shown
// when the entries list is empty.
func drawEmptyPlaceholder(gtx layout.Context, th *material.Theme) layout.Dimensions {
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
lbl := material.Body1(th, i18n.T("msg_empty_list"))
lbl.Color = activePalette.MutedFg
return layout.UniformInset(unit.Dp(8)).Layout(gtx, lbl.Layout)
})
}
// drawDivider paints a 1px-tall light-gray line across the available
// horizontal space. Used between entries in the list.
func drawDivider(gtx layout.Context) layout.Dimensions {
h := gtx.Dp(unit.Dp(1))
size := image.Pt(gtx.Constraints.Max.X, h)
defer clip.Rect{Max: size}.Push(gtx.Ops).Pop()
paint.ColorOp{Color: activePalette.Divider}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
return layout.Dimensions{Size: size}
}