Browse Source

Use Tmds.DBus.SourceGenerator 0.0.3

pull/10651/head
affederaffe 3 years ago
parent
commit
b4b3b913f1
  1. 2
      src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj
  2. 43
      src/Avalonia.FreeDesktop/DBusMenuExporter.cs
  3. 21
      src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs

2
src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj

@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Tmds.DBus.Protocol" Version="0.14.0" />
<PackageReference Include="Tmds.DBus.SourceGenerator" Version="0.0.2" />
<PackageReference Include="Tmds.DBus.SourceGenerator" Version="0.0.3" />
</ItemGroup>
<ItemGroup>

43
src/Avalonia.FreeDesktop/DBusMenuExporter.cs

@ -60,38 +60,43 @@ namespace Avalonia.FreeDesktop
public override string Path { get; }
protected override (uint revision, (int, Dictionary<string, DBusVariantItem>, DBusVariantItem[]) layout) OnGetLayout(int parentId, int recursionDepth, string[] propertyNames)
{
var menu = GetMenu(parentId);
var layout = GetLayout(menu.item, menu.menu, recursionDepth, propertyNames);
if (!IsNativeMenuExported)
protected override async ValueTask<(uint revision, (int, Dictionary<string, DBusVariantItem>, DBusVariantItem[]) layout)> OnGetLayoutAsync(int parentId, int recursionDepth, string[]? propertyNames) =>
await Dispatcher.UIThread.InvokeAsync(() =>
{
IsNativeMenuExported = true;
Dispatcher.UIThread.Post(() => OnIsNativeMenuExportedChanged?.Invoke(this, EventArgs.Empty));
}
var menu = GetMenu(parentId);
var layout = GetLayout(menu.item, menu.menu, recursionDepth, propertyNames);
if (!IsNativeMenuExported)
{
IsNativeMenuExported = true;
OnIsNativeMenuExportedChanged?.Invoke(this, EventArgs.Empty);
}
return (_revision, layout);
}
return (_revision, layout);
});
protected override (int, Dictionary<string, DBusVariantItem>)[] OnGetGroupProperties(int[] ids, string[] propertyNames) =>
ids.Select(id => (id, GetProperties(GetMenu(id), propertyNames))).ToArray();
protected override async ValueTask<(int, Dictionary<string, DBusVariantItem>)[]> OnGetGroupPropertiesAsync(int[] ids, string[] propertyNames) =>
await Dispatcher.UIThread.InvokeAsync(() => ids.Select(id => (id, GetProperties(GetMenu(id), propertyNames))).ToArray());
protected override DBusVariantItem OnGetProperty(int id, string name) => GetProperty(GetMenu(id), name) ?? new DBusVariantItem("i", new DBusInt32Item(0));
protected override async ValueTask<DBusVariantItem> OnGetPropertyAsync(int id, string name) =>
await Dispatcher.UIThread.InvokeAsync(() => GetProperty(GetMenu(id), name) ?? new DBusVariantItem("i", new DBusInt32Item(0)));
protected override void OnEvent(int id, string eventId, DBusVariantItem data, uint timestamp) =>
protected override ValueTask OnEventAsync(int id, string eventId, DBusVariantItem data, uint timestamp)
{
Dispatcher.UIThread.Post(() => HandleEvent(id, eventId));
return new ValueTask();
}
protected override int[] OnEventGroup((int, string, DBusVariantItem, uint)[] events)
protected override ValueTask<int[]> OnEventGroupAsync((int, string, DBusVariantItem, uint)[] events)
{
foreach (var e in events)
Dispatcher.UIThread.Post(() => HandleEvent(e.Item1, e.Item2));
return Array.Empty<int>();
return new ValueTask<int[]>(Array.Empty<int>());
}
protected override bool OnAboutToShow(int id) => false;
protected override ValueTask<bool> OnAboutToShowAsync(int id) => new(false);
protected override (int[] updatesNeeded, int[] idErrors) OnAboutToShowGroup(int[] ids) =>
(Array.Empty<int>(), Array.Empty<int>());
protected override ValueTask<(int[] updatesNeeded, int[] idErrors)> OnAboutToShowGroupAsync(int[] ids) =>
new((Array.Empty<int>(), Array.Empty<int>()));
private async Task InitializeAsync()
{

21
src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs

@ -1,8 +1,10 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Avalonia.Controls.Platform;
using Avalonia.Logging;
using Avalonia.Platform;
using Avalonia.Threading;
using Tmds.DBus.Protocol;
using Tmds.DBus.SourceGenerator;
@ -219,13 +221,6 @@ namespace Avalonia.FreeDesktop
Connection = connection;
BackingProperties.Menu = dbusMenuPath;
BackingProperties.ToolTip = (string.Empty, Array.Empty<(int, int, byte[])>(), string.Empty, string.Empty);
BackingProperties.IconName = string.Empty;
BackingProperties.AttentionIconName = string.Empty;
BackingProperties.AttentionIconPixmap = new []{ DBusTrayIconImpl.EmptyPixmap };
BackingProperties.AttentionMovieName = string.Empty;
BackingProperties.IconThemePath = string.Empty;
BackingProperties.OverlayIconName = string.Empty;
BackingProperties.OverlayIconPixmap = new []{ DBusTrayIconImpl.EmptyPixmap };
InvalidateAll();
}
@ -235,13 +230,17 @@ namespace Avalonia.FreeDesktop
public event Action? ActivationDelegate;
protected override void OnContextMenu(int x, int y) { }
protected override ValueTask OnContextMenuAsync(int x, int y) => new();
protected override void OnActivate(int x, int y) => ActivationDelegate?.Invoke();
protected override ValueTask OnActivateAsync(int x, int y)
{
Dispatcher.UIThread.Post(() => ActivationDelegate?.Invoke());
return new ValueTask();
}
protected override void OnSecondaryActivate(int x, int y) { }
protected override ValueTask OnSecondaryActivateAsync(int x, int y) => new();
protected override void OnScroll(int delta, string orientation) { }
protected override ValueTask OnScrollAsync(int delta, string orientation) => new();
public void InvalidateAll()
{

Loading…
Cancel
Save