On subscribes to all session lifecycle events. Lifecycle events are emitted when sessions are created, deleted, updated, or change foreground/background state (in TUI+server mode). Returns a function that, when called, unsubscribes the handler. Example: unsubscribe := client.On(func(event copil
(handler SessionLifecycleHandler)
| 1454 | // }) |
| 1455 | // defer unsubscribe() |
| 1456 | func (c *Client) On(handler SessionLifecycleHandler) func() { |
| 1457 | c.lifecycleHandlersMux.Lock() |
| 1458 | if c.lifecycleHandlers == nil { |
| 1459 | c.lifecycleHandlers = make(map[uint64]SessionLifecycleHandler) |
| 1460 | } |
| 1461 | c.nextLifecycleHandlerID++ |
| 1462 | id := c.nextLifecycleHandlerID |
| 1463 | c.lifecycleHandlers[id] = handler |
| 1464 | c.lifecycleHandlersMux.Unlock() |
| 1465 | |
| 1466 | return func() { |
| 1467 | c.lifecycleHandlersMux.Lock() |
| 1468 | defer c.lifecycleHandlersMux.Unlock() |
| 1469 | delete(c.lifecycleHandlers, id) |
| 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | // OnEventType subscribes to a specific session lifecycle event type. |
| 1474 | // |
no outgoing calls