From 985bcfa30c0c5799a87ca22343f2e3813403e290 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Fri, 15 Dec 2023 17:12:14 +0100 Subject: [PATCH 1/2] Init on addon register --- addons/io_hubs_addon/debugger.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/io_hubs_addon/debugger.py b/addons/io_hubs_addon/debugger.py index 0b70430a..b0b614d0 100644 --- a/addons/io_hubs_addon/debugger.py +++ b/addons/io_hubs_addon/debugger.py @@ -618,8 +618,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) @@ -631,6 +630,11 @@ def load_post(dummy): bpy.ops.hubs_scene.scene_debugger_instance_add('INVOKE_DEFAULT') +@persistent +def load_post(dummy): + init() + + @persistent def update_session(): hubs_session.update_session_state() @@ -671,6 +675,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) From 3534bb0dfd312ae91166006c1a7205342ea92820 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Mon, 18 Dec 2023 10:31:41 +0100 Subject: [PATCH 2/2] Avoid operator call when registering Avoid operator call when registering --- addons/io_hubs_addon/debugger.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/addons/io_hubs_addon/debugger.py b/addons/io_hubs_addon/debugger.py index b0b614d0..7d0bf07a 100644 --- a/addons/io_hubs_addon/debugger.py +++ b/addons/io_hubs_addon/debugger.py @@ -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'} @@ -627,7 +631,7 @@ def init(): 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