Add direct remote sync shortcut
This commit is contained in:
@@ -2283,6 +2283,18 @@ func (u *ui) openSelectedVaultRemoteButtonLabel() string {
|
|||||||
return "Open Saved Remote"
|
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 {
|
func remoteBindingSuffix(baseURL, path, username string) string {
|
||||||
sum := sha256.Sum256([]byte(strings.TrimSpace(baseURL) + "\n" + strings.TrimSpace(path) + "\n" + strings.TrimSpace(username)))
|
sum := sha256.Sum256([]byte(strings.TrimSpace(baseURL) + "\n" + strings.TrimSpace(path) + "\n" + strings.TrimSpace(username)))
|
||||||
return hex.EncodeToString(sum[:8])
|
return hex.EncodeToString(sum[:8])
|
||||||
@@ -6244,6 +6256,7 @@ func (u *ui) pathBar(gtx layout.Context) layout.Dimensions {
|
|||||||
pathSource = append([]string{}, u.currentPath...)
|
pathSource = append([]string{}, u.currentPath...)
|
||||||
}
|
}
|
||||||
crumbs, indices := u.visibleBreadcrumbs(pathSource)
|
crumbs, indices := u.visibleBreadcrumbs(pathSource)
|
||||||
|
crumbBar := func(gtx layout.Context) layout.Dimensions {
|
||||||
return layout.Flex{Alignment: layout.Middle}.Layout(gtx, func() []layout.FlexChild {
|
return layout.Flex{Alignment: layout.Middle}.Layout(gtx, func() []layout.FlexChild {
|
||||||
children := make([]layout.FlexChild, 0, len(crumbs)*2)
|
children := make([]layout.FlexChild, 0, len(crumbs)*2)
|
||||||
for i, name := range crumbs {
|
for i, name := range crumbs {
|
||||||
@@ -6294,6 +6307,17 @@ func (u *ui) pathBar(gtx layout.Context) layout.Dimensions {
|
|||||||
}
|
}
|
||||||
return children
|
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) {
|
func (u *ui) visibleBreadcrumbs(displayPath []string) ([]string, []int) {
|
||||||
|
|||||||
@@ -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) {
|
func TestUISaveCurrentRemoteBindingActionPersistsBindingIntoVault(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user