bl_info = {
    "name": "Hi3D",
    "author": "Hi3D",
    "version": (1, 0, 8),
    "blender": (2, 80, 0),
    "location": "View3D > Sidebar > Hi3D",
    "description": "Open Hi3D Model Generator website",
    "category": "3D View",
}

import bpy
from bpy.app.handlers import persistent
from . import properties, operators, panels

@persistent
def _hi3d_resume_tasks_on_load(_dummy=None):
    from . import utils
    def _resume():
        try:
            utils.on_blend_load()
            started_gen, started_tex, restarted_tex_submit = utils.resume_pending_tasks()
            print(f"Hi3D load_post: resumed pollers gen={started_gen} tex={started_tex} tex_submit={restarted_tex_submit}")
        except Exception as e:
            print(f"Hi3D resume failed: {e}")
        return None
    bpy.app.timers.register(_resume, first_interval=1.0)

def register():
    properties.register()
    operators.register()
    panels.register()
    from .logger import get_logger
    get_logger()
    if _hi3d_resume_tasks_on_load not in bpy.app.handlers.load_post:
        bpy.app.handlers.load_post.append(_hi3d_resume_tasks_on_load)
    from . import utils
    try:
        utils.on_blend_load()
    except Exception as e:
        print(f"Hi3D ui pump failed: {e}")
    def _resume_on_register():
        try:
            started_gen, started_tex, restarted_tex_submit = utils.resume_pending_tasks()
            print(f"Hi3D register: resumed pollers gen={started_gen} tex={started_tex} tex_submit={restarted_tex_submit}")
        except Exception as e:
            print(f"Hi3D resume failed: {e}")
        return None
    bpy.app.timers.register(_resume_on_register, first_interval=1.0)



def unregister():
    if _hi3d_resume_tasks_on_load in bpy.app.handlers.load_post:
        bpy.app.handlers.load_post.remove(_hi3d_resume_tasks_on_load)
    panels.unregister()
    operators.unregister()
    properties.unregister()
    from .logger import close_logger
    close_logger()
