Skip to content

Commit

Permalink
Hubs instances management
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Dec 1, 2023
1 parent 22da747 commit 4e450f0
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 9 deletions.
86 changes: 82 additions & 4 deletions addons/io_hubs_addon/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ def is_user_logged_in():


def is_user_in_room():
return web_driver.execute_script('try { return APP.scene.is("entered"); } catch(e) { return false; }')
return web_driver.execute_script('try { return APP?.scene?.is("entered"); } catch(e) { return false; }')


def is_instance_set(context):
hubs_instance_idx = get_addon_pref(context).hubs_instance_idx
return hubs_instance_idx != -1


class HubsUpdateSceneOperator(bpy.types.Operator):
Expand Down Expand Up @@ -124,7 +129,7 @@ class HubsCreateRoomOperator(bpy.types.Operator):

@classmethod
def poll(cls, context: Context):
return not isWebdriverAlive()
return not isWebdriverAlive() and is_instance_set(context)

def execute(self, context):
try:
Expand Down Expand Up @@ -176,8 +181,9 @@ def execute(self, context):
if context.scene.hubs_scene_debugger_room_create_prefs.debug_local_scene:
params = f'{params}&debugLocalScene'

web_driver.get(
f'{get_addon_pref(context).hubs_instance_url}?{params}')
prefs = get_addon_pref(context)
hubs_instance_url = prefs.hubs_instances[prefs.hubs_instance_idx].url
web_driver.get(f'{hubs_instance_url}?{params}')

return {'FINISHED'}

Expand Down Expand Up @@ -259,6 +265,11 @@ def draw(self, context: Context):
col.operator(HubsCloseRoomOperator.bl_idname,
text='Close')

if not is_instance_set(context):
row = box.row()
row.alert = True
row.label(text="Set a hubs instance")


class HUBS_PT_ToolsSceneDebuggerUpdatePanel(bpy.types.Panel):
bl_idname = "HUBS_PT_ToolsSceneDebuggerUpdatePanel"
Expand Down Expand Up @@ -354,6 +365,67 @@ def draw(self, context):
row.operator(HubsOpenAddonPrefsOperator.bl_idname,
text='Setup')

prefs = get_addon_pref(context)
row = main_box.row()
row.label(text="Instances:")
row = main_box.row()
row.enabled = not isWebdriverAlive()
row.template_list(HUBS_UL_ToolsSceneDebuggerServers.bl_idname, "", prefs,
"hubs_instances", prefs, "hubs_instance_idx", rows=3)
col = row.column()
col.enabled = not isWebdriverAlive()
col.operator(HubsSceneDebuggerInstanceAdd.bl_idname,
icon='ADD', text="")
col.enabled = not isWebdriverAlive()
col.operator(HubsSceneDebuggerInstanceRemove.bl_idname,
icon='REMOVE', text="")


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

@classmethod
def poll(cls, context: Context):
return not isWebdriverAlive()

def execute(self, context):
prefs = get_addon_pref(context)
new_instance = prefs.hubs_instances.add()
new_instance.url = "https://hubs.mozilla.com/demo"
prefs.hubs_instance_idx = len(
prefs.hubs_instances) - 1
bpy.ops.wm.save_userpref()

return {'FINISHED'}


class HubsSceneDebuggerInstanceRemove(bpy.types.Operator):
bl_idname = "hubs_scene.scene_debugger_instance_remove"
bl_label = "Remove Server Instance"
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context: Context):
return not isWebdriverAlive()

def execute(self, context):
prefs = get_addon_pref(context)
prefs.hubs_instances.remove(prefs.hubs_instance_idx)
prefs.hubs_instances = len(prefs.hubs_instances) - 1
bpy.ops.wm.save_userpref()

return {'FINISHED'}


class HUBS_UL_ToolsSceneDebuggerServers(bpy.types.UIList):
bl_idname = "HUBS_UL_ToolsSceneDebuggerServers"
bl_label = "Instances"

def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
layout.prop(item, "url", text="", emboss=False)


class HubsSceneDebuggerRoomCreatePrefs(bpy.types.PropertyGroup):
new_loader: bpy.props.BoolProperty(name="New Loader", default=True,
Expand Down Expand Up @@ -391,6 +463,9 @@ def register():
bpy.utils.register_class(HubsSceneDebuggerRoomCreatePrefs)
bpy.utils.register_class(HubsOpenAddonPrefsOperator)
bpy.utils.register_class(HubsSceneDebuggerRoomExportPrefs)
bpy.utils.register_class(HubsSceneDebuggerInstanceAdd)
bpy.utils.register_class(HubsSceneDebuggerInstanceRemove)
bpy.utils.register_class(HUBS_UL_ToolsSceneDebuggerServers)

bpy.types.Scene.hubs_scene_debugger_room_create_prefs = bpy.props.PointerProperty(
type=HubsSceneDebuggerRoomCreatePrefs)
Expand All @@ -408,6 +483,9 @@ def unregister():
bpy.utils.unregister_class(HubsSceneDebuggerRoomCreatePrefs)
bpy.utils.unregister_class(HubsOpenAddonPrefsOperator)
bpy.utils.unregister_class(HubsSceneDebuggerRoomExportPrefs)
bpy.utils.unregister_class(HUBS_UL_ToolsSceneDebuggerServers)
bpy.utils.unregister_class(HubsSceneDebuggerInstanceAdd)
bpy.utils.unregister_class(HubsSceneDebuggerInstanceRemove)

del bpy.types.Scene.hubs_scene_debugger_room_create_prefs
del bpy.types.Scene.hubs_scene_debugger_room_export_prefs
Expand Down
39 changes: 34 additions & 5 deletions addons/io_hubs_addon/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ def execute(self, context):
return {'FINISHED'}


class HubsSceneDebuggerInstance(bpy.types.PropertyGroup):
url: bpy.props.StringProperty()


def hubs_instance_idx_set(self, value):
from .debugger import isWebdriverAlive
if isWebdriverAlive():
return
else:
prefs = get_addon_pref(context=bpy.context)
prefs.hubs_instance_idx_ = value


def hubs_instance_idx_get(self):
prefs = get_addon_pref(context=bpy.context)
return prefs.hubs_instance_idx_


class HubsPreferences(AddonPreferences):
bl_idname = __package__

Expand All @@ -162,8 +180,20 @@ class HubsPreferences(AddonPreferences):

viewer_available: BoolProperty()

hubs_instance_url: StringProperty(name="Hubs instance URL", description="URL of the hubs instance to use",
default="https://hubs.local:8080/")
hubs_instances: bpy.props.CollectionProperty(
type=HubsSceneDebuggerInstance)

hubs_instance_idx: bpy.props.IntProperty(
name="Hubs instance index",
description="Active Hubs Scene Debugger Instance index",
set=hubs_instance_idx_set,
get=hubs_instance_idx_get,
default=-1)

hubs_instance_idx_: bpy.props.IntProperty(
name="Hubs instance index (hidden)",
description="Active Hubs Scene Debugger Instance index (hidden)",
default=-1)

browser: EnumProperty(
name="Choose a browser", description="Type",
Expand Down Expand Up @@ -196,9 +226,6 @@ def draw(self, context):
box = layout.box()
box.label(text="Scene debugger configuration")

row = box.row()
row.prop(self, "hubs_instance_url")

if modules_available:
browser_box = box.box()
row = browser_box.row()
Expand Down Expand Up @@ -263,6 +290,7 @@ def draw(self, context):

def register():
bpy.utils.register_class(DepsProperty)
bpy.utils.register_class(HubsSceneDebuggerInstance)
bpy.utils.register_class(HubsPreferences)
bpy.utils.register_class(InstallDepsOperator)
bpy.utils.register_class(UninstallDepsOperator)
Expand All @@ -274,4 +302,5 @@ def unregister():
bpy.utils.unregister_class(UninstallDepsOperator)
bpy.utils.unregister_class(InstallDepsOperator)
bpy.utils.unregister_class(HubsPreferences)
bpy.utils.unregister_class(HubsSceneDebuggerInstance)
bpy.utils.unregister_class(DepsProperty)

0 comments on commit 4e450f0

Please sign in to comment.