Skip to content

Commit

Permalink
Fix IME not working in some scenarios. (#16476)
Browse files Browse the repository at this point in the history
* Fix IME not working in some scenarios.

* If other services trigger `OnNameChange` before `GetNameOwnerAsync`, then we will incorrectly connect to other services, and will be stuck at `Connect`. We should ignore irrelevant services.

* `WatchNameOwnerChangedAsync` should be called only once.

* Add log.
  • Loading branch information
kkwpsv authored Sep 12, 2024
1 parent 9e43170 commit ad8e67c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Avalonia.Input.Raw;
Expand Down Expand Up @@ -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}");
}
}
}
Expand All @@ -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);
Expand Down

0 comments on commit ad8e67c

Please sign in to comment.