|
|
|
@ -13,7 +13,9 @@ using Tmds.DBus; |
|
|
|
[assembly: InternalsVisibleTo(Connection.DynamicAssemblyName)] |
|
|
|
|
|
|
|
#if SIGNED_BUILD
|
|
|
|
[assembly: InternalsVisibleTo("Avalonia.X11, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] |
|
|
|
[assembly: |
|
|
|
InternalsVisibleTo( |
|
|
|
"Avalonia.X11, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87")] |
|
|
|
#else
|
|
|
|
[assembly: InternalsVisibleTo("Avalonia.X11")] |
|
|
|
#endif
|
|
|
|
@ -23,10 +25,10 @@ namespace Avalonia.FreeDesktop |
|
|
|
internal class DBusTrayIconImpl : ITrayIconImpl |
|
|
|
{ |
|
|
|
private static int s_trayIconInstanceId; |
|
|
|
|
|
|
|
|
|
|
|
private readonly ObjectPath _dbusMenuPath; |
|
|
|
private readonly Connection? _connection; |
|
|
|
private readonly IDisposable? _serviceWatchDisposable; |
|
|
|
private IDisposable? _serviceWatchDisposable; |
|
|
|
|
|
|
|
private StatusNotifierItemDbusObj? _statusNotifierItemDbusObj; |
|
|
|
private IStatusNotifierWatcher? _statusNotifierWatcher; |
|
|
|
@ -37,11 +39,11 @@ namespace Avalonia.FreeDesktop |
|
|
|
private bool _isDisposed; |
|
|
|
private bool _serviceConnected; |
|
|
|
private bool _isVisible = true; |
|
|
|
|
|
|
|
|
|
|
|
public bool IsActive { get; private set; } |
|
|
|
public INativeMenuExporter? MenuExporter { get; } |
|
|
|
public Action? OnClicked { get; set; } |
|
|
|
public Func<IWindowIconImpl?, uint[]> IconConverterDelegate { get; set; } |
|
|
|
public Func<IWindowIconImpl?, uint[]> IconConverterDelegate { get; set; } |
|
|
|
|
|
|
|
public DBusTrayIconImpl() |
|
|
|
{ |
|
|
|
@ -56,12 +58,12 @@ namespace Avalonia.FreeDesktop |
|
|
|
} |
|
|
|
|
|
|
|
IsActive = true; |
|
|
|
|
|
|
|
|
|
|
|
_dbusMenuPath = DBusMenuExporter.GenerateDBusMenuObjPath; |
|
|
|
|
|
|
|
|
|
|
|
MenuExporter = DBusMenuExporter.TryCreateDetachedNativeMenu(_dbusMenuPath, _connection); |
|
|
|
|
|
|
|
_serviceWatchDisposable = WatchAsync(); |
|
|
|
|
|
|
|
WatchAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
private void InitializeSNWService() |
|
|
|
@ -85,10 +87,22 @@ namespace Avalonia.FreeDesktop |
|
|
|
|
|
|
|
_serviceConnected = true; |
|
|
|
} |
|
|
|
|
|
|
|
private Task<IDisposable> WatchAsync() => |
|
|
|
_connection?.ResolveServiceOwnerAsync("org.kde.StatusNotifierWatcher", OnNameChange)!; |
|
|
|
|
|
|
|
|
|
|
|
private async void WatchAsync() |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
_serviceWatchDisposable = |
|
|
|
await _connection?.ResolveServiceOwnerAsync("org.kde.StatusNotifierWatcher", OnNameChange)!; |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
Logger.TryGet(LogEventLevel.Error, "DBUS") |
|
|
|
?.Log(this, |
|
|
|
$"Unable to hook watcher method on org.kde.StatusNotifierWatcher: {e}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void OnNameChange(ServiceOwnerChangedEventArgs obj) |
|
|
|
{ |
|
|
|
if (_isDisposed) |
|
|
|
@ -112,6 +126,7 @@ namespace Avalonia.FreeDesktop |
|
|
|
_serviceConnected = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CreateTrayIcon() |
|
|
|
{ |
|
|
|
if (_connection is null || !_serviceConnected || _isDisposed) |
|
|
|
@ -122,7 +137,7 @@ namespace Avalonia.FreeDesktop |
|
|
|
|
|
|
|
_sysTrayServiceName = $"org.kde.StatusNotifierItem-{pid}-{tid}"; |
|
|
|
_statusNotifierItemDbusObj = new StatusNotifierItemDbusObj(_dbusMenuPath); |
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
_connection.RegisterObjectAsync(_statusNotifierItemDbusObj); |
|
|
|
@ -133,7 +148,7 @@ namespace Avalonia.FreeDesktop |
|
|
|
{ |
|
|
|
Logger.TryGet(LogEventLevel.Error, "DBUS") |
|
|
|
?.Log(this, $"Error creating a DBus tray icon: {e}."); |
|
|
|
|
|
|
|
|
|
|
|
_serviceConnected = false; |
|
|
|
} |
|
|
|
|
|
|
|
@ -170,12 +185,12 @@ namespace Avalonia.FreeDesktop |
|
|
|
{ |
|
|
|
_statusNotifierItemDbusObj?.SetIcon(DbusPixmap.EmptyPixmap); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var x11iconData = IconConverterDelegate(icon); |
|
|
|
|
|
|
|
if(x11iconData.Length == 0) return; |
|
|
|
|
|
|
|
|
|
|
|
if (x11iconData.Length == 0) return; |
|
|
|
|
|
|
|
var w = (int)x11iconData[0]; |
|
|
|
var h = (int)x11iconData[1]; |
|
|
|
|
|
|
|
|