Implement unsafe icon cache diagnostics (T-611)
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
"softbox.local/core/application"
|
||||
)
|
||||
|
||||
const unsafeIconCacheMessage = "检测到不安全的图标缓存项。该缓存项未被使用,本次请求没有继续远端获取或自动修复。请完全退出 SoftBox 后,按故障排查文档由管理员人工处理。"
|
||||
|
||||
func (shell *AppShell) layoutDetail(
|
||||
gtx layout.Context,
|
||||
theme *material.Theme,
|
||||
@@ -41,6 +43,9 @@ func (shell *AppShell) layoutDetail(
|
||||
}),
|
||||
)
|
||||
}),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return shell.layoutUnsafeIconCacheFailure(gtx, theme, item.ID)
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Height: unit.Dp(10)}.Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
@@ -118,6 +123,59 @@ func (shell *AppShell) layoutDetail(
|
||||
)
|
||||
}
|
||||
|
||||
func (shell *AppShell) layoutUnsafeIconCacheFailure(
|
||||
gtx layout.Context,
|
||||
theme *material.Theme,
|
||||
appID string,
|
||||
) layout.Dimensions {
|
||||
failure, exists := shell.iconFailures[appID]
|
||||
if !exists || failure.Code != application.IconFailureUnsafe ||
|
||||
failure.Identity.AppID != appID {
|
||||
return layout.Dimensions{}
|
||||
}
|
||||
return layout.Inset{Top: unit.Dp(8)}.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
return outlinedPanel(
|
||||
gtx,
|
||||
shellColors.destructive,
|
||||
shellColors.surface,
|
||||
unit.Dp(6),
|
||||
layout.UniformInset(unit.Dp(10)),
|
||||
func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Flex{Axis: layout.Vertical}.Layout(
|
||||
gtx,
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
title := material.Body1(theme, "图标缓存安全警告")
|
||||
title.Color = shellColors.destructive
|
||||
return title.Layout(gtx)
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Height: unit.Dp(3)}.Layout),
|
||||
layout.Rigid(material.Body2(theme, unsafeIconCacheMessage).Layout),
|
||||
layout.Rigid(layout.Spacer{Height: unit.Dp(4)}.Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
diagnostic := material.Caption(theme, unsafeIconCacheDiagnostic(failure))
|
||||
diagnostic.Color = shellColors.secondary
|
||||
return diagnostic.Layout(gtx)
|
||||
}),
|
||||
)
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func unsafeIconCacheDiagnostic(failure iconFailureState) string {
|
||||
return fmt.Sprintf(
|
||||
"诊断码:%s\n应用 ID:%s\n缓存定位符:%s",
|
||||
failure.Code,
|
||||
failure.Identity.AppID,
|
||||
unsafeIconCacheLocator(failure.Identity),
|
||||
)
|
||||
}
|
||||
|
||||
func unsafeIconCacheLocator(identity application.IconEventIdentity) string {
|
||||
digest := strings.TrimPrefix(identity.Reference, "sha256:")
|
||||
return fmt.Sprintf("%s-%d.icon", digest, identity.DPI)
|
||||
}
|
||||
|
||||
func detailField(
|
||||
gtx layout.Context,
|
||||
theme *material.Theme,
|
||||
|
||||
Reference in New Issue
Block a user