Tighten banner and navigation behavior

This commit is contained in:
Joe Julian
2026-03-29 21:16:38 -07:00
parent da769a9728
commit e5904dd224
4 changed files with 87 additions and 7 deletions
+54 -3
View File
@@ -41,7 +41,7 @@ const (
const (
maxAttachmentBytes = 10 << 20
statusBannerDuration = 4 * time.Second
statusBannerDuration = 2600 * time.Millisecond
)
type bannerKind string
@@ -79,6 +79,7 @@ type statePaths struct {
DefaultSaveAsPath string
RecentVaultsPath string
RecentRemotesPath string
UIPreferencesPath string
}
type recentVaultRecord struct {
@@ -94,6 +95,10 @@ type recentRemoteRecord struct {
LastGroup []string `json:"lastGroup,omitempty"`
}
type uiPreferences struct {
GroupControlsHidden bool `json:"groupControlsHidden"`
}
type ui struct {
mode string
theme *material.Theme
@@ -201,6 +206,7 @@ type ui struct {
keyboardFocus focusID
defaultSaveAsPath string
recentVaultsPath string
uiPreferencesPath string
recentRemotesPath string
editingEntry bool
groupControlsHidden bool
@@ -293,6 +299,7 @@ func newUIWithState(mode string, sess appstate.CurrentSession, paths statePaths)
lifecycleMode: "local",
defaultSaveAsPath: paths.DefaultSaveAsPath,
recentVaultsPath: paths.RecentVaultsPath,
uiPreferencesPath: paths.UIPreferencesPath,
recentRemotesPath: paths.RecentRemotesPath,
recentVaultGroups: map[string][]string{},
now: time.Now,
@@ -309,6 +316,7 @@ func newUIWithState(mode string, sess appstate.CurrentSession, paths statePaths)
u.setCustomFieldRows(nil)
u.loadRecentVaults()
u.loadRecentRemotes()
u.loadUIPreferences()
u.filter()
return u
}
@@ -342,6 +350,7 @@ func defaultStatePaths(stateDir string) statePaths {
DefaultSaveAsPath: filepath.Join(baseDir, "vault.kdbx"),
RecentVaultsPath: filepath.Join(baseDir, "recent-vaults.json"),
RecentRemotesPath: filepath.Join(baseDir, "recent-remotes.json"),
UIPreferencesPath: filepath.Join(baseDir, "ui-prefs.json"),
}
}
@@ -805,6 +814,37 @@ func (u *ui) saveRecentRemotes() {
_ = os.WriteFile(u.recentRemotesPath, content, 0o600)
}
func (u *ui) loadUIPreferences() {
if strings.TrimSpace(u.uiPreferencesPath) == "" {
return
}
content, err := os.ReadFile(u.uiPreferencesPath)
if err != nil {
return
}
var prefs uiPreferences
if err := json.Unmarshal(content, &prefs); err != nil {
return
}
u.groupControlsHidden = prefs.GroupControlsHidden
}
func (u *ui) saveUIPreferences() {
if strings.TrimSpace(u.uiPreferencesPath) == "" {
return
}
if err := os.MkdirAll(filepath.Dir(u.uiPreferencesPath), 0o700); err != nil {
return
}
content, err := json.MarshalIndent(uiPreferences{
GroupControlsHidden: u.groupControlsHidden,
}, "", " ")
if err != nil {
return
}
_ = os.WriteFile(u.uiPreferencesPath, content, 0o600)
}
func (u *ui) noteRecentRemote(baseURL, path, username, password string, rememberAuth bool) {
baseURL = strings.TrimSpace(baseURL)
path = strings.TrimSpace(path)
@@ -1398,6 +1438,7 @@ func (u *ui) layout(gtx layout.Context) layout.Dimensions {
}
for u.toggleGroupControls.Clicked(gtx) {
u.groupControlsHidden = !u.groupControlsHidden
u.saveUIPreferences()
}
for u.renameGroup.Clicked(gtx) {
u.clearDeleteGroupConfirmation()
@@ -1644,11 +1685,21 @@ func (u *ui) navigationHeader(gtx layout.Context) layout.Dimensions {
func (u *ui) sectionBar(gtx layout.Context) layout.Dimensions {
return layout.Flex{Spacing: layout.SpaceStart}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return tonedButton(gtx, u.theme, &u.showEntries, "Entries")
btn := material.Button(u.theme, &u.showEntries, "Entries")
btn.Background = accentColor
btn.Color = color.NRGBA{R: 255, G: 252, B: 247, A: 255}
btn.TextSize = unit.Sp(11)
btn.Inset = layout.Inset{Top: 5, Bottom: 5, Left: 9, Right: 9}
return btn.Layout(gtx)
}),
layout.Rigid(layout.Spacer{Width: unit.Dp(8)}.Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return tonedButton(gtx, u.theme, &u.showRecycle, "Recycle Bin")
btn := material.Button(u.theme, &u.showRecycle, "Recycle Bin")
btn.Background = accentColor
btn.Color = color.NRGBA{R: 255, G: 252, B: 247, A: 255}
btn.TextSize = unit.Sp(11)
btn.Inset = layout.Inset{Top: 5, Bottom: 5, Left: 9, Right: 9}
return btn.Layout(gtx)
}),
)
}