Skip to content

Commit 2a32b10

Browse files
committed
Added Microsoft Copilot
1 parent bd36fd5 commit 2a32b10

File tree

9 files changed

+138
-73
lines changed

9 files changed

+138
-73
lines changed

GoAwayEdge/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
9393
{
9494
Configuration.InitialEnvironment();
9595

96-
if (Configuration.AiProvider != AiProvider.Copilot)
96+
if (Configuration.AiProvider != AiProvider.Default)
9797
{
9898
DebugMessage.DisplayDebugMessage("GoAwayEdge",
9999
$"Opening AI Provider '{Configuration.AiProvider}' (Triggered with argument) ...");
@@ -104,7 +104,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
104104
{
105105
IsDebug = true;
106106
DebugMessage.DisplayDebugMessage("GoAwayEdge",
107-
"You cannot open the Copilot dock if your AI provider is Copilot.");
107+
"You cannot open the Copilot dock if your AI provider is set to default");
108108
Environment.Exit(1);
109109
}
110110
}

GoAwayEdge/Common/Configuration.cs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,55 @@ namespace GoAwayEdge.Common
1010
{
1111
public enum SearchEngine
1212
{
13+
[Description("https://www.google.com/search?q=")]
1314
Google,
15+
16+
[Description("https://www.bing.com/search?q=")]
1417
Bing,
18+
19+
[Description("https://duckduckgo.com/?q=")]
1520
DuckDuckGo,
21+
22+
[Description("https://search.yahoo.com/search?p=")]
1623
Yahoo,
24+
25+
[Description("https://yandex.com/search/?text=")]
1726
Yandex,
27+
28+
[Description("https://www.ecosia.org/search?q=")]
1829
Ecosia,
30+
31+
[Description("https://www.ask.com/web?q=")]
1932
Ask,
33+
34+
[Description("https://qwant.com/?q=")]
2035
Qwant,
36+
37+
[Description("https://www.perplexity.ai/search?copilot=false&q=")]
2138
Perplexity,
39+
2240
Custom
2341
}
2442

2543
public enum AiProvider
2644
{
45+
Default,
46+
47+
[Description("https://copilot.microsoft.com/")]
2748
Copilot,
49+
50+
[Description("https://chatgpt.com/")]
2851
ChatGPT,
52+
53+
[Description("https://gemini.google.com/")]
2954
Gemini,
55+
56+
[Description("https://github.com/copilot")]
3057
GitHub_Copilot,
58+
59+
[Description("https://x.com/i/grok")]
3160
Grok,
61+
3262
Custom
3363
}
3464

@@ -72,6 +102,12 @@ internal class Configuration
72102
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
73103
"valnoxy",
74104
"GoAwayEdge");
105+
106+
public static string UserDir = Path.Combine(
107+
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
108+
"valnoxy",
109+
"GoAwayEdge");
110+
75111
public static ShellManager? ShellManager { get; set; }
76112
public static bool AppBarIsAttached { get; set; }
77113

@@ -226,7 +262,7 @@ public static List<string> GetSearchEngines()
226262
public static List<string> GetAiProviders()
227263
{
228264
var list = (from aiProvider in (AiProvider[])Enum.GetValues(typeof(AiProvider))
229-
where aiProvider != AiProvider.Custom
265+
where aiProvider != AiProvider.Custom && aiProvider != AiProvider.Default
230266
select aiProvider.ToString().Replace("_", " ")).ToList();
231267

232268
try
@@ -240,19 +276,30 @@ public static List<string> GetAiProviders()
240276
list.Add("Custom");
241277
}
242278

279+
try
280+
{
281+
var resourceValueDefault =
282+
(string)Application.Current.MainWindow!.FindResource("Default");
283+
list.Insert(0, !string.IsNullOrEmpty(resourceValueDefault) ? resourceValueDefault : "Default");
284+
}
285+
catch
286+
{
287+
list.Insert(0, "Default");
288+
}
289+
243290
return list;
244291
}
245292

246293
/// <summary>
247-
/// Get a list of all available AI Providers.
294+
/// Get a list of all available Weather Services.
248295
/// </summary>
249296
/// <returns>
250-
/// List of AI Providers.
297+
/// List of Weather Services.
251298
/// </returns>
252299
public static List<string> GetWeatherProviders()
253300
{
254301
var list = (from weatherProvider in (WeatherProvider[])Enum.GetValues(typeof(WeatherProvider))
255-
where (weatherProvider != WeatherProvider.Custom && weatherProvider != WeatherProvider.Default)
302+
where weatherProvider != WeatherProvider.Custom && weatherProvider != WeatherProvider.Default
256303
select weatherProvider.ToString().Replace("_", " ")).ToList();
257304

258305
try

GoAwayEdge/Common/Installation/InstallRoutine.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,28 @@ public static void Uninstall(object? sender, DoWorkEventArgs? e = null)
290290
return;
291291
}
292292

293+
// Remove user directory
294+
try
295+
{
296+
if (Directory.Exists(Configuration.UserDir))
297+
{
298+
var dir = new DirectoryInfo(Configuration.UserDir);
299+
dir.Delete(true);
300+
}
301+
}
302+
catch (Exception ex)
303+
{
304+
Logging.Log("Failed to delete user directory: " + ex, Logging.LogLevel.ERROR);
305+
Application.Current.Dispatcher.Invoke(() =>
306+
{
307+
var errorMessage = LocalizationManager.LocalizeValue("FailedUninstallation", ex.Message);
308+
var messageUi = new MessageUi("GoAwayEdge", errorMessage, "OK");
309+
messageUi.ShowDialog();
310+
});
311+
Environment.Exit(1);
312+
return;
313+
}
314+
293315
// Remove Ifeo & Uri handler from registry
294316
try
295317
{

GoAwayEdge/Common/Runtime/ArgumentParse.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using System.IO;
3+
using System.Text.RegularExpressions;
34
using GoAwayEdge.Common.Debugging;
45

56
namespace GoAwayEdge.Common.Runtime
@@ -40,6 +41,20 @@ public static void Parse(string[] args)
4041
}
4142
else if (isApp)
4243
{
44+
const string pattern = @"--app-id=([^\s]+)";
45+
const string copilotAppId = "khiogjgiicnghciboipemonlmgelhblf";
46+
var match = Regex.Match(argumentJoin, pattern);
47+
if (match.Success)
48+
{
49+
var appId = match.Groups[1].Value;
50+
Logging.Log($"Opening PWA App with ID {appId}");
51+
if (appId == copilotAppId)
52+
{
53+
DebugMessage.DisplayDebugMessage("GoAwayEdge", $"Opening AI Provider '{Configuration.AiProvider}' (PWA) ...");
54+
UserInterface.CopilotDock.InterfaceManager.ShowDock();
55+
return;
56+
}
57+
}
4358
StartProcess(FileConfiguration.NonIfeoPath, singleArgument, $"Opening PWA Application with following arguments: '{singleArgument}'.");
4459
}
4560
}
@@ -198,13 +213,14 @@ public static AiProvider ParseAiProvider(string argument)
198213
{
199214
return argument.ToLower() switch
200215
{
216+
"default" => AiProvider.Default,
201217
"copilot" => AiProvider.Copilot,
202218
"chatgpt" => AiProvider.ChatGPT,
203219
"gemini" => AiProvider.Gemini,
204220
"github_copilot" => AiProvider.GitHub_Copilot,
205221
"grok" => AiProvider.Grok,
206222
"custom" => AiProvider.Custom,
207-
_ => AiProvider.Copilot // Fallback provider
223+
_ => AiProvider.Default // Fallback provider
208224
};
209225
}
210226

GoAwayEdge/Common/Runtime/UrlParse.cs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ public static string Parse(string encodedUrl)
2929
// Decode Url
3030
encodedUrl = encodedUrl.Contains("redirect") ? DotSlash(encodedUrl) : DecodeUrlString(encodedUrl);
3131

32+
// Get new URL
33+
var definedEngineUrl = Configuration.Search == SearchEngine.Custom
34+
? Configuration.CustomQueryUrl : Configuration.GetEnumDescription(Configuration.Search);
35+
3236
// Replace Search Engine
33-
encodedUrl = encodedUrl.Replace("https://www.bing.com/search?q=", DefineEngine(Configuration.Search));
37+
encodedUrl = encodedUrl.Replace("https://www.bing.com/search?q=", definedEngineUrl);
3438

3539
#if DEBUG
3640
var uriMessageUi = new MessageUi("GoAwayEdge",
@@ -41,34 +45,6 @@ public static string Parse(string encodedUrl)
4145
return uri.ToString();
4246
}
4347

44-
private static string DefineEngine(SearchEngine engine)
45-
{
46-
var customQueryUrl = string.Empty;
47-
try
48-
{
49-
customQueryUrl = RegistryConfig.GetKey("CustomQueryUrl");
50-
}
51-
catch
52-
{
53-
// ignore; not an valid object
54-
}
55-
56-
return engine switch
57-
{
58-
SearchEngine.Google => "https://www.google.com/search?q=",
59-
SearchEngine.Bing => "https://www.bing.com/search?q=",
60-
SearchEngine.DuckDuckGo => "https://duckduckgo.com/?q=",
61-
SearchEngine.Yahoo => "https://search.yahoo.com/search?p=",
62-
SearchEngine.Yandex => "https://yandex.com/search/?text=",
63-
SearchEngine.Ecosia => "https://www.ecosia.org/search?q=",
64-
SearchEngine.Ask => "https://www.ask.com/web?q=",
65-
SearchEngine.Qwant => "https://qwant.com/?q=",
66-
SearchEngine.Perplexity => "https://www.perplexity.ai/search?copilot=false&q=",
67-
SearchEngine.Custom => customQueryUrl,
68-
_ => "https://www.google.com/search?q="
69-
};
70-
}
71-
7248
private static string DecodeUrlString(string url)
7349
{
7450
string newUrl;

GoAwayEdge/Localization/ResourceDictionary.de-DE.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
<system:String x:Key="MessageGoAwayEdgeEnabled">GoAwayEdge wurde auf diesem System erfolgreich aktiviert.</system:String>
8484
<system:String x:Key="FailedSetAppDisabled">GoAwayEdge konnte auf diesem System nicht deaktiviert werden: {0}</system:String>
8585
<system:String x:Key="ControlPanelCopilotProviderTitle">KI Anbieter</system:String>
86-
<system:String x:Key="ControlPanelCopilotProviderDescription">Wechseln Sie den Anbieter Ihrer bevorzugten KI (oder zu Ihrer bevorzugten Webseite).</system:String>
86+
<system:String x:Key="ControlPanelCopilotProviderDescription">Wechsel den Anbieter Ihrer bevorzugten KI (oder zu Ihrer bevorzugten Webseite).</system:String>
8787
<system:String x:Key="ControlPanelCustomCopilotProviderTitle">Benutzerdefinierter KI Anbieter</system:String>
88-
<system:String x:Key="ControlPanelCustomCopilotProviderDescription">Bitte geben Sie die URL des KI-Anbieters (oder einer Webseite) ein.</system:String>
88+
<system:String x:Key="ControlPanelCustomCopilotProviderDescription">Bitte gebe die URL des KI-Anbieters (oder einer Webseite) ein.</system:String>
8989
<system:String x:Key="FailedFlushSetting">Die Einstellungen konnten nicht übernommen werden: {0}</system:String>
9090
</ResourceDictionary>

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public CopilotSettings()
3232
{
3333
CopilotProviderBox.SelectedItem = Configuration.AiProvider.ToString();
3434
}
35+
36+
if (Configuration.AiProvider == AiProvider.Default)
37+
CopilotProviderBox.SelectedItem = LocalizationManager.LocalizeValue("Default");
38+
3539
}
3640

3741
private void FlushSettings()
@@ -65,26 +69,30 @@ private void CopilotProviderBox_OnSelectionChanged(object sender, SelectionChang
6569
switch (CopilotProviderBox.SelectedIndex)
6670
{
6771
case 0:
68-
Configuration.AiProvider = AiProvider.Copilot;
72+
Configuration.AiProvider = AiProvider.Default;
6973
CustomSearchPanel.Visibility = Visibility.Collapsed;
7074
break;
7175
case 1:
72-
Configuration.AiProvider = AiProvider.ChatGPT;
76+
Configuration.AiProvider = AiProvider.Copilot;
7377
CustomSearchPanel.Visibility = Visibility.Collapsed;
7478
break;
7579
case 2:
76-
Configuration.AiProvider = AiProvider.Gemini;
80+
Configuration.AiProvider = AiProvider.ChatGPT;
7781
CustomSearchPanel.Visibility = Visibility.Collapsed;
7882
break;
7983
case 3:
80-
Configuration.AiProvider = AiProvider.GitHub_Copilot;
84+
Configuration.AiProvider = AiProvider.Gemini;
8185
CustomSearchPanel.Visibility = Visibility.Collapsed;
8286
break;
8387
case 4:
84-
Configuration.AiProvider = AiProvider.Grok;
88+
Configuration.AiProvider = AiProvider.GitHub_Copilot;
8589
CustomSearchPanel.Visibility = Visibility.Collapsed;
8690
break;
8791
case 5:
92+
Configuration.AiProvider = AiProvider.Grok;
93+
CustomSearchPanel.Visibility = Visibility.Collapsed;
94+
break;
95+
case 6:
8896
Configuration.AiProvider = AiProvider.Custom;
8997
CustomSearchPanel.Visibility = Visibility.Visible;
9098
break;

GoAwayEdge/UserInterface/CopilotDock/CopilotDock.xaml.cs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,13 @@ private async Task InitializeWebViewAsync()
4141
var webView2Environment = await CoreWebView2Environment.CreateAsync(userDataFolder: userProfilePath);
4242
await WebView.EnsureCoreWebView2Async(webView2Environment);
4343

44-
switch (Configuration.AiProvider)
44+
var providerUrl = Configuration.AiProvider == Custom
45+
? Configuration.CustomAiProviderUrl : Configuration.GetEnumDescription(Configuration.AiProvider);
46+
if (providerUrl != null) WebView.Source = new Uri(providerUrl);
47+
else
4548
{
46-
case ChatGPT:
47-
WebView.Source = new Uri("https://chatgpt.com/");
48-
break;
49-
case Gemini:
50-
WebView.Source = new Uri("https://gemini.google.com/");
51-
break;
52-
case GitHub_Copilot:
53-
WebView.Source = new Uri("https://github.com/copilot");
54-
break;
55-
case Grok:
56-
WebView.Source = new Uri("https://x.com/i/grok");
57-
break;
58-
case Custom:
59-
if (Configuration.CustomAiProviderUrl != null)
60-
WebView.Source = new Uri(Configuration.CustomAiProviderUrl);
61-
break;
62-
case Copilot:
63-
default:
64-
Logging.Log($"Failed to load AiProvider! AiProvider Value '{Configuration.AiProvider}' in invalid!");
65-
throw new ArgumentOutOfRangeException();
49+
Logging.Log($"Failed to load AiProvider! AiProvider Value '{Configuration.AiProvider}' in invalid!");
50+
throw new ArgumentOutOfRangeException();
6651
}
6752
}
6853
catch (Exception ex)
@@ -73,8 +58,12 @@ private async Task InitializeWebViewAsync()
7358

7459
private void CloseButton_OnClick(object sender, RoutedEventArgs e)
7560
{
76-
Configuration.ShellManager.AppBarManager.SignalGracefulShutdown();
77-
Configuration.ShellManager.Dispose();
61+
if (Configuration.ShellManager != null)
62+
{
63+
Configuration.ShellManager.AppBarManager.SignalGracefulShutdown();
64+
Configuration.ShellManager.Dispose();
65+
}
66+
7867
Environment.Exit(0);
7968
}
8069

@@ -84,13 +73,13 @@ private void DockButton_OnClick(object sender, RoutedEventArgs e)
8473
{
8574
DockButton.Icon = new SymbolIcon(SymbolRegular.Pin28);
8675
RegistryConfig.SetKey("CopilotDockState", "Detached", userSetting: true);
87-
this.AppBarMode = AppBarMode.None;
76+
AppBarMode = AppBarMode.None;
8877
}
8978
else
9079
{
9180
DockButton.Icon = new SymbolIcon(SymbolRegular.PinOff28);
9281
RegistryConfig.SetKey("CopilotDockState", "Docked", userSetting: true);
93-
this.AppBarMode = AppBarMode.Normal;
82+
AppBarMode = AppBarMode.Normal;
9483
}
9584
Configuration.AppBarIsAttached = !Configuration.AppBarIsAttached;
9685
}

0 commit comments

Comments
 (0)