Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tray: Singleton tray #794

Merged
merged 35 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9c06d8c
move current tray implementation to 'ui' subfolder
iLLiCiTiT Jul 17, 2024
bca296a
more webserver to tray tool
iLLiCiTiT Jul 17, 2024
1bc9733
fix webserver import
iLLiCiTiT Jul 17, 2024
22f7a9d
moved tray addons manager to tray
iLLiCiTiT Jul 17, 2024
fee111d
removed deprecated methods
iLLiCiTiT Jul 17, 2024
eec0d4a
pass tray manager on initialization
iLLiCiTiT Jul 17, 2024
0b71ec7
make tray manager private attribute
iLLiCiTiT Jul 17, 2024
50e196d
removed not existing items from menu order
iLLiCiTiT Jul 17, 2024
74e2a9d
move lib functions to lib.py
iLLiCiTiT Jul 17, 2024
6bd87b0
simplified 'TrayAddonsManager' import
iLLiCiTiT Jul 17, 2024
f6cca92
removed 'TrayModulesManager' import
iLLiCiTiT Jul 18, 2024
f80b82a
changed webserver from addon to feature of tray
iLLiCiTiT Jul 18, 2024
bdd79ea
rename webserver_module.py to webserver.py
iLLiCiTiT Jul 18, 2024
c0d878a
added option to get services submenu via tray manager
iLLiCiTiT Jul 18, 2024
996998d
use addon variables over module variables
iLLiCiTiT Jul 18, 2024
5498bcc
tray is somewhat capable of hangling single tray running
iLLiCiTiT Jul 18, 2024
fbe987c
don't store '_tray_manager' to traywebserver
iLLiCiTiT Jul 19, 2024
1acbd51
simplified webserver logic
iLLiCiTiT Jul 22, 2024
5a7a54f
move host listener to UI
iLLiCiTiT Jul 22, 2024
3eefe4d
faster existing tray validation
iLLiCiTiT Jul 22, 2024
d027b54
added option to validate running tray
iLLiCiTiT Jul 23, 2024
89ad9af
added docstrings
iLLiCiTiT Jul 23, 2024
3416c60
added some functions to init for api
iLLiCiTiT Jul 23, 2024
d482cf7
removed unused imports
iLLiCiTiT Jul 23, 2024
a52bc15
Merge branch 'develop' into feature/AY-6113_Singleton-tray-with-API
iLLiCiTiT Jul 23, 2024
05a13d6
fix multiple bugs
iLLiCiTiT Jul 23, 2024
b5f7162
fix 'set_tray_server_url'
iLLiCiTiT Jul 23, 2024
ebc1c62
small enhancements
iLLiCiTiT Jul 23, 2024
a285008
fix typo
iLLiCiTiT Jul 24, 2024
136da2b
exit if another tray is discovered
iLLiCiTiT Jul 24, 2024
131afb6
call 'set_tray_server_url' as soon as possible
iLLiCiTiT Jul 24, 2024
aee9bd3
don't override tray_url
iLLiCiTiT Jul 24, 2024
43f9f51
'remove_tray_server_url' has force option
iLLiCiTiT Jul 24, 2024
03c93a3
impemented waiting for starting tray
iLLiCiTiT Jul 24, 2024
1020716
Merge branch 'develop' into feature/AY-6113_Singleton-tray-with-API
iLLiCiTiT Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions client/ayon_core/addon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,3 @@ AYON addons should contain separated logic of specific kind of implementation, s
"inventory": []
}
```

### TrayAddonsManager
- inherits from `AddonsManager`
- has specific implementation for AYON Tray and handle `ITrayAddon` methods
2 changes: 0 additions & 2 deletions client/ayon_core/addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .base import (
AYONAddon,
AddonsManager,
TrayAddonsManager,
load_addons,
)

Expand All @@ -27,6 +26,5 @@

"AYONAddon",
"AddonsManager",
"TrayAddonsManager",
"load_addons",
)
202 changes: 9 additions & 193 deletions client/ayon_core/addon/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from .interfaces import (
IPluginPaths,
IHostAddon,
ITrayAddon,
ITrayService
)

# Files that will be always ignored on addons import
Expand Down Expand Up @@ -923,20 +921,20 @@ def connect_addons(self):
report = {}
time_start = time.time()
prev_start_time = time_start
enabled_modules = self.get_enabled_addons()
self.log.debug("Has {} enabled modules.".format(len(enabled_modules)))
for module in enabled_modules:
enabled_addons = self.get_enabled_addons()
self.log.debug("Has {} enabled addons.".format(len(enabled_addons)))
for addon in enabled_addons:
try:
if not is_func_marked(module.connect_with_addons):
module.connect_with_addons(enabled_modules)
if not is_func_marked(addon.connect_with_addons):
addon.connect_with_addons(enabled_addons)

elif hasattr(module, "connect_with_modules"):
elif hasattr(addon, "connect_with_modules"):
self.log.warning((
"DEPRECATION WARNING: Addon '{}' still uses"
" 'connect_with_modules' method. Please switch to use"
" 'connect_with_addons' method."
).format(module.name))
module.connect_with_modules(enabled_modules)
).format(addon.name))
addon.connect_with_modules(enabled_addons)

except Exception:
self.log.error(
Expand All @@ -945,7 +943,7 @@ def connect_addons(self):
)

now = time.time()
report[module.__class__.__name__] = now - prev_start_time
report[addon.__class__.__name__] = now - prev_start_time
prev_start_time = now

if self._report is not None:
Expand Down Expand Up @@ -1338,185 +1336,3 @@ def get_host_module(self, host_name):
" 'get_host_module' please use 'get_host_addon' instead."
)
return self.get_host_addon(host_name)


class TrayAddonsManager(AddonsManager):
# Define order of addons in menu
# TODO find better way how to define order
addons_menu_order = (
"user",
"ftrack",
"kitsu",
"launcher_tool",
"avalon",
"clockify",
"traypublish_tool",
"log_viewer",
)

def __init__(self, settings=None):
super(TrayAddonsManager, self).__init__(settings, initialize=False)

self.tray_manager = None

self.doubleclick_callbacks = {}
self.doubleclick_callback = None

def add_doubleclick_callback(self, addon, callback):
"""Register double-click callbacks on tray icon.

Currently, there is no way how to determine which is launched. Name of
callback can be defined with `doubleclick_callback` attribute.

Missing feature how to define default callback.

Args:
addon (AYONAddon): Addon object.
callback (FunctionType): Function callback.
"""

callback_name = "_".join([addon.name, callback.__name__])
if callback_name not in self.doubleclick_callbacks:
self.doubleclick_callbacks[callback_name] = callback
if self.doubleclick_callback is None:
self.doubleclick_callback = callback_name
return

self.log.warning((
"Callback with name \"{}\" is already registered."
).format(callback_name))

def initialize(self, tray_manager, tray_menu):
self.tray_manager = tray_manager
self.initialize_addons()
self.tray_init()
self.connect_addons()
self.tray_menu(tray_menu)

def get_enabled_tray_addons(self):
"""Enabled tray addons.

Returns:
list[AYONAddon]: Enabled addons that inherit from tray interface.
"""

return [
addon
for addon in self.get_enabled_addons()
if isinstance(addon, ITrayAddon)
]

def restart_tray(self):
if self.tray_manager:
self.tray_manager.restart()

def tray_init(self):
report = {}
time_start = time.time()
prev_start_time = time_start
for addon in self.get_enabled_tray_addons():
try:
addon._tray_manager = self.tray_manager
addon.tray_init()
addon.tray_initialized = True
except Exception:
self.log.warning(
"Addon \"{}\" crashed on `tray_init`.".format(
addon.name
),
exc_info=True
)

now = time.time()
report[addon.__class__.__name__] = now - prev_start_time
prev_start_time = now

if self._report is not None:
report[self._report_total_key] = time.time() - time_start
self._report["Tray init"] = report

def tray_menu(self, tray_menu):
ordered_addons = []
enabled_by_name = {
addon.name: addon
for addon in self.get_enabled_tray_addons()
}

for name in self.addons_menu_order:
addon_by_name = enabled_by_name.pop(name, None)
if addon_by_name:
ordered_addons.append(addon_by_name)
ordered_addons.extend(enabled_by_name.values())

report = {}
time_start = time.time()
prev_start_time = time_start
for addon in ordered_addons:
if not addon.tray_initialized:
continue

try:
addon.tray_menu(tray_menu)
except Exception:
# Unset initialized mark
addon.tray_initialized = False
self.log.warning(
"Addon \"{}\" crashed on `tray_menu`.".format(
addon.name
),
exc_info=True
)
now = time.time()
report[addon.__class__.__name__] = now - prev_start_time
prev_start_time = now

if self._report is not None:
report[self._report_total_key] = time.time() - time_start
self._report["Tray menu"] = report

def start_addons(self):
report = {}
time_start = time.time()
prev_start_time = time_start
for addon in self.get_enabled_tray_addons():
if not addon.tray_initialized:
if isinstance(addon, ITrayService):
addon.set_service_failed_icon()
continue

try:
addon.tray_start()
except Exception:
self.log.warning(
"Addon \"{}\" crashed on `tray_start`.".format(
addon.name
),
exc_info=True
)
now = time.time()
report[addon.__class__.__name__] = now - prev_start_time
prev_start_time = now

if self._report is not None:
report[self._report_total_key] = time.time() - time_start
self._report["Addons start"] = report

def on_exit(self):
for addon in self.get_enabled_tray_addons():
if addon.tray_initialized:
try:
addon.tray_exit()
except Exception:
self.log.warning(
"Addon \"{}\" crashed on `tray_exit`.".format(
addon.name
),
exc_info=True
)

# DEPRECATED
def get_enabled_tray_modules(self):
return self.get_enabled_tray_addons()

def start_modules(self):
self.start_addons()
7 changes: 2 additions & 5 deletions client/ayon_core/cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ class Commands:
"""
@staticmethod
def launch_tray():
from ayon_core.lib import Logger
from ayon_core.tools import tray

Logger.set_process_name("Tray")
from ayon_core.tools.tray import main

tray.main()
main()

@staticmethod
def add_addons(click_func):
Expand Down
2 changes: 0 additions & 2 deletions client/ayon_core/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
load_modules,

ModulesManager,
TrayModulesManager,
)


Expand All @@ -38,5 +37,4 @@
"load_modules",

"ModulesManager",
"TrayModulesManager",
)
4 changes: 0 additions & 4 deletions client/ayon_core/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ayon_core.addon import (
AYONAddon,
AddonsManager,
TrayAddonsManager,
load_addons,
)
from ayon_core.addon.base import (
Expand All @@ -12,18 +11,15 @@
)

ModulesManager = AddonsManager
TrayModulesManager = TrayAddonsManager
load_modules = load_addons


__all__ = (
"AYONAddon",
"AddonsManager",
"TrayAddonsManager",
"load_addons",
"OpenPypeModule",
"OpenPypeAddOn",
"ModulesManager",
"TrayModulesManager",
"load_modules",
)
13 changes: 0 additions & 13 deletions client/ayon_core/modules/webserver/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion client/ayon_core/modules/webserver/version.py

This file was deleted.

Loading