Handle local-open remote sync fallback
This commit is contained in:
@@ -1052,7 +1052,7 @@ func (u *ui) openVaultAction() error {
|
||||
u.restoreRecentVaultGroup(path)
|
||||
u.syncSavedRemoteBindingSelection()
|
||||
if err := u.synchronizeSelectedRemoteBindingOnOpen(); err != nil {
|
||||
return err
|
||||
u.showStatusMessage("Remote sync on open failed: " + err.Error())
|
||||
}
|
||||
u.loadSecuritySettingsFromSession()
|
||||
u.editingEntry = false
|
||||
@@ -1093,7 +1093,7 @@ func (u *ui) startOpenVaultAction() {
|
||||
u.restoreRecentVaultGroup(path)
|
||||
u.syncSavedRemoteBindingSelection()
|
||||
if err := u.synchronizeSelectedRemoteBindingOnOpen(); err != nil {
|
||||
return err
|
||||
u.showStatusMessage("Remote sync on open failed: " + err.Error())
|
||||
}
|
||||
u.loadSecuritySettingsFromSession()
|
||||
u.editingEntry = false
|
||||
@@ -2309,6 +2309,17 @@ func (u *ui) syncSavedRemoteBindingSelection() {
|
||||
if strings.TrimSpace(u.selectedVaultRemoteCredentialEntryID) == "" && len(entries) == 1 {
|
||||
u.selectedVaultRemoteCredentialEntryID = entries[0].ID
|
||||
}
|
||||
if strings.TrimSpace(u.selectedVaultRemoteProfileID) == "" || strings.TrimSpace(u.selectedVaultRemoteCredentialEntryID) == "" {
|
||||
if record, ok := u.boundRecentRemoteForLocalVault(strings.TrimSpace(u.vaultPath.Text())); ok {
|
||||
u.selectedVaultRemoteProfileID = strings.TrimSpace(record.RemoteProfileID)
|
||||
u.selectedVaultRemoteCredentialEntryID = strings.TrimSpace(record.CredentialEntryID)
|
||||
u.selectedVaultRemoteSyncMode = normalizeUISyncMode(appstate.SyncMode(record.SyncMode))
|
||||
if profile, ok := u.selectedVaultRemoteProfile(); ok {
|
||||
u.remoteBaseURL.SetText(profile.BaseURL)
|
||||
u.remotePath.SetText(profile.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
if binding, ok := u.selectedVaultRemoteBinding(); ok {
|
||||
for _, record := range u.recentRemotes {
|
||||
if strings.TrimSpace(record.LocalVaultPath) != strings.TrimSpace(binding.LocalVaultPath) {
|
||||
@@ -2327,6 +2338,27 @@ func (u *ui) syncSavedRemoteBindingSelection() {
|
||||
u.selectedVaultRemoteSyncMode = appstate.SyncModeManual
|
||||
}
|
||||
|
||||
func (u *ui) boundRecentRemoteForLocalVault(path string) (recentRemoteRecord, bool) {
|
||||
path = strings.TrimSpace(path)
|
||||
if path == "" {
|
||||
return recentRemoteRecord{}, false
|
||||
}
|
||||
var matches []recentRemoteRecord
|
||||
for _, record := range u.recentRemotes {
|
||||
if strings.TrimSpace(record.LocalVaultPath) != path {
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(record.RemoteProfileID) == "" || strings.TrimSpace(record.CredentialEntryID) == "" {
|
||||
continue
|
||||
}
|
||||
matches = append(matches, record)
|
||||
}
|
||||
if len(matches) != 1 {
|
||||
return recentRemoteRecord{}, false
|
||||
}
|
||||
return matches[0], true
|
||||
}
|
||||
|
||||
func (u *ui) shouldShowSavedRemoteBindingSelectors() bool {
|
||||
profiles := u.availableRemoteProfiles()
|
||||
entries := u.availableRemoteCredentialEntries()
|
||||
@@ -7094,5 +7126,19 @@ func runFilePicker(name string, args ...string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(string(output)), nil
|
||||
return parsePickedFilePath(output)
|
||||
}
|
||||
|
||||
func parsePickedFilePath(output []byte) (string, error) {
|
||||
lines := strings.Split(strings.ReplaceAll(string(output), "\r\n", "\n"), "\n")
|
||||
for i := len(lines) - 1; i >= 0; i-- {
|
||||
line := strings.TrimSpace(lines[i])
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(line, "/") || strings.HasPrefix(line, "~/") {
|
||||
return line, nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("file picker did not return a path")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user