Detect webview crash and disable webview login

This commit is contained in:
Michael Bucari-Tovo
2025-11-10 12:47:48 -07:00
committed by Mbucari
parent 7a01f075ac
commit c878b9fec0
6 changed files with 30 additions and 6 deletions

View File

@@ -222,6 +222,7 @@ public class App : Application
// logging is init'd here
AppScaffolding.LibationScaffolding.RunPostMigrationScaffolding(AppScaffolding.Variety.Chardonnay, config);
Program.LoggingEnabled = true;
}
private static void ShowMainWindow(IClassicDesktopStyleApplicationLifetime desktop)

View File

@@ -8,7 +8,7 @@
x:DataType="vm:ImportantSettingsVM"
x:Class="LibationAvalonia.Controls.Settings.Important">
<Grid RowDefinitions="Auto,Auto,Auto,*">
<Grid RowDefinitions="Auto,Auto,Auto,Auto,*">
<controls:GroupBox
Grid.Row="0"
Margin="5"
@@ -69,9 +69,16 @@
</StackPanel>
</controls:GroupBox>
<CheckBox
Grid.Row="1"
Margin="10,5"
IsChecked="{CompiledBinding UseWebView, Mode=TwoWay}">
<TextBlock Text="{CompiledBinding UseWebViewText}" />
</CheckBox>
<StackPanel
Grid.Row="1" Margin="5"
Grid.Row="2" Margin="5"
Orientation="Horizontal">
<TextBlock
@@ -96,7 +103,7 @@
</StackPanel>
<controls:GroupBox
Grid.Row="2"
Grid.Row="3"
Margin="5"
Label="Display Settings">
<Grid
@@ -151,7 +158,7 @@
</controls:GroupBox>
<Grid
Grid.Row="3"
Grid.Row="4"
ColumnDefinitions="Auto,Auto,*"
Margin="10"
VerticalAlignment="Bottom">

View File

@@ -28,7 +28,7 @@ namespace LibationAvalonia.Dialogs.Login
{
try
{
if (await BrowserLoginAsync(choiceIn.LoginUrl) is ChoiceOut external)
if (Configuration.Instance.UseWebView && await BrowserLoginAsync(choiceIn.LoginUrl) is ChoiceOut external)
return external;
}
catch (Exception ex)

View File

@@ -5,6 +5,7 @@ using System.Threading.Tasks;
using ApplicationServices;
using AppScaffolding;
using Avalonia;
using Avalonia.Controls;
using ReactiveUI.Avalonia;
using LibationFileManager;
using LibationAvalonia.Dialogs;
@@ -18,7 +19,7 @@ namespace LibationAvalonia
static class Program
{
private static System.Threading.Lock SetupLock { get; } = new();
private static bool LoggingEnabled { get; set; }
internal static bool LoggingEnabled { get; set; }
[STAThread]
static void Main(string[] args)
{
@@ -64,6 +65,13 @@ namespace LibationAvalonia
}
catch (Exception ex)
{
if (new StackTrace(ex).GetFrames().Any(f => f.GetMethod()?.DeclaringType == typeof(NativeWebDialog)))
{
//Many of the NativeWebDialog exceptions cannot be handled by user code,
//so a webview failure is a fatal error. Disable webview usage and rely
//on the external browser login method instead.
Configuration.Instance.UseWebView = false;
}
LogAndShowCrashMessage(ex);
}
}

View File

@@ -25,6 +25,7 @@ namespace LibationAvalonia.ViewModels.Settings
OverwriteExisting = config.OverwriteExisting;
CreationTime = DateTimeSources.SingleOrDefault(v => v.Value == config.CreationTime) ?? DateTimeSources[0];
LastWriteTime = DateTimeSources.SingleOrDefault(v => v.Value == config.LastWriteTime) ?? DateTimeSources[0];
UseWebView = config.UseWebView;
LoggingLevel = config.LogLevel;
GridScaleFactor = scaleFactorToLinearRange(config.GridScaleFactor);
GridFontScaleFactor = scaleFactorToLinearRange(config.GridFontScaleFactor);
@@ -41,6 +42,7 @@ namespace LibationAvalonia.ViewModels.Settings
config.OverwriteExisting = OverwriteExisting;
config.CreationTime = CreationTime.Value;
config.LastWriteTime = LastWriteTime.Value;
config.UseWebView = UseWebView;
config.LogLevel = LoggingLevel;
}
@@ -83,6 +85,8 @@ namespace LibationAvalonia.ViewModels.Settings
= Enum.GetValues<Configuration.DateTimeSource>()
.Select(v => new EnumDisplay<Configuration.DateTimeSource>(v))
.ToArray();
public string UseWebViewText { get; } = Configuration.GetDescription(nameof(Configuration.UseWebView));
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));
@@ -96,6 +100,7 @@ namespace LibationAvalonia.ViewModels.Settings
public float GridFontScaleFactor { get; set; }
public EnumDisplay<Configuration.DateTimeSource> CreationTime { get; set; }
public EnumDisplay<Configuration.DateTimeSource> LastWriteTime { get; set; }
public bool UseWebView { get; set; }
public Serilog.Events.LogEventLevel LoggingLevel { get; set; }
public string ThemeVariant

View File

@@ -326,6 +326,9 @@ namespace LibationFileManager
[Description("Automatically run periodic scans in the background?")]
public bool AutoScan { get => GetNonString(defaultValue: true); set => SetNonString(value); }
[Description("Use Libation's buit-in web broswer to log into Audible?")]
public bool UseWebView { get => GetNonString(defaultValue: true); set => 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
public bool AutoDownloadEpisodes { get => GetNonString(defaultValue: false); set => SetNonString(value); }