Add direct remote sync shortcut

This commit is contained in:
Joe Julian
2026-04-06 17:29:23 -07:00
parent 839cc6cc1c
commit 8b4f3f91be
2 changed files with 116 additions and 46 deletions
+24
View File
@@ -2283,6 +2283,18 @@ func (u *ui) openSelectedVaultRemoteButtonLabel() string {
return "Open Saved Remote"
}
func (u *ui) shouldShowDirectRemoteSyncShortcut() bool {
if !u.hasOpenVault() || u.isVaultLocked() || u.state.Section != appstate.SectionEntries {
return false
}
_, ok := u.selectedVaultRemoteBinding()
return ok
}
func (u *ui) directRemoteSyncShortcutLabel() string {
return "Use Remote Sync"
}
func remoteBindingSuffix(baseURL, path, username string) string {
sum := sha256.Sum256([]byte(strings.TrimSpace(baseURL) + "\n" + strings.TrimSpace(path) + "\n" + strings.TrimSpace(username)))
return hex.EncodeToString(sum[:8])
@@ -6244,6 +6256,7 @@ func (u *ui) pathBar(gtx layout.Context) layout.Dimensions {
pathSource = append([]string{}, u.currentPath...)
}
crumbs, indices := u.visibleBreadcrumbs(pathSource)
crumbBar := func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Alignment: layout.Middle}.Layout(gtx, func() []layout.FlexChild {
children := make([]layout.FlexChild, 0, len(crumbs)*2)
for i, name := range crumbs {
@@ -6295,6 +6308,17 @@ func (u *ui) pathBar(gtx layout.Context) layout.Dimensions {
return children
}()...)
}
if !u.shouldShowDirectRemoteSyncShortcut() {
return crumbBar(gtx)
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(crumbBar),
layout.Rigid(layout.Spacer{Height: unit.Dp(6)}.Layout),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return tonedButton(gtx, u.theme, &u.openSelectedVaultRemote, u.directRemoteSyncShortcutLabel())
}),
)
}
func (u *ui) visibleBreadcrumbs(displayPath []string) ([]string, []int) {
if u.state.Section == appstate.SectionTemplates {
+46
View File
@@ -5422,6 +5422,52 @@ func TestUIOpenSelectedVaultRemoteButtonLabelUsesSavedRemoteLanguageForMultipleC
}
}
func TestUIShouldShowDirectRemoteSyncShortcutForSavedBinding(t *testing.T) {
t.Parallel()
u := newUIWithModel("desktop", vault.Model{
Entries: []vault.Entry{{
ID: "remote-creds-1",
Title: "WebDAV Sign-In",
Username: "tjulian",
Path: []string{"Crew", "Internet"},
}},
RemoteProfiles: []vault.RemoteProfile{{
ID: "family-webdav",
Name: "Family Vault",
Backend: vault.RemoteBackendWebDAV,
BaseURL: "https://dav.example.invalid/remote.php/dav",
Path: "files/family/keepass.kdbx",
}},
})
u.state.Section = appstate.SectionEntries
if !u.shouldShowDirectRemoteSyncShortcut() {
t.Fatal("shouldShowDirectRemoteSyncShortcut() = false, want true for an opened vault with a saved remote binding")
}
}
func TestUIShouldHideDirectRemoteSyncShortcutWithoutSavedBinding(t *testing.T) {
t.Parallel()
u := newUIWithModel("desktop", vault.Model{})
u.state.Section = appstate.SectionEntries
if u.shouldShowDirectRemoteSyncShortcut() {
t.Fatal("shouldShowDirectRemoteSyncShortcut() = true, want false without a saved remote binding")
}
}
func TestUIDirectRemoteSyncShortcutLabelUsesSyncLanguage(t *testing.T) {
t.Parallel()
u := newUIWithSession("desktop", &session.Manager{})
if got := u.directRemoteSyncShortcutLabel(); got != "Use Remote Sync" {
t.Fatalf("directRemoteSyncShortcutLabel() = %q, want Use Remote Sync", got)
}
}
func TestUISaveCurrentRemoteBindingActionPersistsBindingIntoVault(t *testing.T) {
t.Parallel()