Skip to content

Commit

Permalink
Merge pull request #800 from ynput/enhancement/helper-to-have-running…
Browse files Browse the repository at this point in the history
…-tray

Tray: Helper to make sure it is running
  • Loading branch information
iLLiCiTiT authored Jul 25, 2024
2 parents 9a063b2 + 1d23d07 commit 1be3378
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/ayon_core/tools/stdout_broker/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import websocket

from ayon_core.lib import Logger
from ayon_core.tools.tray.webserver import HostMsgAction
from ayon_core.tools.tray import HostMsgAction

log = Logger.get_logger(__name__)

Expand Down
6 changes: 3 additions & 3 deletions client/ayon_core/tools/tray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from .webserver import HostMsgAction
from .addons_manager import TrayAddonsManager
from .structures import HostMsgAction
from .lib import (
TrayState,
get_tray_state,
is_tray_running,
get_tray_server_url,
make_sure_tray_is_running,
main,
)


__all__ = (
"HostMsgAction",
"TrayAddonsManager",

"TrayState",
"get_tray_state",
"is_tray_running",
"get_tray_server_url",
"make_sure_tray_is_running",
"main",
)
43 changes: 42 additions & 1 deletion client/ayon_core/tools/tray/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import ayon_api
import requests

from ayon_core.lib import Logger
from ayon_core.lib import Logger, get_ayon_launcher_args, run_detached_process
from ayon_core.lib.local_settings import get_ayon_appdirs


Expand Down Expand Up @@ -356,6 +356,47 @@ def is_tray_running(
return state != TrayState.NOT_RUNNING


def make_sure_tray_is_running(
ayon_url: Optional[str] = None,
variant: Optional[str] = None,
env: Optional[Dict[str, str]] = None
):
"""Make sure that tray for AYON url and variant is running.
Args:
ayon_url (Optional[str]): AYON server url.
variant (Optional[str]): Settings variant.
env (Optional[Dict[str, str]]): Environment variables for the process.
"""
state = get_tray_state(ayon_url, variant)
if state == TrayState.RUNNING:
return

if state == TrayState.STARTING:
_wait_for_starting_tray(ayon_url, variant)
state = get_tray_state(ayon_url, variant)
if state == TrayState.RUNNING:
return

args = get_ayon_launcher_args("tray", "--force")
if env is None:
env = os.environ.copy()

# Make sure 'QT_API' is not set
env.pop("QT_API", None)

if ayon_url:
env["AYON_SERVER_URL"] = ayon_url

# TODO maybe handle variant in a better way
if variant:
if variant == "staging":
args.append("--use-staging")

run_detached_process(args, env=env)


def main(force=False):
from ayon_core.tools.tray.ui import main

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion client/ayon_core/tools/tray/ui/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
WrappedCallbackItem,
get_ayon_qt_app,
)
from ayon_core.tools.tray import TrayAddonsManager
from ayon_core.tools.tray.lib import (
set_tray_server_url,
remove_tray_server_url,
TrayIsRunningError,
)

from .addons_manager import TrayAddonsManager
from .host_console_listener import HostListener
from .info_widget import InfoWidget
from .dialogs import (
Expand Down
2 changes: 0 additions & 2 deletions client/ayon_core/tools/tray/webserver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from .structures import HostMsgAction
from .base_routes import RestApiEndpoint
from .server import find_free_port, WebServerManager


__all__ = (
"HostMsgAction",
"RestApiEndpoint",
"find_free_port",
"WebServerManager",
Expand Down

0 comments on commit 1be3378

Please sign in to comment.