Add support for per-feed user agent

This commit is contained in:
2023-06-15 17:28:38 -04:00
parent f5f78c8825
commit 0ddd38e3f2
7 changed files with 126 additions and 43 deletions

View File

@@ -94,6 +94,13 @@
<ComboBoxItem Content="{x:Static properties:Resources.openAllMultipleToolbarButton}"
Tag="{x:Static feedCenter:MultipleOpenAction.IndividualPages}" />
</ComboBox>
<ComboBox Name="UserAgentComboBox"
mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="{x:Static properties:Resources.userAgentLabel}"
DisplayMemberPath="Caption"
ItemsSource="{Binding Source={x:Static options:UserAgentItem.UserAgents}}"
SelectedValuePath="UserAgent"
SelectedValue="{Binding Path=UserAgent, UpdateSourceTrigger=Explicit, ValidatesOnExceptions=true}" />
</StackPanel>
</TabItem>
<TabItem Header="{x:Static properties:Resources.authenticationTab}">

View File

@@ -12,11 +12,9 @@
d:DesignWidth="300">
<StackPanel options:Spacing.Vertical="10">
<CheckBox Content="{x:Static properties:Resources.startWithWindowsCheckBox}"
Name="StartWithWindowsCheckBox"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=StartWithWindows}"
Click="OnSaveSettings" />
<ComboBox Name="BrowserComboBox"
mah:TextBoxHelper.UseFloatingWatermark="True"
<ComboBox mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="{x:Static properties:Resources.defaultBrowserLabel}"
d:DataContext="{d:DesignInstance Type=installedBrowsers:InstalledBrowser}"
DisplayMemberPath="Name"
@@ -24,12 +22,11 @@
SelectedValuePath="Key"
SelectedValue="{Binding Source={x:Static properties:Settings.Default}, Path=Browser}"
SelectionChanged="OnSaveSettings" />
<ComboBox Name="UserAgentComboBox"
mah:TextBoxHelper.UseFloatingWatermark="True"
<ComboBox mah:TextBoxHelper.UseFloatingWatermark="True"
mah:TextBoxHelper.Watermark="{x:Static properties:Resources.defaultUserAgentLabel}"
d:DataContext="{d:DesignInstance Type=options:UserAgentItem}"
DisplayMemberPath="Caption"
ItemsSource="{Binding Source={x:Static options:UserAgentItem.UserAgents}}"
ItemsSource="{Binding Source={x:Static options:UserAgentItem.DefaultUserAgents}}"
SelectedValuePath="UserAgent"
SelectedValue="{Binding Source={x:Static properties:Settings.Default}, Path=DefaultUserAgent}"
SelectionChanged="OnSaveSettings" />

View File

@@ -1,17 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using FeedCenter.Properties;
namespace FeedCenter.Options;
public class UserAgentItem
{
public string Caption { get; set; }
public string UserAgent { get; set; }
public static List<UserAgentItem> UserAgents => new()
public static List<UserAgentItem> DefaultUserAgents => new()
{
new UserAgentItem
{
Caption = Properties.Resources.DefaultUserAgentCaption,
Caption = Properties.Resources.ApplicationUserAgentCaption,
UserAgent = string.Empty
},
new UserAgentItem
@@ -30,4 +31,29 @@ public class UserAgentItem
UserAgent = "curl/7.47.0"
}
};
public string UserAgent { get; set; }
public static List<UserAgentItem> UserAgents
{
get
{
var defaultUserAgents = DefaultUserAgents;
var applicationDefaultUserAgent = defaultUserAgents.First(dua => dua.UserAgent == Settings.Default.DefaultUserAgent);
var userAgents = new List<UserAgentItem>
{
new()
{
Caption = string.Format(Resources.DefaultUserAgentCaption, applicationDefaultUserAgent.Caption),
UserAgent = null
}
};
userAgents.AddRange(defaultUserAgents);
return userAgents;
}
}
}