Skip to content

Commit

Permalink
Merge pull request #214 from builder555/dev
Browse files Browse the repository at this point in the history
fix ui opening
  • Loading branch information
builder555 committed Jan 31, 2024
2 parents 533cba0 + 17da2ea commit d07c690
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
29 changes: 12 additions & 17 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ws_server import CommandProcessor, WebSocketHandler
from version_checker import VersionChecker
import logging
import webbrowser
from io_utils import parse_cmd_args, get_resource_path
from rich.logging import RichHandler

Expand All @@ -20,16 +21,15 @@
DEFAULT_HOST = "0.0.0.0"
DEFAULT_PORT = 8080

import webbrowser


async def open_browser(url):
await asyncio.sleep(5)
webbrowser.open(url)


async def log(msg):
logging.info(msg)
async def handle_ui_opening(args):
host = args.host if args.host != "0.0.0.0" else "localhost"
if not args.no_open:
await asyncio.sleep(5)
url = f"http://{host}:{args.port}"
webbrowser.open(url)
else:
logging.info(f"Open browser at http://{host}:{args.port}")


async def main(stop_event=asyncio.Event()):
Expand All @@ -47,24 +47,19 @@ async def main(stop_event=asyncio.Event()):
command_processor = CommandProcessor(
pinecil_finder, app_version_manager, ironos_version_manager
)
tasks = []
try:
ui_path = get_resource_path("gui", max_levels=2)
tasks += [asyncio.create_task(handle_ui_opening(args))]
except FileNotFoundError:
logging.warning("gui directory not found. You will need to serve UI separately")
ui_path = ""
ws_handler = WebSocketHandler(command_processor, ui_path=ui_path)
pinecil_monitor = PinecilMonitor(pinecil_finder, ws_handler.broadcast)
tasks = [
tasks += [
asyncio.create_task(ws_handler.serve(args.host, args.port)),
asyncio.create_task(pinecil_monitor.monitor(stop_event)),
]
if not args.no_open:
url = f"http://{args.host}:{args.port}"
tasks.append(asyncio.create_task(open_browser(url)))
else:
tasks.append(
asyncio.create_task(log(f"Open browser at http://{args.host}:{args.port}"))
)
try:
await asyncio.gather(*tasks)
except KeyboardInterrupt:
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.5
2.2.6

0 comments on commit d07c690

Please sign in to comment.