diff --git a/src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs b/src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs index 158321acf5c..764bc9df157 100644 --- a/src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs +++ b/src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Threading.Tasks; using Avalonia.Input.Raw; @@ -59,17 +60,25 @@ public DBusTextInputMethodBase(Connection connection, params string[] knownNames private async Task WatchAsync() { + var dbus = new OrgFreedesktopDBus(Connection, "org.freedesktop.DBus", "/org/freedesktop/DBus"); + try + { + _disposables.Add(await dbus.WatchNameOwnerChangedAsync(OnNameChange)); + } + catch (DBusException e) + { + Logger.TryGet(LogEventLevel.Error, LogArea.FreeDesktopPlatform)?.Log(this, $"WatchNameOwnerChangedAsync failed: {e}"); + } foreach (var name in _knownNames) { - var dbus = new OrgFreedesktopDBus(Connection, "org.freedesktop.DBus", "/org/freedesktop/DBus"); try { - _disposables.Add(await dbus.WatchNameOwnerChangedAsync(OnNameChange)); var nameOwner = await dbus.GetNameOwnerAsync(name); OnNameChange(null, (name, null, nameOwner)); } - catch (DBusException) + catch (DBusException e) { + Logger.TryGet(LogEventLevel.Error, LogArea.FreeDesktopPlatform)?.Log(this, $"GetNameOwnerAsync failed: {e}"); } } } @@ -87,6 +96,11 @@ private async void OnNameChange(Exception? e, (string ServiceName, string? OldOw return; } + if (!_knownNames.Contains(args.ServiceName)) + { + return; + } + if (args.NewOwner is not null && _currentName is null) { _onlineNamesQueue.Enqueue(args.ServiceName);