Skip to content

Commit

Permalink
feat: AI Search selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinguin2001 committed Dec 22, 2024
1 parent 3cfeff7 commit d48bf1c
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExce

private void LoadSettings()
{
AISearchUrl = SettingsHelper.GetSetting("AISearchUrl") ?? "https://www.perplexity.ai/search?q=";
SearchUrl = SettingsHelper.GetSetting("SearchUrl") ?? "https://www.qwant.com/?q=";

if (SettingsHelper.GetSetting("ForceDark") == "true")
Expand Down
Binary file added src/Assets/AISparkles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/Bluebird.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Assets\AISparkles.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\Backgrounds\Attributions.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
1 change: 1 addition & 0 deletions src/Core/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static MainPage MainPageContent
}
// Global variables
public static StorageFolder localFolder = ApplicationData.Current.LocalFolder;
public static string AISearchUrl { get; set; }
public static string SearchUrl { get; set; }
public static string StartupUrl { get; set; }

Expand Down
6 changes: 6 additions & 0 deletions src/Core/SearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ public class SearchEngine(string EngineFriendlyName, string SearchUrl)
public string EngineFriendlyName { get; set; } = EngineFriendlyName;
public string SearchUrl { get; set; } = SearchUrl;
}

public enum SearchEngineType
{
AI,
Classic
}
26 changes: 22 additions & 4 deletions src/Core/SearchEngineHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

public class SearchEngineHelper
{
public static void SetSearchEngine(SearchEngine engine)
public static void SetSearchEngine(SearchEngine engine, SearchEngineType engineType)
{
SettingsHelper.SetSetting("EngineFriendlyName", engine.EngineFriendlyName);
SettingsHelper.SetSetting("SearchUrl", engine.SearchUrl);
SearchUrl = engine.SearchUrl;
if (engineType == SearchEngineType.AI)
{
SettingsHelper.SetSetting("AIEngineFriendlyName", engine.EngineFriendlyName);
SettingsHelper.SetSetting("AISearchUrl", engine.SearchUrl);
AISearchUrl = engine.SearchUrl;
return;
}

if (engineType == SearchEngineType.Classic)
{
SettingsHelper.SetSetting("EngineFriendlyName", engine.EngineFriendlyName);
SettingsHelper.SetSetting("SearchUrl", engine.SearchUrl);
SearchUrl = engine.SearchUrl;
return;
}
}

public static List<SearchEngine> SearchEngines =
Expand All @@ -23,4 +35,10 @@ public static void SetSearchEngine(SearchEngine engine)
new SearchEngine("Yahoo!", "https://search.yahoo.com/search?p="),
new SearchEngine("Yandex", "https://yandex.com/search/?text=")
];

public static List<SearchEngine> AISearchEngines =
[
new SearchEngine("ChatGPT", "https://chatgpt.com/?q="),
new SearchEngine("Perplexity.ai", "https://www.perplexity.ai/search?q=")
];
}
2 changes: 1 addition & 1 deletion src/Pages/NewTabPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void AISearchButton_Click(object sender, RoutedEventArgs e)
string query = UrlBox.Text;
if (!string.IsNullOrEmpty(query))
{
NavigateToUrl("https://www.perplexity.ai/search?q=" + query);
NavigateToUrl(AISearchUrl + query);
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
</ComboBox.ItemTemplate>
</ComboBox>
</toolkitc:SettingsCard>
<toolkitc:SettingsCard Header="AI search engine">
<toolkitc:SettingsCard.HeaderIcon>
<BitmapIcon ShowAsMonochrome="False" UriSource="/Assets/AISparkles.png" />
</toolkitc:SettingsCard.HeaderIcon>
<ComboBox x:Name="AISearchEngineSelector">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="core:SearchEngine">
<TextBlock Text="{x:Bind EngineFriendlyName}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</toolkitc:SettingsCard>
<!-- Data -->
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="Personalization" />
<toolkitc:SettingsCard Description="Clear all user data" Header="Clear data">
Expand Down
20 changes: 18 additions & 2 deletions src/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
// General
SearchEngineSelector.ItemsSource = SearchEngineHelper.SearchEngines;
string SearchEngine = SettingsHelper.GetSetting("EngineFriendlyName");

foreach (SearchEngine engine in SearchEngineHelper.SearchEngines)
{
if (engine.SearchUrl == SearchUrl)
Expand All @@ -26,6 +25,16 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
}
}

AISearchEngineSelector.ItemsSource = SearchEngineHelper.AISearchEngines;
string AISearchEngine = SettingsHelper.GetSetting("AIEngineFriendlyName");
foreach (SearchEngine AIengine in SearchEngineHelper.AISearchEngines)
{
if (AIengine.SearchUrl == AISearchUrl)
{
AISearchEngineSelector.SelectedItem = AIengine;
}
}

if (SettingsHelper.GetSetting("ForceDark") == "true")
ForceDarkSwitch.IsOn = true;

Expand All @@ -42,6 +51,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)

// Set event handlers
SearchEngineSelector.SelectionChanged += SearchEngineSelector_SelectionChanged;
AISearchEngineSelector.SelectionChanged += AISearchEngineSelector_SelectionChanged;
ForceDarkSwitch.Toggled += ForceDarkSwitch_Toggled;
CompactTabsToggle.Toggled += CompactTabsToggle_Toggled;
NewTabBgImageToggle.Toggled += NewTabBgImageToggle_Toggled;
Expand All @@ -51,7 +61,13 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
private void SearchEngineSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SearchEngine engine = e.AddedItems[0] as SearchEngine;
SearchEngineHelper.SetSearchEngine(engine);
SearchEngineHelper.SetSearchEngine(engine, SearchEngineType.Classic);
}

private void AISearchEngineSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
SearchEngine engine = e.AddedItems[0] as SearchEngine;
SearchEngineHelper.SetSearchEngine(engine, SearchEngineType.AI);
}

private async void ClearUserDataButton_Click(object sender, RoutedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/WebViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private void AISearchButton_Click(object sender, RoutedEventArgs e)
string query = UrlBox.Text;
if (!string.IsNullOrEmpty(query))
{
NavigateToUrl("https://www.perplexity.ai/search?q=" + query);
NavigateToUrl(AISearchUrl + query);
}
}

Expand Down

0 comments on commit d48bf1c

Please sign in to comment.