Ink-away.koplugin
Public API

onAnnotationClosed

Run a callback when the annotation editor closes.

Use this to restore your plugin's state after annotation ends. No viewer or surface registration is required.

local stop = ink:onAnnotationClosed(function(event)
    self.annotation_open = false
    self.last_annotation_document = event.document
end)

-- When your plugin disconnects:
stop()

Arguments

NameTypeMeaning
callbackfunctionReceives {document, surface} after the session's cleanup attempts. Its return value is ignored.

document is the book's document object. surface is the final surface used by the session, or nil for the normal reader. It can differ from the opening surface after a viewer handoff.

Returns

An idempotent unsubscribe() function with no arguments or result.

Things to know

  • This is a closure notification, not proof that saving to disk succeeded.
  • It reports future closures only; it does not replay an earlier session.
  • Returning false cannot cancel closure. Listener errors are logged and isolated.
  • Invalid callback types and registration after reader closure raise a Lua assertion.
  • Independent listeners run in subscription order. Removing a listener during an event takes effect immediately; adding one takes effect on the next event. Treat each payload as read-only.

Use onAnnotationOpened to track the other end of the session. The event-only example shows both.

On this page