diff --git a/internal/cli/cmd_edit.go b/internal/cli/cmd_edit.go index 454500e..1b4ad99 100644 --- a/internal/cli/cmd_edit.go +++ b/internal/cli/cmd_edit.go @@ -3,6 +3,7 @@ package cli import ( "fmt" "os" + "time" "lucor.dev/paw/internal/paw" ) @@ -88,6 +89,8 @@ func (cmd *EditCmd) Run(s paw.Storage) error { return fmt.Errorf("unsupported item type: %q", cmd.itemType) } + item.GetMetadata().Modified = time.Now() + err = s.StoreItem(vault, item) if err != nil { return err diff --git a/internal/cli/cmd_show.go b/internal/cli/cmd_show.go index db3445a..2aa6419 100644 --- a/internal/cli/cmd_show.go +++ b/internal/cli/cmd_show.go @@ -122,8 +122,8 @@ func (cmd *ShowCmd) Run(s paw.Storage) error { fmt.Printf("Note: %s\n", v.Value) } - fmt.Printf("Created: %s\n", item.GetMetadata().Created.Format(time.RFC1123)) fmt.Printf("Modified: %s\n", item.GetMetadata().Modified.Format(time.RFC1123)) + fmt.Printf("Created: %s\n", item.GetMetadata().Created.Format(time.RFC1123)) if pclip != nil { ctx, cancel := context.WithTimeout(context.Background(), clipboardWriteTimeout) diff --git a/internal/paw/item_metadata.go b/internal/paw/item_metadata.go index dee908e..72e786a 100644 --- a/internal/paw/item_metadata.go +++ b/internal/paw/item_metadata.go @@ -34,6 +34,10 @@ func (m *Metadata) GetMetadata() *Metadata { return m } +func (m *Metadata) IsEmpty() bool { + return m.Name == "" +} + func (m *Metadata) String() string { return m.Name } diff --git a/internal/ui/vault_view.go b/internal/ui/vault_view.go index 6f82544..478c82a 100644 --- a/internal/ui/vault_view.go +++ b/internal/ui/vault_view.go @@ -11,6 +11,7 @@ import ( "strings" "sync" "sync/atomic" + "time" "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" @@ -326,8 +327,10 @@ func (vw *vaultView) editItemView(ctx context.Context, fyneItem FyneItem) fyne.C var reloadItems bool var isNew bool - if metadata.Created == metadata.Modified { + if item.GetMetadata().IsEmpty() { isNew = true + } else { + metadata.Modified = time.Now() } if isNew && vw.vault.HasItem(editItem) {