mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
Merge branch 'develop' into enhancement/reduce-cli-commands
This commit is contained in:
commit
07296c3633
2 changed files with 71 additions and 0 deletions
|
|
@ -356,6 +356,39 @@ def is_tray_running(
|
||||||
return state != TrayState.NOT_RUNNING
|
return state != TrayState.NOT_RUNNING
|
||||||
|
|
||||||
|
|
||||||
|
def show_message_in_tray(
|
||||||
|
title, message, icon=None, msecs=None, tray_url=None
|
||||||
|
):
|
||||||
|
"""Show message in tray.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
title (str): Message title.
|
||||||
|
message (str): Message content.
|
||||||
|
icon (Optional[Literal["information", "warning", "critical"]]): Icon
|
||||||
|
for the message.
|
||||||
|
msecs (Optional[int]): Duration of the message.
|
||||||
|
tray_url (Optional[str]): Tray server url.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if not tray_url:
|
||||||
|
tray_url = get_tray_server_url()
|
||||||
|
|
||||||
|
# TODO handle this case, e.g. raise an error?
|
||||||
|
if not tray_url:
|
||||||
|
return
|
||||||
|
|
||||||
|
# TODO handle response, can fail whole request or can fail on status
|
||||||
|
requests.post(
|
||||||
|
f"{tray_url}/tray/message",
|
||||||
|
json={
|
||||||
|
"title": title,
|
||||||
|
"message": message,
|
||||||
|
"icon": icon,
|
||||||
|
"msecs": msecs
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def make_sure_tray_is_running(
|
def make_sure_tray_is_running(
|
||||||
ayon_url: Optional[str] = None,
|
ayon_url: Optional[str] = None,
|
||||||
variant: Optional[str] = None,
|
variant: Optional[str] = None,
|
||||||
|
|
@ -412,6 +445,10 @@ def main(force=False):
|
||||||
state = TrayState.NOT_RUNNING
|
state = TrayState.NOT_RUNNING
|
||||||
|
|
||||||
if state == TrayState.RUNNING:
|
if state == TrayState.RUNNING:
|
||||||
|
show_message_in_tray(
|
||||||
|
"Tray is already running",
|
||||||
|
"Your AYON tray application is already running."
|
||||||
|
)
|
||||||
print("Tray is already running.")
|
print("Tray is already running.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ class TrayManager:
|
||||||
kwargs["msecs"] = msecs
|
kwargs["msecs"] = msecs
|
||||||
|
|
||||||
self.tray_widget.showMessage(*args, **kwargs)
|
self.tray_widget.showMessage(*args, **kwargs)
|
||||||
|
# TODO validate 'self.tray_widget.supportsMessages()'
|
||||||
|
|
||||||
def initialize_addons(self):
|
def initialize_addons(self):
|
||||||
"""Add addons to tray."""
|
"""Add addons to tray."""
|
||||||
|
|
@ -148,6 +149,9 @@ class TrayManager:
|
||||||
self._addons_manager.add_route(
|
self._addons_manager.add_route(
|
||||||
"GET", "/tray", self._web_get_tray_info
|
"GET", "/tray", self._web_get_tray_info
|
||||||
)
|
)
|
||||||
|
self._addons_manager.add_route(
|
||||||
|
"POST", "/tray/message", self._web_show_tray_message
|
||||||
|
)
|
||||||
|
|
||||||
admin_submenu = ITrayAction.admin_submenu(tray_menu)
|
admin_submenu = ITrayAction.admin_submenu(tray_menu)
|
||||||
tray_menu.addMenu(admin_submenu)
|
tray_menu.addMenu(admin_submenu)
|
||||||
|
|
@ -294,6 +298,36 @@ class TrayManager:
|
||||||
"running_time": time.time() - self._start_time,
|
"running_time": time.time() - self._start_time,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
async def _web_show_tray_message(self, request: Request) -> Response:
|
||||||
|
data = await request.json()
|
||||||
|
try:
|
||||||
|
title = data["title"]
|
||||||
|
message = data["message"]
|
||||||
|
icon = data.get("icon")
|
||||||
|
msecs = data.get("msecs")
|
||||||
|
except KeyError as exc:
|
||||||
|
return json_response(
|
||||||
|
{
|
||||||
|
"error": f"Missing required data. {exc}",
|
||||||
|
"success": False,
|
||||||
|
},
|
||||||
|
status=400,
|
||||||
|
)
|
||||||
|
|
||||||
|
if icon == "information":
|
||||||
|
icon = QtWidgets.QSystemTrayIconInformation
|
||||||
|
elif icon == "warning":
|
||||||
|
icon = QtWidgets.QSystemTrayIconWarning
|
||||||
|
elif icon == "critical":
|
||||||
|
icon = QtWidgets.QSystemTrayIcon.Critical
|
||||||
|
else:
|
||||||
|
icon = None
|
||||||
|
|
||||||
|
self.execute_in_main_thread(
|
||||||
|
self.show_tray_message, title, message, icon, msecs
|
||||||
|
)
|
||||||
|
return json_response({"success": True})
|
||||||
|
|
||||||
def _on_update_check_timer(self):
|
def _on_update_check_timer(self):
|
||||||
try:
|
try:
|
||||||
bundles = ayon_api.get_bundles()
|
bundles = ayon_api.get_bundles()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue