# -*- coding: utf-8 -*-
import nuke

def _get_nuke_major_version():
    try:
        if hasattr(nuke, "NUKE_VERSION_MAJOR"):
            return int(nuke.NUKE_VERSION_MAJOR)
        env = getattr(nuke, "env", {})
        if type(env) is dict and "NukeVersionMajor" in env:
            return int(env["NukeVersionMajor"])
    except Exception:
        pass
    return 0

if _get_nuke_major_version() >= 13:
    try:
        import missing_relinker
        
        MENU_LABEL = "Missing Relinker"
        COMMAND_LABEL = "启动插件"
        SHORTCUT = None
        COMMAND_EXPR = "missing_relinker.show_dialog()"

        menubar = nuke.menu("Nuke")
        menu = menubar.findItem(MENU_LABEL)
        if menu is None:
            menu = menubar.addMenu(MENU_LABEL)
        existing = menu.findItem(COMMAND_LABEL)
        if existing is None:
            menu.addCommand(COMMAND_LABEL, COMMAND_EXPR, SHORTCUT)
    except Exception:
        pass