mirror of
https://github.com/Stone-Red-Code/Markdowser.git
synced 2026-09-04 09:06:15 +02:00
Add UserAgent setting
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Markdowser.Utilities;
|
||||
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Markdowser.Models;
|
||||
@@ -15,6 +16,8 @@ public class Settings
|
||||
|
||||
public string? HomeUrl { get; set; }
|
||||
|
||||
public string UserAgent { get; set; } = $"{Assembly.GetExecutingAssembly().GetName().Name}/{Assembly.GetExecutingAssembly().GetName().Version?.ToString()}";
|
||||
|
||||
public static void SaveSettings()
|
||||
{
|
||||
if (!Directory.Exists(Configuration.ApplicationDataPath))
|
||||
|
||||
@@ -161,7 +161,6 @@ public partial class MainWindowViewModel : ViewModelBase
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd($"{nameof(Markdowser)}/{Assembly.GetExecutingAssembly().GetName().Version?.ToString()}");
|
||||
httpClient.Timeout = TimeSpan.FromSeconds(10);
|
||||
|
||||
content = DefaultContent;
|
||||
@@ -232,6 +231,13 @@ public partial class MainWindowViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
httpClient.DefaultRequestHeaders.UserAgent.Clear();
|
||||
if (!httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd(Settings.Current.UserAgent))
|
||||
{
|
||||
WindowNotificationManager.Show(new Notification("Invalid User Agent", "Failed to set user agent.", NotificationType.Error));
|
||||
return;
|
||||
}
|
||||
|
||||
IsBusy = true;
|
||||
Progress = 0;
|
||||
|
||||
|
||||
@@ -16,6 +16,12 @@ public class SettingsViewModel : ViewModelBase
|
||||
set => Settings.Current.SearchEngineUrl = value;
|
||||
}
|
||||
|
||||
public string UserAgent
|
||||
{
|
||||
get => Settings.Current.UserAgent;
|
||||
set => Settings.Current.UserAgent = value;
|
||||
}
|
||||
|
||||
public bool DarkMode
|
||||
{
|
||||
get => Settings.Current.DarkMode;
|
||||
|
||||
@@ -28,5 +28,8 @@
|
||||
|
||||
<TextBlock Text="Home URL" />
|
||||
<TextBox Text="{Binding HomeUrl}" Watermark="URL, or leave empty to use default" />
|
||||
|
||||
<TextBlock Text="User Agent" />
|
||||
<TextBox Text="{Binding UserAgent}" Watermark="User agent string" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
Reference in New Issue
Block a user