Add search engine url setting

This commit is contained in:
Stone_Red
2024-04-10 11:14:20 +02:00
parent cbe32f7bdf
commit 4f3c59a32c
5 changed files with 20 additions and 2 deletions
+2
View File
@@ -11,6 +11,8 @@ public class Settings
public bool DarkMode { get; set; }
public string SearchEngineUrl { get; set; } = "https://duckduckgo.com/html/?kd=-1&k1=-1&q={0}";
public string? HomeUrl { get; set; }
public static void SaveSettings()
@@ -220,7 +220,14 @@ public partial class MainWindowViewModel : ViewModelBase
else
{
// Search with duckduckgo
Url = $"https://duckduckgo.com/html/?kd=-1&k1=-1&q={Uri.EscapeDataString(Url)}";
try
{
Url = string.Format(Settings.Current.SearchEngineUrl, Uri.EscapeDataString(Url));
}
catch (FormatException ex)
{
WindowNotificationManager.Show(new Notification("Invalid Search Engine URL", $"{ex.Message}", NotificationType.Error));
}
}
}
@@ -10,6 +10,12 @@ public class SettingsViewModel : ViewModelBase
set => Settings.Current.HomeUrl = value;
}
public string SearchEngineUrl
{
get => Settings.Current.SearchEngineUrl;
set => Settings.Current.SearchEngineUrl = value;
}
public bool DarkMode
{
get => Settings.Current.DarkMode;
+1 -1
View File
@@ -87,7 +87,7 @@
<Button Grid.Column="3" i:Attached.Icon="fa-solid fa-house" Command="{StaticResource HomeCommand}" />
<Grid Grid.Column="4">
<TextBox IsVisible="{Binding !IsBusy}" Watermark="Search DuckDuckGo or type a URL" Text="{Binding Url}" BorderThickness="0">
<TextBox IsVisible="{Binding !IsBusy}" Watermark="Search or type a URL" Text="{Binding Url}" BorderThickness="0">
<TextBox.KeyBindings>
<KeyBinding Gesture="Enter" Command="{Binding Browse}" />
</TextBox.KeyBindings>
+3
View File
@@ -23,6 +23,9 @@
<TextBlock Text="Dark Mode" />
<ToggleSwitch IsChecked="{Binding DarkMode}" Command="{StaticResource ChangeThemeCommand}" />
<TextBlock Text="Search Engine URL" />
<TextBox Text="{Binding SearchEngineUrl}" Watermark="URL with {0} as encoded search query" />
<TextBlock Text="Home URL" />
<TextBox Text="{Binding HomeUrl}" Watermark="URL, or leave empty to use default" />
</StackPanel>