# SPDX-License-Identifier: GPL-2.0-or-later


"""
Extending features of the Asset Browser for a studio use. 
"""

bl_info = {
    "name": "Asset Library",
    "description": "Asset Library based on the Asset Browser.",
    "author": "Christophe Seux",
    "version": (2, 0),
    "blender": (4, 0, 2),
    "warning": "In development, things may change",
    "location": "Asset Browser",
    "category": "Import-Export",
}

import sys

from . import operators, properties, ui, preferences, data_type
from .core.lib_utils import load_libraries, update_library_path


bl_modules = (
    operators,
    properties,
    ui,
    preferences,
    data_type
)

# Reload Modules from inside Blender
if "bpy" in locals():
    import importlib
    
    for mod in modules:
        importlib.reload(mod)

import bpy


def load_handler():
    print('load_handler')
    load_libraries()
    update_library_path()
    #set_env_libraries()
    #bpy.ops.assetlib.set_paths(all=True)

    #if not bpy.app.background:
    #    bpy.ops.assetlib.bundle(blocking=False, mode='AUTO_BUNDLE')
            


def register():
    """Register the addon Asset Library for Blender"""
    
    for mod in bl_modules:
        mod.register()
    
    
    bpy.app.timers.register(load_handler, first_interval=1)


def unregister():
    """Unregister the addon Asset Library for Blender"""

    for mod in reversed(bl_modules):
        mod.unregister()