Files
winauth-go/internal/ui/entry_ring.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

58 lines
1.6 KiB
Go

package ui
import (
"time"
"gioui.org/layout"
"gioui.org/unit"
"git.wxccs.org/iceking2nd/winauth-go/internal/authenticator"
)
// entryProgressRing draws the per-row TOTP countdown ring. For HOTP
// entries it returns a same-sized blank box so the rows still line up.
func entryProgressRing(gtx layout.Context, en *entry) layout.Dimensions {
const ringDp = 22
if en.Auth == nil || en.Auth.Name() == "hotp" {
return layout.Dimensions{Size: gtx.Constraints.Constrain(
layout.Spacer{Width: unit.Dp(ringDp), Height: unit.Dp(ringDp)}.Layout(gtx).Size,
)}
}
period := totpPeriod(en.Auth)
if period <= 0 {
period = authenticator.DefaultPeriod
}
now := time.Now().Unix()
elapsed := now % int64(period)
remaining := int64(period) - elapsed
progress := float32(remaining) / float32(period)
fg := activePalette.RingFg
if remaining <= 5 {
fg = activePalette.RingFgWarn
}
bg := activePalette.RingBg
return progressRing{
Size: unit.Dp(ringDp),
Stroke: unit.Dp(2.5),
Progress: progress,
Color: fg,
BgColor: bg,
}.Layout(gtx)
}
// totpPeriod extracts the configured period from any authenticator whose
// underlying Base we can reach. Returns 0 if the authenticator does not
// expose one (in which case callers fall back to the default).
func totpPeriod(a authenticator.Authenticator) int {
type periodGetter interface{ GetPeriod() int }
if pg, ok := a.(periodGetter); ok {
return pg.GetPeriod()
}
// All current TOTP-like authenticators (Google/Microsoft/Okta/Steam/
// BattleNet) embed authenticator.Base whose default period is 30s,
// matching the C# original. Hard-code that here.
return authenticator.DefaultPeriod
}