Bug fix #1664 - WebView breaks catastrophically under Linux Snap -- segfault with no logged errors

This commit is contained in:
rmcrackan
2026-03-11 13:00:19 -04:00
parent 760b0dcb6b
commit 5cf710756f
7 changed files with 42 additions and 18 deletions

View File

@@ -72,10 +72,18 @@
<CheckBox
Grid.Row="1"
Margin="10,5"
IsEnabled="{CompiledBinding !UseWebViewSettingDisabled}"
IsChecked="{CompiledBinding UseWebView, Mode=TwoWay}">
<TextBlock Text="{CompiledBinding UseWebViewText}" />
</CheckBox>
<StackPanel>
<TextBlock Text="{CompiledBinding UseWebViewText}" />
<TextBlock
IsVisible="{CompiledBinding UseWebViewSettingDisabled}"
FontStyle="Italic"
Opacity="0.8"
Margin="0,2,0,0"
Text="{CompiledBinding UseWebViewSnapMessage}" />
</StackPanel>
</CheckBox>
<StackPanel
Grid.Row="2" Margin="5"

View File

@@ -1,4 +1,4 @@
using AudibleApi;
using AudibleApi;
using AudibleUtilities;
using Avalonia.Controls;
using Avalonia.Platform;
@@ -34,7 +34,7 @@ public class AvaloniaLoginChoiceEager : ILoginChoiceEager
}
catch (Exception ex)
{
Serilog.Log.Logger.Error(ex, $"Failed to use the {nameof(NativeWebDialog)}");
Serilog.Log.Logger.Warning(ex, "WebView login failed; falling back to external browser");
}
var externalDialog = new LoginExternalDialog(_account, choiceIn.LoginUrl);
@@ -44,6 +44,19 @@ public class AvaloniaLoginChoiceEager : ILoginChoiceEager
}
private async Task<ChoiceOut?> BrowserLoginAsync(ChoiceIn shoiceIn)
{
try
{
return await BrowserLoginAsyncCore(shoiceIn);
}
catch (Exception ex)
{
Serilog.Log.Logger.Warning(ex, "In-app browser failed; falling back to external browser");
return null;
}
}
private async Task<ChoiceOut?> BrowserLoginAsyncCore(ChoiceIn shoiceIn)
{
TaskCompletionSource<ChoiceOut?> tcs = new();

View File

@@ -52,6 +52,7 @@ static class Program
if (config.LibationFiles.SettingsAreValid)
{
App.RunMigrations(config);
// When running inside Snap, UseWebView getter returns false to avoid portal/sandbox crashes (e.g. github ticket #1664).
//Start loading the library before loading the main form
App.LibraryTask = Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
}

View File

@@ -1,4 +1,4 @@
using Dinah.Core;
using Dinah.Core;
using FileManager;
using LibationFileManager;
using LibationUiBase;
@@ -83,6 +83,9 @@ public class ImportantSettingsVM : ViewModelBase
.ToArray();
public string UseWebViewText { get; } = Configuration.GetDescription(nameof(Configuration.UseWebView));
/// <summary>When true, the Use WebView setting is disabled (e.g. when running in Snap to avoid portal/sandbox crashes).</summary>
public bool UseWebViewSettingDisabled => Configuration.IsRunningUnderSnap;
public string UseWebViewSnapMessage { get; } = Configuration.IsRunningUnderSnap ? "Disabled when running in Snap (avoids login crash). Use external browser instead." : "";
public Serilog.Events.LogEventLevel[] LoggingLevels { get; } = Enum.GetValues<Serilog.Events.LogEventLevel>();
public string GridScaleFactorText { get; } = Configuration.GetDescription(nameof(Configuration.GridScaleFactor));
public string GridFontScaleFactorText { get; } = Configuration.GetDescription(nameof(Configuration.GridFontScaleFactor));

View File

@@ -1,4 +1,4 @@
using System;
using System;
namespace LibationFileManager;
@@ -24,6 +24,10 @@ public partial class Configuration
public static bool IsWindows { get; } = OperatingSystem.IsWindows();
public static bool IsLinux { get; } = OperatingSystem.IsLinux();
public static bool IsMacOs { get; } = OperatingSystem.IsMacOS();
/// <summary>True when running inside a (Linux) Snap sandbox (e.g. snap run libation). WebView login is disabled in this environment to avoid portal/sandbox crashes.</summary>
public static bool IsRunningUnderSnap { get; } = IsLinux && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SNAP"));
public static Version? LibationVersion { get; private set; }
public static void SetLibationVersion(Version? version) => LibationVersion = version;

View File

@@ -1,4 +1,4 @@
using FileManager;
using FileManager;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
@@ -344,7 +344,11 @@ public partial class Configuration
public bool AutoScan { get => GetNonString(defaultValue: false); set => SetNonString(value); }
[Description("Use Libation's built-in web browser to log into Audible?")]
public bool UseWebView { get => GetNonString(defaultValue: true); set => SetNonString(value); }
public bool UseWebView
{
get => Configuration.IsRunningUnderSnap ? false : GetNonString(defaultValue: true);
set { if (!Configuration.IsRunningUnderSnap) SetNonString(value); }
}
[Description("Auto download books? After scan, download new books in 'checked' accounts.")]
// poorly named setting. Should just be 'AutoDownload'. It is NOT episode specific

View File

@@ -1,9 +0,0 @@
{
"$schema": "https://json.schemastore.org/global.json",
"sdk": {
"version": "10.0.101"
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}