Skip to content

Commit

Permalink
Merge pull request #3 from Roblox/fix/new-file-open
Browse files Browse the repository at this point in the history
Restart event loop after a file is opened
  • Loading branch information
Nightriff authored Jul 31, 2023
2 parents 5f62af0 + de9059a commit eec6c8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
importlib.reload(RBX_OT_install_dependencies)

import bpy
from bpy.app.handlers import persistent
from bpy.types import Panel, AddonPreferences
from bpy.props import (
StringProperty,
Expand Down Expand Up @@ -226,6 +227,13 @@ def poll(cls, context):
return rbx.is_logged_in and not rbx.is_processing_login_or_logout


@persistent
def load_post(dummy):
from .lib import event_loop

event_loop.reset_timer_running()


def get_classes():
from .lib import (
event_loop,
Expand Down Expand Up @@ -260,6 +268,7 @@ def register():
from .lib import roblox_properties

bpy.types.WindowManager.rbx = PointerProperty(type=roblox_properties.RbxProperties)
bpy.app.handlers.load_post.append(load_post)


def unregister():
Expand All @@ -268,3 +277,5 @@ def unregister():
for cls in reversed(get_classes()):
bpy.utils.unregister_class(cls)
del bpy.types.WindowManager.rbx

bpy.app.handlers.load_post.remove(load_post)
8 changes: 8 additions & 0 deletions lib/event_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def get_loop():
return loop


# If a new file is opened during the session the modal timer will stop
# running. This function is called from a post load handler in this event
# to reset the timer_running flag so the event loop can be restarted.
def reset_timer_running():
global timer_running
timer_running = False


def __ensure_started():
global timer_running

Expand Down

0 comments on commit eec6c8a

Please sign in to comment.