Browse Source

Log DBus Exceptions

pull/11526/head
affederaffe 3 years ago
parent
commit
d94c0670c8
  1. 2
      samples/ControlCatalog/Pages/DialogsPage.xaml.cs
  2. 3
      src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs
  3. 4
      src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxX11TextInputMethod.cs
  4. 7
      src/Avalonia.FreeDesktop/DBusIme/IBus/IBusX11TextInputMethod.cs
  5. 18
      src/Avalonia.FreeDesktop/DBusSystemDialog.cs

2
samples/ControlCatalog/Pages/DialogsPage.xaml.cs

@ -307,7 +307,7 @@ namespace ControlCatalog.Pages
Content:
";
resultText += await ReadTextFromFile(file, 10000);
resultText += await ReadTextFromFile(file, 500);
}
openedFileContent.Text = resultText;

3
src/Avalonia.FreeDesktop/DBusIme/DBusTextInputMethodBase.cs

@ -76,7 +76,10 @@ namespace Avalonia.FreeDesktop.DBusIme
private async void OnNameChange(Exception? e, (string ServiceName, string? OldOwner, string? NewOwner) args)
{
if (e is not null)
{
Logger.TryGet(LogEventLevel.Error, LogArea.FreeDesktopPlatform)?.Log(this, $"OnNameChange failed: {e}");
return;
}
if (args.NewOwner is not null && _currentName is null)
{

4
src/Avalonia.FreeDesktop/DBusIme/Fcitx/FcitxX11TextInputMethod.cs

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Avalonia.Input;
using Avalonia.Input.Raw;
using Avalonia.Input.TextInput;
using Avalonia.Logging;
using Tmds.DBus.Protocol;
using Tmds.DBus.SourceGenerator;
@ -138,7 +139,10 @@ namespace Avalonia.FreeDesktop.DBusIme.Fcitx
private void OnCommitString(Exception? e, string s)
{
if (e is not null)
{
Logger.TryGet(LogEventLevel.Error, LogArea.FreeDesktopPlatform)?.Log(this, $"OnCommitString failed: {e}");
return;
}
FireCommit(s);
}

7
src/Avalonia.FreeDesktop/DBusIme/IBus/IBusX11TextInputMethod.cs

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using Avalonia.Input;
using Avalonia.Input.Raw;
using Avalonia.Input.TextInput;
using Avalonia.Logging;
using Tmds.DBus.Protocol;
using Tmds.DBus.SourceGenerator;
@ -31,7 +32,10 @@ namespace Avalonia.FreeDesktop.DBusIme.IBus
private void OnForwardKey(Exception? e, (uint keyval, uint keycode, uint state) k)
{
if (e is not null)
{
Logger.TryGet(LogEventLevel.Error, LogArea.FreeDesktopPlatform)?.Log(this, $"OnForwardKey failed: {e}");
return;
}
var state = (IBusModifierMask)k.state;
KeyModifiers mods = default;
@ -54,7 +58,10 @@ namespace Avalonia.FreeDesktop.DBusIme.IBus
private void OnCommitText(Exception? e, DBusVariantItem variantItem)
{
if (e is not null)
{
Logger.TryGet(LogEventLevel.Error, LogArea.FreeDesktopPlatform)?.Log(this, $"OnCommitText failed: {e}");
return;
}
if (variantItem.Value is DBusStructItem { Count: >= 3 } structItem && structItem[2] is DBusStringItem stringItem)
FireCommit(stringItem.Value);

18
src/Avalonia.FreeDesktop/DBusSystemDialog.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Platform;
using Avalonia.Platform.Storage;
@ -66,8 +67,9 @@ namespace Avalonia.FreeDesktop
using var disposable = await request.WatchResponseAsync((e, x) =>
{
if (e is not null)
return;
tsc.TrySetResult((x.results["uris"].Value as DBusArrayItem)?.Select(static y => (y as DBusStringItem)!.Value).ToArray());
tsc.TrySetException(e);
else
tsc.TrySetResult((x.results["uris"].Value as DBusArrayItem)?.Select(static y => (y as DBusStringItem)!.Value).ToArray());
});
var uris = await tsc.Task ?? Array.Empty<string>();
@ -86,7 +88,7 @@ namespace Avalonia.FreeDesktop
if (options.SuggestedFileName is { } currentName)
chooserOptions.Add("current_name", new DBusVariantItem("s", new DBusStringItem(currentName)));
if (options.SuggestedStartLocation?.TryGetLocalPath() is { } folderPath)
chooserOptions.Add("current_folder", new DBusVariantItem("s", new DBusStringItem(folderPath)));
chooserOptions.Add("current_folder", new DBusVariantItem("ay", new DBusArrayItem(DBusType.Byte, Encoding.UTF8.GetBytes(folderPath).Select(static x => new DBusByteItem(x)))));
objectPath = await _fileChooser.SaveFileAsync(parentWindow, options.Title ?? string.Empty, chooserOptions);
var request = new OrgFreedesktopPortalRequest(_connection, "org.freedesktop.portal.Desktop", objectPath);
@ -94,8 +96,9 @@ namespace Avalonia.FreeDesktop
using var disposable = await request.WatchResponseAsync((e, x) =>
{
if (e is not null)
return;
tsc.TrySetResult((x.results["uris"].Value as DBusArrayItem)?.Select(static y => (y as DBusStringItem)!.Value).ToArray());
tsc.TrySetException(e);
else
tsc.TrySetResult((x.results["uris"].Value as DBusArrayItem)?.Select(static y => (y as DBusStringItem)!.Value).ToArray());
});
var uris = await tsc.Task;
@ -124,8 +127,9 @@ namespace Avalonia.FreeDesktop
using var disposable = await request.WatchResponseAsync((e, x) =>
{
if (e is not null)
return;
tsc.TrySetResult((x.results["uris"].Value as DBusArrayItem)?.Select(static y => (y as DBusStringItem)!.Value).ToArray());
tsc.TrySetException(e);
else
tsc.TrySetResult((x.results["uris"].Value as DBusArrayItem)?.Select(static y => (y as DBusStringItem)!.Value).ToArray());
});
var uris = await tsc.Task ?? Array.Empty<string>();

Loading…
Cancel
Save