mirror of
https://github.com/pdxlocations/contact.git
synced 2026-03-28 17:12:35 +01:00
Compare commits
2 Commits
notificati
...
errors
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30402f4906 | ||
|
|
324e0b03e7 |
@@ -68,10 +68,6 @@ def prompt_region_if_unset(args: object) -> None:
|
|||||||
|
|
||||||
def initialize_globals(args: object) -> None:
|
def initialize_globals(args: object) -> None:
|
||||||
"""Initializes interface and shared globals."""
|
"""Initializes interface and shared globals."""
|
||||||
interface_state.interface = initialize_interface(args)
|
|
||||||
|
|
||||||
if interface_state.interface.localNode.localConfig.lora.region == 0:
|
|
||||||
prompt_region_if_unset(args)
|
|
||||||
|
|
||||||
interface_state.myNodeNum = get_nodeNum()
|
interface_state.myNodeNum = get_nodeNum()
|
||||||
ui_state.channel_list = get_channels()
|
ui_state.channel_list = get_channels()
|
||||||
@@ -84,55 +80,63 @@ def initialize_globals(args: object) -> None:
|
|||||||
|
|
||||||
def main(stdscr: curses.window) -> None:
|
def main(stdscr: curses.window) -> None:
|
||||||
"""Main entry point for the curses UI."""
|
"""Main entry point for the curses UI."""
|
||||||
|
|
||||||
output_capture = io.StringIO()
|
output_capture = io.StringIO()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with contextlib.redirect_stdout(output_capture), contextlib.redirect_stderr(output_capture):
|
setup_colors()
|
||||||
setup_colors()
|
draw_splash(stdscr)
|
||||||
draw_splash(stdscr)
|
|
||||||
|
|
||||||
args = setup_parser().parse_args()
|
args = setup_parser().parse_args()
|
||||||
|
|
||||||
if getattr(args, "settings", False):
|
if getattr(args, "settings", False):
|
||||||
subprocess.run([sys.executable, "-m", "contact.settings"], check=True)
|
subprocess.run([sys.executable, "-m", "contact.settings"], check=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
logging.info("Initializing interface...")
|
logging.info("Initializing interface...")
|
||||||
with app_state.lock:
|
with app_state.lock:
|
||||||
initialize_globals(args)
|
interface_state.interface = initialize_interface(args)
|
||||||
logging.info("Starting main UI")
|
|
||||||
|
|
||||||
main_ui(stdscr)
|
if interface_state.interface.localNode.localConfig.lora.region == 0:
|
||||||
|
prompt_region_if_unset(args)
|
||||||
|
|
||||||
except Exception as e:
|
initialize_globals(args)
|
||||||
console_output = output_capture.getvalue()
|
logging.info("Starting main UI")
|
||||||
logging.error("Uncaught exception: %s", e)
|
|
||||||
logging.error("Traceback: %s", traceback.format_exc())
|
try:
|
||||||
logging.error("Console output:\n%s", console_output)
|
with contextlib.redirect_stdout(output_capture), contextlib.redirect_stderr(output_capture):
|
||||||
|
main_ui(stdscr)
|
||||||
|
except Exception:
|
||||||
|
console_output = output_capture.getvalue()
|
||||||
|
logging.error("Uncaught exception inside main_ui")
|
||||||
|
logging.error("Traceback:\n%s", traceback.format_exc())
|
||||||
|
logging.error("Console output:\n%s", console_output)
|
||||||
|
return
|
||||||
|
|
||||||
|
except Exception:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def start() -> None:
|
def start() -> None:
|
||||||
"""Launch curses wrapper and redirect logs to file."""
|
"""Entry point for the application."""
|
||||||
|
|
||||||
if "--help" in sys.argv or "-h" in sys.argv:
|
if "--help" in sys.argv or "-h" in sys.argv:
|
||||||
setup_parser().print_help()
|
setup_parser().print_help()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
with open(config.log_file_path, "a", buffering=1) as log_f:
|
try:
|
||||||
sys.stdout = log_f
|
curses.wrapper(main)
|
||||||
sys.stderr = log_f
|
except KeyboardInterrupt:
|
||||||
|
logging.info("User exited with Ctrl+C")
|
||||||
with contextlib.redirect_stdout(log_f), contextlib.redirect_stderr(log_f):
|
sys.exit(0)
|
||||||
try:
|
except Exception as e:
|
||||||
curses.wrapper(main)
|
logging.critical("Fatal error", exc_info=True)
|
||||||
except KeyboardInterrupt:
|
try:
|
||||||
logging.info("User exited with Ctrl+C")
|
curses.endwin()
|
||||||
sys.exit(0)
|
except Exception:
|
||||||
except Exception as e:
|
pass
|
||||||
logging.error("Fatal error: %s", e)
|
print("Fatal error:", e)
|
||||||
logging.error("Traceback: %s", traceback.format_exc())
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user