Skip to content

Commit 1492a02

Browse files
committed
Added Copilot Key Settings
1 parent 2a32b10 commit 1492a02

File tree

5 files changed

+144
-12
lines changed

5 files changed

+144
-12
lines changed

GoAwayEdge/Common/Configuration.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.ComponentModel;
22
using System.IO;
33
using System.IO.Pipes;
4+
using System.Runtime.InteropServices;
45
using System.Windows;
56
using GoAwayEdge.Common.Debugging;
67
using ManagedShell;
@@ -10,10 +11,10 @@ namespace GoAwayEdge.Common
1011
{
1112
public enum SearchEngine
1213
{
13-
[Description("https://www.google.com/search?q=")]
14+
[Description("https://google.com/search?q=")]
1415
Google,
1516

16-
[Description("https://www.bing.com/search?q=")]
17+
[Description("https://bing.com/search?q=")]
1718
Bing,
1819

1920
[Description("https://duckduckgo.com/?q=")]
@@ -25,16 +26,16 @@ public enum SearchEngine
2526
[Description("https://yandex.com/search/?text=")]
2627
Yandex,
2728

28-
[Description("https://www.ecosia.org/search?q=")]
29+
[Description("https://ecosia.org/search?q=")]
2930
Ecosia,
3031

31-
[Description("https://www.ask.com/web?q=")]
32+
[Description("https://ask.com/web?q=")]
3233
Ask,
3334

3435
[Description("https://qwant.com/?q=")]
3536
Qwant,
3637

37-
[Description("https://www.perplexity.ai/search?copilot=false&q=")]
38+
[Description("https://perplexity.ai/search?copilot=false&q=")]
3839
Perplexity,
3940

4041
Custom
@@ -77,14 +78,18 @@ public enum WeatherProvider
7778
[Description("https://weather.com/{country-code}/weather/today/l/{latitude},{longitude}")]
7879
WeatherCom,
7980

80-
[Description("https://www.accuweather.com/{short-country-code}/search-locations?query={latitude},{longitude}")]
81+
[Description("https://accuweather.com/{short-country-code}/search-locations?query={latitude},{longitude}")]
8182
AccuWeather,
8283

8384
Custom
8485
}
8586

8687
internal class Configuration
8788
{
89+
[DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
90+
private static extern int SetCurrentProcessExplicitAppUserModelID(string appID);
91+
92+
8893
public static EdgeChannel Channel { get; set; }
8994
public static SearchEngine Search { get; set; }
9095
public static AiProvider AiProvider { get; set; }
@@ -110,6 +115,8 @@ internal class Configuration
110115

111116
public static ShellManager? ShellManager { get; set; }
112117
public static bool AppBarIsAttached { get; set; }
118+
public static string? CopilotExternalApp { get; set; }
119+
public static string? CopilotExternalAppArgument { get; set; }
113120

114121

115122
/// <summary>
@@ -152,6 +159,8 @@ public static bool InitialEnvironment(bool setupRunning = false)
152159
Search = Runtime.ArgumentParse.ParseSearchEngine(RegistryConfig.GetKey("SearchEngine"));
153160
AiProvider = Runtime.ArgumentParse.ParseAiProvider(RegistryConfig.GetKey("AiProvider", userSetting: true));
154161
WeatherProvider = Runtime.ArgumentParse.ParseWeatherProvider(RegistryConfig.GetKey("WeatherProvider", userSetting: true));
162+
CopilotExternalApp = RegistryConfig.GetKey("ExternalApp", userSetting: true);
163+
CopilotExternalAppArgument = RegistryConfig.GetKey("ExternalAppArgs", userSetting: true);
155164
if (Search == SearchEngine.Custom)
156165
{
157166
CustomQueryUrl = RegistryConfig.GetKey("CustomQueryUrl");
@@ -178,6 +187,12 @@ public static bool InitialEnvironment(bool setupRunning = false)
178187
Logging.Log($"Value of CustomQueryUrl: {CustomQueryUrl}");
179188
Logging.Log($"Value of CustomAiProviderUrl: {CustomAiProviderUrl}");
180189
Logging.Log($"Value of CustomWeatherProviderUrl: {CustomWeatherProviderUrl}");
190+
Logging.Log($"Value of CopilotExternalApp: {CopilotExternalApp}");
191+
Logging.Log($"Value of CopilotExternalAppArgument: {CopilotExternalAppArgument}");
192+
193+
// Test AUMID
194+
int result = SetCurrentProcessExplicitAppUserModelID("dev.valnoxy.GoAwayEdge");
195+
Logging.Log($"Result of AUMID: {result}");
181196
return true;
182197
}
183198
catch (Exception ex)

GoAwayEdge/Common/Runtime/Weather.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Buffers.Text;
2-
using System.Globalization;
3-
using System.Security.Policy;
1+
using System.Globalization;
42
using System.Text;
53
using System.Web;
64
using Newtonsoft.Json;

GoAwayEdge/Localization/ResourceDictionary.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
<system:String x:Key="ControlPanelWeatherProviderDescription">Change the service to your favorite Weather website.</system:String>
7575
<system:String x:Key="ControlPanelCustomWeatherProviderTitle">Custom Weather Service</system:String>
7676
<system:String x:Key="ControlPanelCustomWeatherProviderDescription">Please enter the URL from the Weather Service.</system:String>
77+
<system:String x:Key="CopilotKeyTitle">Copilot Key</system:String>
78+
<system:String x:Key="ControlPanelHotkeyExternalProgramTitle">External Program</system:String>
79+
<system:String x:Key="ControlPanelHotkeyExternalProgramDescription">???</system:String>
80+
<system:String x:Key="ControlPanelHotkeyExternalProgramPathTitle">Path to Application</system:String>
81+
<system:String x:Key="ControlPanelHotkeyExternalProgramPathDescription">Select the application you want to run.</system:String>
82+
<system:String x:Key="ControlPanelHotkeyExternalProgramArgsTitle">Arguments</system:String>
83+
<system:String x:Key="ControlPanelHotkeyExternalProgramArgsDescription">Define the arguments of your application.</system:String>
84+
<system:String x:Key="ControlPanelHotkeyExternalProgramNoSource">No source selected</system:String>
7785

7886
<!-- Error Handling / Notifications -->
7987
<system:String x:Key="FailedInitialization">Initialization failed: {0}</system:String>

GoAwayEdge/UserInterface/ControlPanel/Pages/CopilotSettings.xaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,76 @@
6363
</ui:CardControl.Header>
6464
</ui:CardControl>
6565
</StackPanel>
66+
67+
<ui:TextBlock FontTypography="Subtitle" Margin="0,10,0,0" Text="{DynamicResource CopilotKeyTitle}" Foreground="{DynamicResource TextFillColorPrimaryBrush}"/>
68+
<StackPanel Margin="0,5,0,0" >
69+
<ui:CardExpander Icon="{ui:SymbolIcon AppGeneric24}" IsExpanded="true">
70+
<ui:CardExpander.Header>
71+
<Grid>
72+
<Grid.ColumnDefinitions>
73+
<ColumnDefinition Width="*" />
74+
<ColumnDefinition Width="Auto" />
75+
</Grid.ColumnDefinitions>
76+
<StackPanel Grid.Column="0" VerticalAlignment="Center">
77+
<TextBlock
78+
FontSize="13"
79+
FontWeight="Medium"
80+
Text="{DynamicResource ControlPanelHotkeyExternalProgramTitle}" />
81+
<TextBlock
82+
FontSize="12"
83+
Text="{DynamicResource ControlPanelHotkeyExternalProgramDescription}" />
84+
</StackPanel>
85+
</Grid>
86+
</ui:CardExpander.Header>
87+
<StackPanel>
88+
<ui:CardControl Icon="{ui:SymbolIcon WindowApps24}" Margin="0,5,0,0">
89+
<ui:CardControl.Header>
90+
<Grid>
91+
<Grid.ColumnDefinitions>
92+
<ColumnDefinition Width="*" />
93+
<ColumnDefinition Width="Auto" />
94+
<ColumnDefinition Width="Auto" />
95+
</Grid.ColumnDefinitions>
96+
<StackPanel Grid.Column="0" VerticalAlignment="Center">
97+
<TextBlock FontSize="13"
98+
FontWeight="Medium"
99+
Text="{DynamicResource ControlPanelHotkeyExternalProgramPathTitle}" />
100+
<TextBlock FontSize="12"
101+
Foreground="{DynamicResource TextFillColorTertiaryBrush}"
102+
Text="{DynamicResource ControlPanelHotkeyExternalProgramPathDescription}" />
103+
</StackPanel>
104+
<ui:SymbolIcon Grid.Column="1" x:Name="ExternalAppStatus" Margin="0,0,10,0" FontSize="18"/>
105+
<ui:TextBox Grid.Column="2" Width="300" Height="35" Margin="10,0,0,0" Icon="{ui:SymbolIcon Settings24}" x:Name="ExternalAppTextBox" TextChanged="ExternalAppTextBox_OnTextChanged"/>
106+
</Grid>
107+
</ui:CardControl.Header>
108+
</ui:CardControl>
109+
<ui:CardControl Icon="{ui:SymbolIcon Settings24}" Margin="0,5,0,0">
110+
<ui:CardControl.Header>
111+
<Grid>
112+
<Grid.ColumnDefinitions>
113+
<ColumnDefinition Width="*" />
114+
<ColumnDefinition Width="Auto" />
115+
<ColumnDefinition Width="Auto" />
116+
</Grid.ColumnDefinitions>
117+
<StackPanel Grid.Column="0" VerticalAlignment="Center">
118+
<TextBlock FontSize="13"
119+
FontWeight="Medium"
120+
Text="{DynamicResource ControlPanelHotkeyExternalProgramArgsTitle}" />
121+
<TextBlock FontSize="12"
122+
Foreground="{DynamicResource TextFillColorTertiaryBrush}"
123+
Text="{DynamicResource ControlPanelHotkeyExternalProgramArgsDescription}" />
124+
</StackPanel>
125+
<TextBlock FontSize="12"
126+
Grid.Column="1"
127+
VerticalAlignment="Center"
128+
Foreground="{DynamicResource TextFillColorTertiaryBrush}"/>
129+
<ui:TextBox Grid.Column="2" Width="300" Height="35" Margin="10,0,0,0" Icon="{ui:SymbolIcon Settings24}" x:Name="ExternalAppArgsTextBox" TextChanged="ExternalAppArgsTextBox_OnTextChanged"/>
130+
</Grid>
131+
</ui:CardControl.Header>
132+
</ui:CardControl>
133+
</StackPanel>
134+
</ui:CardExpander>
135+
</StackPanel>
66136
</StackPanel>
67137
</ScrollViewer>
68138
</Page>

GoAwayEdge/UserInterface/ControlPanel/Pages/CopilotSettings.xaml.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows;
1+
using System.IO;
2+
using System.Windows;
23
using System.Windows.Controls;
34
using GoAwayEdge.Common;
45
using Wpf.Ui.Controls;
@@ -36,22 +37,39 @@ public CopilotSettings()
3637
if (Configuration.AiProvider == AiProvider.Default)
3738
CopilotProviderBox.SelectedItem = LocalizationManager.LocalizeValue("Default");
3839

40+
if (Configuration.CopilotExternalApp != null) ExternalAppTextBox.Text = Configuration.CopilotExternalApp;
41+
if (Configuration.CopilotExternalAppArgument != null) ExternalAppArgsTextBox.Text = Configuration.CopilotExternalAppArgument;
3942
}
4043

41-
private void FlushSettings()
44+
private static void FlushSettings()
4245
{
4346
try
4447
{
45-
RegistryConfig.SetKey("AiProvider", Configuration.AiProvider.ToString(), userSetting: true);
48+
// Ai Provider
4649
if (Configuration.AiProvider == AiProvider.Custom)
4750
{
4851
if (Configuration.CustomAiProviderUrl != null)
52+
{
53+
RegistryConfig.SetKey("AiProvider", Configuration.AiProvider.ToString(), userSetting: true);
4954
RegistryConfig.SetKey("CustomAiProviderUrl", Configuration.CustomAiProviderUrl, userSetting: true);
55+
}
5056
}
5157
else
5258
{
59+
RegistryConfig.SetKey("AiProvider", Configuration.AiProvider.ToString(), userSetting: true);
5360
RegistryConfig.RemoveKey("CustomAiProviderUrl", userSetting: true);
5461
}
62+
63+
// External App
64+
if (Configuration.CopilotExternalApp != null)
65+
RegistryConfig.SetKey("ExternalApp", Configuration.CopilotExternalApp, userSetting: true);
66+
else
67+
RegistryConfig.RemoveKey("ExternalApp", userSetting: true);
68+
69+
if (Configuration.CopilotExternalAppArgument != null)
70+
RegistryConfig.SetKey("ExternalAppArgs", Configuration.CopilotExternalAppArgument, userSetting: true);
71+
else
72+
RegistryConfig.RemoveKey("ExternalAppArgs", userSetting: true);
5573
}
5674
catch (Exception ex)
5775
{
@@ -115,5 +133,28 @@ private void QueryProviderTextBox_OnTextChanged(object sender, TextChangedEventA
115133
CustomUrlStatus.Symbol = SymbolRegular.ErrorCircle24;
116134
}
117135
}
136+
137+
private void ExternalAppTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
138+
{
139+
// Test if the file exists
140+
if (File.Exists(ExternalAppTextBox.Text))
141+
{
142+
ExternalAppStatus.Symbol = SymbolRegular.CheckmarkCircle24;
143+
Configuration.CopilotExternalApp = ExternalAppTextBox.Text;
144+
FlushSettings();
145+
}
146+
else
147+
{
148+
ExternalAppStatus.Symbol = SymbolRegular.ErrorCircle24;
149+
}
150+
}
151+
152+
private void ExternalAppArgsTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
153+
{
154+
if (ExternalAppStatus.Symbol != SymbolRegular.CheckmarkCircle24) return;
155+
156+
Configuration.CopilotExternalAppArgument = ExternalAppArgsTextBox.Text;
157+
FlushSettings();
158+
}
118159
}
119160
}

0 commit comments

Comments
 (0)