Skip to content

Commit

Permalink
added more debug messages and re-raise
Browse files Browse the repository at this point in the history
  • Loading branch information
tappi287 committed Mar 13, 2024
1 parent cbafeea commit fb296df
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions openvr_fsr_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def register_gevent_error_handler(error_handler):

logging.debug('Registering gevent error handler')
Hub._origin_handle_error = Hub.handle_error

def custom_handle_error(self, context, e_type, value, tb):
Expand All @@ -40,6 +40,7 @@ def custom_handle_error(self, context, e_type, value, tb):
self._origin_handle_error(context, e_type, value, tb)

Hub.handle_error = custom_handle_error
logging.debug('Registered gevent error handler')


def _start_in_browser(npm_serve=True):
Expand All @@ -59,13 +60,20 @@ def _start_in_browser(npm_serve=True):

edge_cmd = f"{os.path.expandvars('%PROGRAMFILES(x86)%')}\\Microsoft\\Edge\\Application\\msedge.exe"
start_url = f'http://{host}:{url_port}'
logging.debug(f'Preparing Browser start: {start_url}/{page}')
if Path(edge_cmd).exists():
logging.debug(f'Found Edge: {edge_cmd}')
else:
logging.debug(f'Edge not found: {edge_cmd}')

try:
app_module_prefs = getattr(AppSettings, 'app_preferences', dict()).get('appModules', list())
if Path(edge_cmd).exists() and 'edge_preferred' in app_module_prefs:
logging.debug('Starting in Edge.')
eel.start(page, mode='custom', host=host, port=port, block=False,
cmdline_args=[edge_cmd, '--profile-directory=Default', f'--app={start_url}'])
else:
logging.debug('Starting in Chrome.')
eel.start(page, host=host, port=port, block=False, close_callback=close_request)
except EnvironmentError:
# If Chrome isn't found, fallback to Microsoft Chromium Edge
Expand All @@ -79,36 +87,28 @@ def _start_in_browser(npm_serve=True):
eel.start(page, mode=None, app_mode=False, host=host, port=port, block=False)
# Open system default web browser
webbrowser.open_new(start_url)
logging.debug('Browser Start finished')


def start_eel():
logging.info('\n\n\n')
logging.info('#######################################################')
logging.info('################ Starting APP ###########')
logging.info('#######################################################\n\n\n')
logging.info('#######################################################')

if FROZEN:
# Set Exception hook
sys.excepthook = AppExceptionHook.exception_hook
register_gevent_error_handler(AppExceptionHook.gevent_error_handler)

AppSettings.load()
logging.debug('App-Settings loaded')

# This will ask for and re-run with admin rights
# if setting needs_admin set.
if AppSettings.needs_admin and not run_as_admin():
return

"""
THIS WILL DISABLE ctypes support! But it will make sure launching an executable
or basically any executable that is loading DLLs will work.
"""
if sys.platform == "win32":
import ctypes
ctypes.windll.kernel32.SetDllDirectoryA(None)
"""
//
"""
_start_in_browser(not FROZEN)
gevent.sleep(0.5)
if AppExceptionHook.event.is_set():
Expand All @@ -117,6 +117,7 @@ def start_eel():
raise RuntimeError(AppExceptionHook.gui_msg)

# -- Run until window/tab closed
logging.debug('Entering event loop')
while not CLOSE_EVENT.is_set():
CLOSE_EVENT.wait(timeout=1)

Expand All @@ -126,9 +127,6 @@ def start_eel():
# Capture exception events
AppExceptionHook.exception_event_loop()

# -- Shutdown Greenlets
# logging.debug('Shutting down Greenlets.')
# gevent.joinall((cg, hg, rg), timeout=15.0, raise_error=True)
AppSettings.previous_version = get_version()
AppSettings.save()

Expand All @@ -141,4 +139,8 @@ def start_eel():


if __name__ == '__main__':
start_eel()
try:
start_eel()
except Exception as e:
logging.error(f'Exception in main loop: {e}')
raise e

0 comments on commit fb296df

Please sign in to comment.