refactor(systray): rely on fabric stock icon handling
Upstream fabric now resolves tray icons correctly, so the local pixbuf fallback patch is gone. The patch keeps only config-based item hiding by wrapping do_update_properties.
This commit is contained in:
3 files changed
+12
-62
No files matched your search
+1
-1
@@ -106,4 +106,4 @@ known-first-party = ["services", "utils", "shared", "window"]
|
|||||||
"examples/**" = ["INP001", "D101", "D102", "D103"]
|
"examples/**" = ["INP001", "D101", "D102", "D103"]
|
||||||
|
|
||||||
[tool.uv.sources]
|
[tool.uv.sources]
|
||||||
fabric = { git = "https://github.com/Fabric-Development/fabric.git", tag = "v0.0.2" }
|
fabric = { git = "https://github.com/Fabric-Development/fabric.git" }
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
import weakref
|
import weakref
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from fabric.system_tray.widgets import SystemTrayItem
|
from fabric.system_tray.widgets import SystemTrayItem
|
||||||
from fabric.utils import GdkPixbuf, GLib, logger
|
from fabric.utils import logger
|
||||||
|
|
||||||
from services.config import get_config, on_config_change
|
from services.config import get_config, on_config_change
|
||||||
|
|
||||||
@@ -27,62 +26,6 @@ def should_hide(item) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def patched_do_update_properties(self, *_):
|
|
||||||
# Determine the icon name to use
|
|
||||||
item = self._item
|
|
||||||
icon_name = item.icon_name
|
|
||||||
attention_icon_name = item.attention_icon_name
|
|
||||||
|
|
||||||
# Log item info for user debugging
|
|
||||||
logger.info(
|
|
||||||
f"[SysTray] Item: title='{getattr(item, 'title', '')}', identifier='{getattr(item, 'identifier', '')}'"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Visibility check
|
|
||||||
is_hidden = should_hide(item)
|
|
||||||
self.set_visible(not is_hidden)
|
|
||||||
|
|
||||||
if is_hidden:
|
|
||||||
return
|
|
||||||
|
|
||||||
if item.status == "NeedsAttention" and attention_icon_name:
|
|
||||||
preferred_icon_name = attention_icon_name
|
|
||||||
else:
|
|
||||||
preferred_icon_name = icon_name
|
|
||||||
|
|
||||||
# 1. Try the standard fabric/GTK implementation first
|
|
||||||
pixbuf = item.get_preferred_icon_pixbuf(self._icon_size)
|
|
||||||
|
|
||||||
# 2. If standard lookup fails, try your specific absolute path logic
|
|
||||||
if pixbuf is None and preferred_icon_name:
|
|
||||||
path = Path(preferred_icon_name)
|
|
||||||
if path.is_absolute() and path.exists():
|
|
||||||
try:
|
|
||||||
target_size = self._icon_size if self._icon_size else 24
|
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
|
||||||
str(path),
|
|
||||||
target_size,
|
|
||||||
target_size,
|
|
||||||
True, # Preserve aspect ratio
|
|
||||||
)
|
|
||||||
except GLib.GError:
|
|
||||||
pixbuf = None
|
|
||||||
|
|
||||||
# Apply the resulting pixbuf or the fallback "missing" icon
|
|
||||||
if pixbuf:
|
|
||||||
self._image.set_from_pixbuf(pixbuf)
|
|
||||||
else:
|
|
||||||
self._image.set_from_icon_name("image-missing", self._icon_size)
|
|
||||||
|
|
||||||
tooltip = item.tooltip
|
|
||||||
self.set_tooltip_markup(
|
|
||||||
tooltip.description
|
|
||||||
or tooltip.title
|
|
||||||
or (item.title.title() if item.title else None)
|
|
||||||
or "Unknown"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def apply_enhanced_system_tray():
|
def apply_enhanced_system_tray():
|
||||||
# Patch __init__ to track instances
|
# Patch __init__ to track instances
|
||||||
original_init = SystemTrayItem.__init__
|
original_init = SystemTrayItem.__init__
|
||||||
@@ -93,7 +36,14 @@ def apply_enhanced_system_tray():
|
|||||||
|
|
||||||
SystemTrayItem.__init__ = patched_init
|
SystemTrayItem.__init__ = patched_init
|
||||||
|
|
||||||
# Replace the method on the class so all tray items use this logic
|
# Wrap the stock implementation so fabric keeps handling icons,
|
||||||
|
# while we enforce the configured visibility rules
|
||||||
|
original_do_update_properties = SystemTrayItem.do_update_properties
|
||||||
|
|
||||||
|
def patched_do_update_properties(self, *_):
|
||||||
|
original_do_update_properties(self)
|
||||||
|
self.set_visible(not should_hide(self._item))
|
||||||
|
|
||||||
SystemTrayItem.do_update_properties = patched_do_update_properties
|
SystemTrayItem.do_update_properties = patched_do_update_properties
|
||||||
|
|
||||||
# Setup hot-reload listener
|
# Setup hot-reload listener
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ wheels = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "fabric"
|
name = "fabric"
|
||||||
version = "0.0.2"
|
version = "0.0.2"
|
||||||
source = { git = "https://github.com/Fabric-Development/fabric.git?tag=v0.0.2#85cacf660b1a324525a4dd9b512521e55ef7f89b" }
|
source = { git = "https://github.com/Fabric-Development/fabric.git#75471c13456e504d20120cab7b1e4a660e2a108d" }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "click" },
|
{ name = "click" },
|
||||||
{ name = "loguru" },
|
{ name = "loguru" },
|
||||||
@@ -268,7 +268,7 @@ dev = [
|
|||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "fabric", git = "https://github.com/Fabric-Development/fabric.git?tag=v0.0.2" },
|
{ name = "fabric", git = "https://github.com/Fabric-Development/fabric.git" },
|
||||||
{ name = "keyring", specifier = "==25.7.0" },
|
{ name = "keyring", specifier = "==25.7.0" },
|
||||||
{ name = "keyrings-alt", specifier = "==5.0.2" },
|
{ name = "keyrings-alt", specifier = "==5.0.2" },
|
||||||
{ name = "psutil", specifier = "==7.2.2" },
|
{ name = "psutil", specifier = "==7.2.2" },
|
||||||
|
|||||||
Reference in new issue
Block a user