Browse Source

Fix IME not working in some scenarios. (#16476)

* 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.
pull/17021/head
Shaojun Li 2 years ago
committed by GitHub
parent
commit
ad8e67c177
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 20
      src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs

20
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 @@ namespace Avalonia.FreeDesktop.DBusIme
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 @@ namespace Avalonia.FreeDesktop.DBusIme
return;
}
if (!_knownNames.Contains(args.ServiceName))
{
return;
}
if (args.NewOwner is not null && _currentName is null)
{
_onlineNamesQueue.Enqueue(args.ServiceName);

Loading…
Cancel
Save