120 lines
3.2 KiB
Go
120 lines
3.2 KiB
Go
package sync
|
|
|
|
import "git.julianfamily.org/keepassgo/internal/appstate"
|
|
|
|
type SourceMode string
|
|
|
|
const (
|
|
SourceLocal SourceMode = "local"
|
|
SourceRemote SourceMode = "remote"
|
|
)
|
|
|
|
type Direction string
|
|
|
|
const (
|
|
DirectionPull Direction = "pull"
|
|
DirectionPush Direction = "push"
|
|
)
|
|
|
|
type DialogPurpose string
|
|
|
|
const (
|
|
DialogPurposeAdvanced DialogPurpose = "advanced"
|
|
DialogPurposeRemoteSetup DialogPurpose = "remote-setup"
|
|
)
|
|
|
|
type MenuModel struct {
|
|
HasOpenVault bool
|
|
HasSelectedBinding bool
|
|
ShowSelectors bool
|
|
ShowShare bool
|
|
ShowSaveCurrentBinding bool
|
|
SavedBindingSummary MenuBindingSummary
|
|
RemoteBaseURL string
|
|
RemotePath string
|
|
RemoteUsername string
|
|
RemotePassword string
|
|
SelectedVaultSyncMode appstate.SyncMode
|
|
}
|
|
|
|
type MenuBindingSummary struct {
|
|
ProfileLabel string
|
|
CredentialLabel string
|
|
SyncLabel string
|
|
OK bool
|
|
}
|
|
|
|
func (m MenuModel) SavedBindingHeading() string {
|
|
if !m.ShowSelectors {
|
|
return "Use this vault's saved remote sync target"
|
|
}
|
|
return "Use a saved remote profile from this vault"
|
|
}
|
|
|
|
func (m MenuModel) OpenSelectedButtonLabel() string {
|
|
if !m.ShowSelectors {
|
|
return "Use Remote Sync"
|
|
}
|
|
return "Open Saved Remote"
|
|
}
|
|
|
|
func (m MenuModel) ShowDirectRemoteSyncShortcut() bool {
|
|
return m.HasOpenVault && m.HasSelectedBinding
|
|
}
|
|
|
|
func (m MenuModel) DirectRemoteSyncShortcutLabel() string { return "Use Remote Sync" }
|
|
|
|
func (m MenuModel) ShowRemoteSyncSettingsShortcut() bool {
|
|
return m.HasOpenVault && m.HasSelectedBinding
|
|
}
|
|
|
|
func (m MenuModel) RemoteSyncSettingsShortcutLabel() string { return "Remote Sync Settings" }
|
|
|
|
func (m MenuModel) ShowRemoveRemoteSyncShortcut() bool { return m.ShowRemoteSyncSettingsShortcut() }
|
|
|
|
func (m MenuModel) RemoveRemoteSyncShortcutLabel() string { return "Stop Using Remote Sync" }
|
|
|
|
func (m MenuModel) ShowRemoteSyncSetupShortcut() bool {
|
|
return m.HasOpenVault && !m.HasSelectedBinding
|
|
}
|
|
|
|
func (m MenuModel) RemoteSyncSetupShortcutLabel() string { return "Set Up Remote Sync" }
|
|
|
|
func (m MenuModel) ActionLabels() []string {
|
|
labels := []string{"Open Advanced Sync"}
|
|
if m.ShowRemoteSyncSetupShortcut() {
|
|
labels = append(labels, m.RemoteSyncSetupShortcutLabel())
|
|
}
|
|
if m.ShowDirectRemoteSyncShortcut() {
|
|
labels = append(labels, m.DirectRemoteSyncShortcutLabel())
|
|
}
|
|
if m.ShowRemoteSyncSettingsShortcut() {
|
|
labels = append(labels, m.RemoteSyncSettingsShortcutLabel())
|
|
}
|
|
if m.ShowRemoveRemoteSyncShortcut() {
|
|
labels = append(labels, m.RemoveRemoteSyncShortcutLabel())
|
|
}
|
|
return labels
|
|
}
|
|
|
|
func (m MenuModel) SaveCurrentRemoteBindingHeading() string {
|
|
return "Bind this local vault to the current remote target"
|
|
}
|
|
|
|
func (m MenuModel) SaveCurrentRemoteBindingButtonLabel() string { return "Save Remote In Vault" }
|
|
|
|
func SummaryText(purpose DialogPurpose, source SourceMode, direction Direction) string {
|
|
if purpose == DialogPurposeRemoteSetup {
|
|
return "Push this local vault to a WebDAV target and save that target for future sync."
|
|
}
|
|
sourceLabel := "another local vault file"
|
|
if source == SourceRemote {
|
|
sourceLabel = "another WebDAV-backed vault"
|
|
}
|
|
action := "Pull changes from"
|
|
if direction == DirectionPush {
|
|
action = "Push the current vault into"
|
|
}
|
|
return action + " " + sourceLabel + "."
|
|
}
|