Ink-away.koplugin
Public API

installPluginIntegration

Connect a viewer and surface, with optional events, in one call.

Start here for a rendering consumer. This registers a surface provider and optional callbacks for that exact surface.

local cleanup = ink:installPluginIntegration(viewer_widget, surface, {
    on_open = function() self.annotation_open = true end,
    on_close = function() self.annotation_open = false end,
    on_error = function(err) self.last_error = tostring(err) end,
})

-- Before destroying your viewer:
cleanup()

Arguments

NameTypeMeaning
widgettableYour actual KOReader viewer widget.
surfacetableA valid surface for the exact current document object.
optionstable, optionalon_open(event), on_close(event), and on_error(err) callbacks. Any may be omitted.

Open/close payloads contain document and surface. These callbacks only match this surface; independent subscriptions can observe all reader sessions.

Returns

A cleanup(release_surface) function. It returns no value and is safe to call more than once. Normally call cleanup() to save/close the surface's active editor, then remove the provider and listeners. Close listeners remain active until release finishes. Release errors are reported after registrations are removed.

For an intentional navigation handoff, cleanup(false) removes registrations without releasing the active surface. A later call does not undo that choice; the landing viewer owns final release.

Things to know

  • The same widget and exact surface return the original cleanup. New callbacks do not replace the first ones.
  • A different surface on an already-registered widget raises an assertion. Clean up the old installation first.
  • Invalid surfaces, wrong-document objects, invalid options, and setup on a closed reader raise assertions immediately.
  • Do not also call registerRenderingView() for the same widget: they share one provider slot.
  • Registration does not show a viewer or open the editor. The viewer must be on the window stack when annotation opens.
  • A handoff to another surface does not give this installation the final close event. Use independent listeners if you need every closure.

See the rendering example for the full lifecycle.

On this page