Skip to content

Commit

Permalink
update dbus stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacato committed Jun 25, 2024
1 parent 755120b commit 066bcab
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Tmds.DBus.Protocol" Version="0.17.0" />
<PackageReference Include="Tmds.DBus.SourceGenerator" Version="0.0.16" PrivateAssets="all" />
<PackageReference Include="Tmds.DBus.Protocol" Version="0.19.0" />
<PackageReference Include="Tmds.DBus.SourceGenerator" Version="0.0.17" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 13 additions & 7 deletions src/Avalonia.FreeDesktop/DBusMenuExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public DBusMenuExporterImpl(Connection connection, IntPtr xid)
InitBackingProperties();
Connection = connection;
_xid = (uint)xid.ToInt32();
Path = GenerateDBusMenuObjPath;
TargetPath = GenerateDBusMenuObjPath;
_pathHandler = new PathHandler(TargetPath);
_pathHandler.Add(this);
SetNativeMenu(new NativeMenu());
_ = InitializeAsync();
}
Expand All @@ -53,19 +55,21 @@ public DBusMenuExporterImpl(Connection connection, string path)
InitBackingProperties();
Connection = connection;
_appMenu = false;
Path = path;
TargetPath = path;
_pathHandler = new PathHandler(TargetPath);
_pathHandler.Add(this);
SetNativeMenu(new NativeMenu());
_ = InitializeAsync();
}

public string TargetPath { get; set; }

private void InitBackingProperties()
{
Version = 4;
}

protected override Connection Connection { get; }

public override string Path { get; }
public override Connection Connection { get; }

protected override ValueTask<(uint Revision, (int, Dictionary<string, Variant>, Variant[]) Layout)> OnGetLayoutAsync(int parentId, int recursionDepth, string[] propertyNames)
{
Expand Down Expand Up @@ -106,15 +110,15 @@ protected override ValueTask<int[]> OnEventGroupAsync((int, string, VariantValue

private async Task InitializeAsync()
{
Connection.AddMethodHandler(this);
Connection.AddMethodHandler(_pathHandler);
if (!_appMenu)
return;

_registrar = new ComCanonicalAppMenuRegistrar(Connection, "com.canonical.AppMenu.Registrar", "/com/canonical/AppMenu/Registrar");
try
{
if (!_disposed)
await _registrar.RegisterWindowAsync(_xid, Path);
await _registrar.RegisterWindowAsync(_xid, TargetPath);
}
catch
{
Expand Down Expand Up @@ -217,6 +221,8 @@ private int GetId(NativeMenuItemBase item)
"type", "label", "enabled", "visible", "shortcut", "toggle-type", "children-display", "toggle-state", "icon-data"
};

private PathHandler _pathHandler;

private static Variant? GetProperty((NativeMenuItemBase? item, NativeMenu? menu) i, string name)
{
var (it, menu) = i;
Expand Down
14 changes: 9 additions & 5 deletions src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal class DBusTrayIconImpl : ITrayIconImpl
private bool _isDisposed;
private bool _serviceConnected;
private bool _isVisible = true;
private readonly PathHandler _pathHandler1;

public bool IsActive { get; private set; }
public INativeMenuExporter? MenuExporter { get; }
Expand All @@ -56,7 +57,9 @@ public DBusTrayIconImpl()
MenuExporter = DBusMenuExporter.TryCreateDetachedNativeMenu(_dbusMenuPath, _connection);

_statusNotifierItemDbusObj = new StatusNotifierItemDbusObj(_connection, _dbusMenuPath);
_connection.AddMethodHandler(_statusNotifierItemDbusObj);
_pathHandler1 = new PathHandler("/StatusNotifierItem");
_pathHandler1.Add(_statusNotifierItemDbusObj);
_connection.AddMethodHandler(_pathHandler1);

WatchAsync();
}
Expand Down Expand Up @@ -212,19 +215,20 @@ public void SetToolTipText(string? text)
/// </remarks>
internal class StatusNotifierItemDbusObj : OrgKdeStatusNotifierItem
{
private readonly PathHandler _pathHandler;

public StatusNotifierItemDbusObj(Connection connection, ObjectPath dbusMenuPath)
{
Connection = connection;
Menu = dbusMenuPath;
_pathHandler = new PathHandler(dbusMenuPath);
_pathHandler.Add(this);
InvalidateAll();
}

protected override Connection Connection { get; }

public override string Path => "/StatusNotifierItem";

public event Action? ActivationDelegate;

public override Connection Connection { get; }
protected override ValueTask OnContextMenuAsync(int x, int y) => new();

protected override ValueTask OnActivateAsync(int x, int y)
Expand Down
27 changes: 0 additions & 27 deletions src/Browser/Avalonia.Browser/webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 066bcab

Please sign in to comment.