-- LrInitPlugin hook. Runs on plugin load / reload / enable, before
-- any menu item is clicked.
--
-- Registers IPC action handlers early so reloading the plugin to
-- pick up new handler definitions immediately makes them callable —
-- no need to click "Open Pairs Window" just to wire the RPC surface.
--
-- Diagnostic ping stays here too so the browser's status probes
-- work even with the window closed.

local Log = require 'Log'
local IPC = require 'IPC'
local Handlers = require 'Handlers'
local Stats = require 'Stats'

Log.line('init', 'LrInitPlugin fired',
    'install_id=' .. Stats.installId())

IPC.register('ping', function(id, _reqJson)
    return string.format(
        '{"id":"%s","ok":true,"message":"pong","time_ms":%d}',
        id, math.floor(os.time() * 1000))
end)

Handlers.register()
