Move sync menu state decisions out of renderers

This commit is contained in:
Joe Julian
2026-04-08 23:27:47 -07:00
parent 9660369851
commit 16f603ccba
3 changed files with 196 additions and 97 deletions
+15 -52
View File
@@ -2740,98 +2740,61 @@ func (u *ui) shouldShowSavedRemoteBindingSelectors() bool {
}
func (u *ui) savedRemoteBindingSummary() (profileLabel, credentialLabel, syncLabel string, ok bool) {
profile, ok := u.selectedVaultRemoteProfile()
if !ok {
return "", "", "", false
}
entry, ok := u.selectedVaultRemoteCredentialEntry()
if !ok {
return "", "", "", false
}
credentialLabel = entry.Title
if strings.TrimSpace(entry.Username) != "" {
credentialLabel += " · " + strings.TrimSpace(entry.Username)
}
syncLabel = "Sync manually when you choose Use Remote Sync."
if normalizeUISyncMode(u.selectedVaultRemoteSyncMode) == appstate.SyncModeAutomaticOnOpenSave {
syncLabel = "Syncs automatically on open and save."
}
return profile.Name, credentialLabel, syncLabel, true
summary := u.computeSavedRemoteBindingSummary()
return summary.profileLabel, summary.credentialLabel, summary.syncLabel, summary.ok
}
func (u *ui) savedRemoteBindingHeading() string {
if !u.shouldShowSavedRemoteBindingSelectors() {
return "Use this vault's saved remote sync target"
}
return "Use a saved remote profile from this vault"
return u.buildSyncMenuModel().savedBindingHeading()
}
func (u *ui) openSelectedVaultRemoteButtonLabel() string {
if !u.shouldShowSavedRemoteBindingSelectors() {
return "Use Remote Sync"
}
return "Open Saved Remote"
return u.buildSyncMenuModel().openSelectedButtonLabel()
}
func (u *ui) shouldShowDirectRemoteSyncShortcut() bool {
if !u.hasOpenVault() || u.isVaultLocked() || u.state.Section != appstate.SectionEntries {
return false
}
_, ok := u.selectedVaultRemoteBinding()
return ok
return u.buildSyncMenuModel().showDirectRemoteSyncShortcut()
}
func (u *ui) directRemoteSyncShortcutLabel() string {
return "Use Remote Sync"
return u.buildSyncMenuModel().directRemoteSyncShortcutLabel()
}
func (u *ui) shouldShowRemoteSyncSettingsShortcut() bool {
if !u.hasOpenVault() || u.isVaultLocked() || u.state.Section != appstate.SectionEntries {
return false
}
_, ok := u.selectedVaultRemoteBinding()
return ok
return u.buildSyncMenuModel().showRemoteSyncSettingsShortcut()
}
func (u *ui) remoteSyncSettingsShortcutLabel() string {
return "Remote Sync Settings"
return u.buildSyncMenuModel().remoteSyncSettingsShortcutLabel()
}
func (u *ui) shouldShowRemoveRemoteSyncShortcut() bool {
return u.shouldShowRemoteSyncSettingsShortcut()
return u.buildSyncMenuModel().showRemoveRemoteSyncShortcut()
}
func (u *ui) removeRemoteSyncShortcutLabel() string {
return "Stop Using Remote Sync"
return u.buildSyncMenuModel().removeRemoteSyncShortcutLabel()
}
func (u *ui) shouldShowRemoteSyncSetupShortcut() bool {
if !u.hasOpenVault() || u.isVaultLocked() || u.state.Section != appstate.SectionEntries {
return false
}
_, ok := u.selectedVaultRemoteBinding()
return !ok
return u.buildSyncMenuModel().showRemoteSyncSetupShortcut()
}
func (u *ui) remoteSyncSetupShortcutLabel() string {
return "Set Up Remote Sync"
return u.buildSyncMenuModel().remoteSyncSetupShortcutLabel()
}
func (u *ui) syncMenuActionLabels() []string {
labels := []string{"Open Advanced Sync"}
if u.shouldShowRemoteSyncSetupShortcut() {
labels = append(labels, u.remoteSyncSetupShortcutLabel())
}
if u.shouldShowDirectRemoteSyncShortcut() {
labels = append(labels, u.directRemoteSyncShortcutLabel())
}
if u.shouldShowRemoteSyncSettingsShortcut() {
labels = append(labels, u.remoteSyncSettingsShortcutLabel())
}
if u.shouldShowRemoveRemoteSyncShortcut() {
labels = append(labels, u.removeRemoteSyncShortcutLabel())
}
return labels
return u.buildSyncMenuModel().actionLabels()
}
func remoteBindingSuffix(baseURL, path, username string) string {
@@ -2939,11 +2902,11 @@ func (u *ui) removeSelectedRemoteBindingAction() error {
}
func (u *ui) saveCurrentRemoteBindingHeading() string {
return "Bind this local vault to the current remote target"
return u.buildSyncMenuModel().saveCurrentRemoteBindingHeading()
}
func (u *ui) saveCurrentRemoteBindingButtonLabel() string {
return "Save Remote In Vault"
return u.buildSyncMenuModel().saveCurrentRemoteBindingButtonLabel()
}
func (u *ui) materializeCurrentRemoteCache() error {