Add lifecycle remote sync shortcut
This commit is contained in:
@@ -114,6 +114,14 @@ type uiSurface struct {
|
||||
Locked bool
|
||||
}
|
||||
|
||||
type lifecycleOpenIntent string
|
||||
|
||||
const (
|
||||
lifecycleOpenIntentNone lifecycleOpenIntent = ""
|
||||
lifecycleOpenIntentRemoteSyncSetup lifecycleOpenIntent = "remote_sync_setup"
|
||||
lifecycleOpenIntentRemoteSyncSettings lifecycleOpenIntent = "remote_sync_settings"
|
||||
)
|
||||
|
||||
type emptyState struct {
|
||||
Title string
|
||||
Body string
|
||||
@@ -285,6 +293,7 @@ type ui struct {
|
||||
unlockVault widget.Clickable
|
||||
createVault widget.Clickable
|
||||
openVault widget.Clickable
|
||||
lifecycleRemoteSyncAction widget.Clickable
|
||||
saveVault widget.Clickable
|
||||
saveAsVault widget.Clickable
|
||||
openRemote widget.Clickable
|
||||
@@ -506,6 +515,7 @@ type ui struct {
|
||||
backgroundActionSerial int
|
||||
activeBackgroundAction int
|
||||
lastLifecycleAction string
|
||||
pendingLifecycleOpenIntent lifecycleOpenIntent
|
||||
requestMasterPassFocus bool
|
||||
invalidate func()
|
||||
}
|
||||
@@ -1070,6 +1080,7 @@ func (u *ui) openVaultAction() error {
|
||||
u.loadSecuritySettingsFromSession()
|
||||
u.editingEntry = false
|
||||
u.filter()
|
||||
u.applyPendingLifecycleOpenIntent()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1111,11 +1122,49 @@ func (u *ui) startOpenVaultAction() {
|
||||
u.loadSecuritySettingsFromSession()
|
||||
u.editingEntry = false
|
||||
u.filter()
|
||||
u.applyPendingLifecycleOpenIntent()
|
||||
return nil
|
||||
}, nil
|
||||
})
|
||||
}
|
||||
|
||||
func (u *ui) shouldShowLifecycleRemoteSyncAction() bool {
|
||||
return strings.TrimSpace(u.vaultPath.Text()) != ""
|
||||
}
|
||||
|
||||
func (u *ui) lifecycleRemoteSyncActionLabel() string {
|
||||
path := strings.TrimSpace(u.vaultPath.Text())
|
||||
if path == "" {
|
||||
return "Open Vault And Set Up Remote Sync"
|
||||
}
|
||||
if hasBoundRecentRemote(u.recentRemotes, path) {
|
||||
return "Open Vault And Open Remote Sync Settings"
|
||||
}
|
||||
return "Open Vault And Set Up Remote Sync"
|
||||
}
|
||||
|
||||
func (u *ui) beginLifecycleRemoteSyncOpen() {
|
||||
path := strings.TrimSpace(u.vaultPath.Text())
|
||||
switch {
|
||||
case path == "":
|
||||
u.pendingLifecycleOpenIntent = lifecycleOpenIntentNone
|
||||
case hasBoundRecentRemote(u.recentRemotes, path):
|
||||
u.pendingLifecycleOpenIntent = lifecycleOpenIntentRemoteSyncSettings
|
||||
default:
|
||||
u.pendingLifecycleOpenIntent = lifecycleOpenIntentRemoteSyncSetup
|
||||
}
|
||||
u.startOpenVaultAction()
|
||||
}
|
||||
|
||||
func (u *ui) applyPendingLifecycleOpenIntent() {
|
||||
intent := u.pendingLifecycleOpenIntent
|
||||
u.pendingLifecycleOpenIntent = lifecycleOpenIntentNone
|
||||
switch intent {
|
||||
case lifecycleOpenIntentRemoteSyncSetup, lifecycleOpenIntentRemoteSyncSettings:
|
||||
u.openRemoteSyncSetupDialog()
|
||||
}
|
||||
}
|
||||
|
||||
func (u *ui) saveAction() error {
|
||||
if err := u.state.Save(); err != nil {
|
||||
return err
|
||||
@@ -2568,8 +2617,17 @@ func (u *ui) boundRecentRemoteForLocalVault(path string) (recentRemoteRecord, bo
|
||||
if path == "" {
|
||||
return recentRemoteRecord{}, false
|
||||
}
|
||||
return boundRecentRemoteForLocalVaultRecords(u.recentRemotes, path)
|
||||
}
|
||||
|
||||
func hasBoundRecentRemote(records []recentRemoteRecord, path string) bool {
|
||||
_, ok := boundRecentRemoteForLocalVaultRecords(records, strings.TrimSpace(path))
|
||||
return ok
|
||||
}
|
||||
|
||||
func boundRecentRemoteForLocalVaultRecords(records []recentRemoteRecord, path string) (recentRemoteRecord, bool) {
|
||||
var matches []recentRemoteRecord
|
||||
for _, record := range u.recentRemotes {
|
||||
for _, record := range records {
|
||||
if strings.TrimSpace(record.LocalVaultPath) != path {
|
||||
continue
|
||||
}
|
||||
@@ -3982,6 +4040,12 @@ func (u *ui) layout(gtx layout.Context) layout.Dimensions {
|
||||
for u.openVault.Clicked(gtx) {
|
||||
u.startOpenVaultAction()
|
||||
}
|
||||
for u.lifecycleRemoteSyncAction.Clicked(gtx) {
|
||||
if u.lifecycleBusy() {
|
||||
continue
|
||||
}
|
||||
u.beginLifecycleRemoteSyncOpen()
|
||||
}
|
||||
for u.saveVault.Clicked(gtx) {
|
||||
u.runAction("save vault", u.saveAction)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user