Add remote sync removal flow
This commit is contained in:
@@ -296,6 +296,7 @@ type ui struct {
|
||||
useSavedAdvancedSyncRemote widget.Clickable
|
||||
openSelectedVaultRemote widget.Clickable
|
||||
saveCurrentRemoteBinding widget.Clickable
|
||||
removeSelectedRemoteBinding widget.Clickable
|
||||
openSecuritySettings widget.Clickable
|
||||
openRemotePrefsHelp widget.Clickable
|
||||
closeAdvancedSync widget.Clickable
|
||||
@@ -2646,6 +2647,14 @@ func (u *ui) remoteSyncSettingsShortcutLabel() string {
|
||||
return "Remote Sync Settings"
|
||||
}
|
||||
|
||||
func (u *ui) shouldShowRemoveRemoteSyncShortcut() bool {
|
||||
return u.shouldShowRemoteSyncSettingsShortcut()
|
||||
}
|
||||
|
||||
func (u *ui) removeRemoteSyncShortcutLabel() string {
|
||||
return "Stop Using Remote Sync"
|
||||
}
|
||||
|
||||
func (u *ui) shouldShowRemoteSyncSetupShortcut() bool {
|
||||
if !u.hasOpenVault() || u.isVaultLocked() || u.state.Section != appstate.SectionEntries {
|
||||
return false
|
||||
@@ -2719,6 +2728,49 @@ func (u *ui) saveCurrentRemoteBindingAction() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *ui) stripRecentRemoteBinding(binding appstate.RemoteBinding) {
|
||||
localPath := strings.TrimSpace(binding.LocalVaultPath)
|
||||
profileID := strings.TrimSpace(binding.RemoteProfileID)
|
||||
credentialID := strings.TrimSpace(binding.CredentialEntryID)
|
||||
for i := range u.recentRemotes {
|
||||
record := &u.recentRemotes[i]
|
||||
if strings.TrimSpace(record.LocalVaultPath) != localPath {
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(record.RemoteProfileID) != profileID {
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(record.CredentialEntryID) != credentialID {
|
||||
continue
|
||||
}
|
||||
record.LocalVaultPath = ""
|
||||
record.RemoteProfileID = ""
|
||||
record.CredentialEntryID = ""
|
||||
record.SyncMode = ""
|
||||
}
|
||||
}
|
||||
|
||||
func (u *ui) removeSelectedRemoteBindingAction() error {
|
||||
binding, ok := u.selectedVaultRemoteBinding()
|
||||
if !ok {
|
||||
return fmt.Errorf("no saved remote sync target is selected")
|
||||
}
|
||||
if err := u.state.RemoveRemoteBinding(binding); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := u.state.Save(); err != nil {
|
||||
return err
|
||||
}
|
||||
u.stripRecentRemoteBinding(binding)
|
||||
u.selectedVaultRemoteProfileID = ""
|
||||
u.selectedVaultRemoteCredentialEntryID = ""
|
||||
u.selectedVaultRemoteSyncMode = appstate.SyncModeManual
|
||||
u.remoteUsername.SetText("")
|
||||
u.remotePassword.SetText("")
|
||||
u.showStatusMessage("Remote sync is no longer set up for this vault.")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *ui) saveCurrentRemoteBindingHeading() string {
|
||||
return "Bind this local vault to the current remote target"
|
||||
}
|
||||
@@ -4291,6 +4343,9 @@ func (u *ui) layout(gtx layout.Context) layout.Dimensions {
|
||||
for u.saveCurrentRemoteBinding.Clicked(gtx) {
|
||||
u.runAction("save remote binding", u.saveCurrentRemoteBindingAction)
|
||||
}
|
||||
for u.removeSelectedRemoteBinding.Clicked(gtx) {
|
||||
u.runAction("remove remote sync binding", u.removeSelectedRemoteBindingAction)
|
||||
}
|
||||
for u.shareCurrentVault.Clicked(gtx) {
|
||||
u.runAction("share vault", u.shareCurrentVaultAction)
|
||||
}
|
||||
@@ -6857,7 +6912,7 @@ func (u *ui) pathBar(gtx layout.Context) layout.Dimensions {
|
||||
return children
|
||||
}()...)
|
||||
}
|
||||
if !u.shouldShowDirectRemoteSyncShortcut() && !u.shouldShowRemoteSyncSetupShortcut() && !u.shouldShowRemoteSyncSettingsShortcut() {
|
||||
if !u.shouldShowDirectRemoteSyncShortcut() && !u.shouldShowRemoteSyncSetupShortcut() && !u.shouldShowRemoteSyncSettingsShortcut() && !u.shouldShowRemoveRemoteSyncShortcut() {
|
||||
return crumbBar(gtx)
|
||||
}
|
||||
children := []layout.FlexChild{
|
||||
@@ -6885,6 +6940,14 @@ func (u *ui) pathBar(gtx layout.Context) layout.Dimensions {
|
||||
return tonedButton(gtx, u.theme, &u.useSavedAdvancedSyncRemote, u.remoteSyncSettingsShortcutLabel())
|
||||
}))
|
||||
}
|
||||
if u.shouldShowRemoveRemoteSyncShortcut() {
|
||||
if u.shouldShowDirectRemoteSyncShortcut() || u.shouldShowRemoteSyncSetupShortcut() || u.shouldShowRemoteSyncSettingsShortcut() {
|
||||
children = append(children, layout.Rigid(layout.Spacer{Height: unit.Dp(6)}.Layout))
|
||||
}
|
||||
children = append(children, layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return tonedButton(gtx, u.theme, &u.removeSelectedRemoteBinding, u.removeRemoteSyncShortcutLabel())
|
||||
}))
|
||||
}
|
||||
return layout.Flex{Axis: layout.Vertical}.Layout(gtx, children...)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user