Add session mode: signing in and adding to the cart.
With cart_mode = "session", dibs signs in to the shop's account and puts an item in the cart when it fires. The account's cookies are kept apart from the watcher's and stored encrypted, with the key in the OS keyring. Without a keyring, they're stored in a file only you can read. An alert now goes out right away, without a cart link, and a second one follows once the item is in the cart. If adding fails, the second alert carries the cart link instead. Amazon only accepts additions its page scripts have seen, so plugins can now press a button in headless Chrome with ctx:click. The TUI asks for one-time codes and shows the plugin's warning about account locks in a modal. 'dibs login' signs in from a terminal, or with --browser in a Chrome window, and 'dibs logout' deletes the cookies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e2cbc1a55c
commit
15a34e1f84
39 files changed
+3529
-163
No files matched your search
@@ -50,6 +50,17 @@ type CheckMsg struct {
|
||||
PriceErr error
|
||||
}
|
||||
|
||||
// CartMsg is the outcome of adding an item to the cart in session mode.
|
||||
type CartMsg struct {
|
||||
Item string
|
||||
// URL is the URL as configured.
|
||||
URL string
|
||||
// Link is the cart page, or the cart link when adding failed. It is
|
||||
// what enter opens from now on.
|
||||
Link string
|
||||
Err error
|
||||
}
|
||||
|
||||
type (
|
||||
tickMsg time.Time
|
||||
logMsg LogLine
|
||||
@@ -109,6 +120,7 @@ type Model struct {
|
||||
noteTime time.Time
|
||||
reloading bool
|
||||
solving string // the host whose bot check is open in a browser
|
||||
modal *modal
|
||||
}
|
||||
|
||||
// New returns the TUI for ctl. path is the config file, and logs is the
|
||||
@@ -172,13 +184,50 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.rows = m.ctl.Statuses()
|
||||
case openMsg:
|
||||
if msg.err != nil { m.setNote("cannot open the browser: "+msg.err.Error(), true) } else { m.setNote("opened "+msg.url, false) }
|
||||
case CartMsg:
|
||||
m.carted(msg)
|
||||
case promptMsg:
|
||||
if m.modal != nil { m.answer(promptReply{}) }
|
||||
|
||||
var cmd tea.Cmd
|
||||
m.modal, cmd = newModal(msg)
|
||||
return m, tea.Batch(cmd, tea.Raw("\a"))
|
||||
case closePromptMsg:
|
||||
if m.modal != nil && m.modal.msg.id == msg.id { m.modal = nil }
|
||||
case tea.KeyPressMsg:
|
||||
if m.modal != nil { return m, m.modalKey(msg) }
|
||||
|
||||
return m, m.key(msg)
|
||||
default:
|
||||
// The modal's cursor blinks.
|
||||
if m.modal != nil {
|
||||
var cmd tea.Cmd
|
||||
m.modal.input, cmd = m.modal.input.Update(msg)
|
||||
return m, cmd
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// carted records the outcome of adding an item to the cart.
|
||||
func (m *Model) carted(c CartMsg) {
|
||||
r := m.results[c.URL]
|
||||
if r == nil {
|
||||
r = &result{}
|
||||
m.results[c.URL] = r
|
||||
}
|
||||
|
||||
r.cartLink = c.Link
|
||||
|
||||
if c.Err != nil {
|
||||
m.setNote("adding "+c.Item+" to the cart failed: "+c.Err.Error(), true)
|
||||
return
|
||||
}
|
||||
|
||||
m.setNote(c.Item+" is in the cart: press enter on its row and finish checkout", false)
|
||||
}
|
||||
|
||||
// checked records a check. A new alert flashes its row and rings the bell.
|
||||
func (m *Model) checked(c CheckMsg) tea.Cmd {
|
||||
r := m.results[c.Result.URL]
|
||||
|
||||
Reference in new issue
Block a user