Move app UI package under internal/appui
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
package appui
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"git.julianfamily.org/keepassgo/appstate"
|
||||
)
|
||||
|
||||
type syncMenuModel struct {
|
||||
hasOpenVault bool
|
||||
hasSelectedBinding bool
|
||||
showSelectors bool
|
||||
showShare bool
|
||||
showSaveCurrentBinding bool
|
||||
savedBindingSummary syncMenuBindingSummary
|
||||
remoteBaseURL string
|
||||
remotePath string
|
||||
remoteUsername string
|
||||
remotePassword string
|
||||
selectedVaultSyncMode appstate.SyncMode
|
||||
}
|
||||
|
||||
type syncMenuBindingSummary struct {
|
||||
profileLabel string
|
||||
credentialLabel string
|
||||
syncLabel string
|
||||
ok bool
|
||||
}
|
||||
|
||||
func (u *ui) buildSyncMenuModel() syncMenuModel {
|
||||
model := syncMenuModel{
|
||||
hasOpenVault: u.hasOpenVault(),
|
||||
showSelectors: u.shouldShowSavedRemoteBindingSelectors(),
|
||||
showShare: supportsVaultShare(runtime.GOOS) && u.vaultSharer != nil && strings.TrimSpace(u.currentShareableVaultPath()) != "",
|
||||
remoteBaseURL: strings.TrimSpace(u.remoteBaseURL.Text()),
|
||||
remotePath: strings.TrimSpace(u.remotePath.Text()),
|
||||
remoteUsername: strings.TrimSpace(u.remoteUsername.Text()),
|
||||
remotePassword: u.remotePassword.Text(),
|
||||
selectedVaultSyncMode: normalizeUISyncMode(u.selectedVaultRemoteSyncMode),
|
||||
}
|
||||
_, model.hasSelectedBinding = u.selectedVaultRemoteBinding()
|
||||
model.savedBindingSummary = u.computeSavedRemoteBindingSummary()
|
||||
model.showSaveCurrentBinding = model.hasOpenVault && model.remoteBaseURL != "" && model.remotePath != "" && model.remoteUsername != "" && model.remotePassword != ""
|
||||
return model
|
||||
}
|
||||
|
||||
func (u *ui) computeSavedRemoteBindingSummary() syncMenuBindingSummary {
|
||||
profile, ok := u.selectedVaultRemoteProfile()
|
||||
if !ok {
|
||||
return syncMenuBindingSummary{}
|
||||
}
|
||||
entry, ok := u.selectedVaultRemoteCredentialEntry()
|
||||
if !ok {
|
||||
return syncMenuBindingSummary{}
|
||||
}
|
||||
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 syncMenuBindingSummary{
|
||||
profileLabel: profile.Name,
|
||||
credentialLabel: credentialLabel,
|
||||
syncLabel: syncLabel,
|
||||
ok: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (m syncMenuModel) 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 syncMenuModel) openSelectedButtonLabel() string {
|
||||
if !m.showSelectors {
|
||||
return "Use Remote Sync"
|
||||
}
|
||||
return "Open Saved Remote"
|
||||
}
|
||||
|
||||
func (m syncMenuModel) showDirectRemoteSyncShortcut() bool {
|
||||
return m.hasOpenVault && m.hasSelectedBinding
|
||||
}
|
||||
|
||||
func (m syncMenuModel) directRemoteSyncShortcutLabel() string {
|
||||
return "Use Remote Sync"
|
||||
}
|
||||
|
||||
func (m syncMenuModel) showRemoteSyncSettingsShortcut() bool {
|
||||
return m.hasOpenVault && m.hasSelectedBinding
|
||||
}
|
||||
|
||||
func (m syncMenuModel) remoteSyncSettingsShortcutLabel() string {
|
||||
return "Remote Sync Settings"
|
||||
}
|
||||
|
||||
func (m syncMenuModel) showRemoveRemoteSyncShortcut() bool {
|
||||
return m.showRemoteSyncSettingsShortcut()
|
||||
}
|
||||
|
||||
func (m syncMenuModel) removeRemoteSyncShortcutLabel() string {
|
||||
return "Stop Using Remote Sync"
|
||||
}
|
||||
|
||||
func (m syncMenuModel) showRemoteSyncSetupShortcut() bool {
|
||||
return m.hasOpenVault && !m.hasSelectedBinding
|
||||
}
|
||||
|
||||
func (m syncMenuModel) remoteSyncSetupShortcutLabel() string {
|
||||
return "Set Up Remote Sync"
|
||||
}
|
||||
|
||||
func (m syncMenuModel) 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 syncMenuModel) saveCurrentRemoteBindingHeading() string {
|
||||
return "Bind this local vault to the current remote target"
|
||||
}
|
||||
|
||||
func (m syncMenuModel) saveCurrentRemoteBindingButtonLabel() string {
|
||||
return "Save Remote In Vault"
|
||||
}
|
||||
Reference in New Issue
Block a user