Skip to content

Commit

Permalink
Merge pull request #260 from MozillaReality/init-on-addon-register
Browse files Browse the repository at this point in the history
Init on addon register
  • Loading branch information
keianhzo authored Dec 18, 2023
2 parents d552627 + 3534bb0 commit 5f43404
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions addons/io_hubs_addon/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,20 +409,24 @@ def draw(self, context):
text='Setup')


def add_instance(context):
prefs = context.window_manager.hubs_scene_debugger_prefs
new_instance = prefs.hubs_instances.add()
new_instance.name = "Demo Hub"
new_instance.url = "https://hubs.mozilla.com/demo"
prefs.hubs_instance_idx = len(
prefs.hubs_instances) - 1

save_prefs(context)


class HubsSceneDebuggerInstanceAdd(bpy.types.Operator):
bl_idname = "hubs_scene.scene_debugger_instance_add"
bl_label = "Add Server Instance"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
prefs = context.window_manager.hubs_scene_debugger_prefs
new_instance = prefs.hubs_instances.add()
new_instance.name = "Demo Hub"
new_instance.url = "https://hubs.mozilla.com/demo"
prefs.hubs_instance_idx = len(
prefs.hubs_instances) - 1

save_prefs(context)
add_instance(context)

return {'FINISHED'}

Expand Down Expand Up @@ -618,8 +622,7 @@ class HubsSceneDebuggerRoomExportPrefs(bpy.types.PropertyGroup):
default=False, options=set())


@persistent
def load_post(dummy):
def init():
if not bpy.app.timers.is_registered(update_session):
bpy.app.timers.register(update_session)

Expand All @@ -628,7 +631,12 @@ def load_post(dummy):

prefs = bpy.context.window_manager.hubs_scene_debugger_prefs
if len(prefs.hubs_instances) == 0:
bpy.ops.hubs_scene.scene_debugger_instance_add('INVOKE_DEFAULT')
add_instance(bpy.context)


@persistent
def load_post(dummy):
init()


@persistent
Expand Down Expand Up @@ -671,6 +679,8 @@ def register():
if load_post not in bpy.app.handlers.load_post:
bpy.app.handlers.load_post.append(load_post)

init()


def unregister():
bpy.utils.unregister_class(HubsUpdateSceneOperator)
Expand Down

0 comments on commit 5f43404

Please sign in to comment.