Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy committed Sep 24, 2024
1 parent c8cc806 commit b3d704c
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/Desktop/RodelAgent.UI.Models/Constants/SettingNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ public enum SettingNames
IsDrawHistoryColumnManualHide,
IsAudioHistoryColumnManualHide,
LastSelectedFeaturePage,
IsInternalPromptTest,
}
#pragma warning restore CS1591 // 缺少对公共可见类型或成员的 XML 注释
72 changes: 43 additions & 29 deletions src/Desktop/RodelAgent.UI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Rodel. All rights reserved.

using System.Web;
using H.NotifyIcon;
using Microsoft.UI.Dispatching;
using Microsoft.Windows.AppLifecycle;
Expand Down Expand Up @@ -126,47 +127,60 @@ private void InitializeTrayIcon()

private async Task LaunchWindowAsync(IActivatedEventArgs args = default)
{
var instance = AppInstance.FindOrRegisterForKey(Id);
if (args is IProtocolActivatedEventArgs protocolArgs
&& !string.IsNullOrEmpty(protocolArgs.Uri.Host))
{
// 处理协议启动.
if (protocolArgs.Uri.Host == "internal")
{
var query = protocolArgs.Uri.Query;
var queryItems = HttpUtility.ParseQueryString(query);
var feature = queryItems["feature"]?.ToLower() ?? string.Empty;
if (!string.IsNullOrEmpty(feature))
{
if (feature == "prompt-test")
{
SettingsToolkit.WriteLocalSetting(SettingNames.IsInternalPromptTest, true);
}
else if(feature == "clear")
{
SettingsToolkit.WriteLocalSetting(SettingNames.IsInternalPromptTest, false);
}
}
}
}
else

// If the current instance is not the previously registered instance
if (!instance.IsCurrent)
{
var instance = AppInstance.FindOrRegisterForKey(Id);
var activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs();

// If the current instance is not the previously registered instance
if (!instance.IsCurrent)
{
var activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
// Redirect to the existing instance
await instance.RedirectActivationToAsync(activatedArgs);

// Redirect to the existing instance
await instance.RedirectActivationToAsync(activatedArgs);
// Kill the current instance
Current.Exit();
return;
}

// Kill the current instance
Current.Exit();
return;
}
var shouldSkipStartup = SettingsToolkit.ReadLocalSetting(SettingNames.ShouldSkipStartup, false);
if (!shouldSkipStartup)
{
var window = new StartupWindow();
window.Activate();
}
else
{
_window = new MainWindow();
_window.Closed += OnMainWindowClosedAsync;

var shouldSkipStartup = SettingsToolkit.ReadLocalSetting(SettingNames.ShouldSkipStartup, false);
if (!shouldSkipStartup)
HandleCloseEvents = SettingsToolkit.ReadLocalSetting(SettingNames.HideWhenCloseWindow, true);
if (HandleCloseEvents)
{
var window = new StartupWindow();
window.Activate();
InitializeTrayIcon();
}
else
{
_window = new MainWindow();
_window.Closed += OnMainWindowClosedAsync;

HandleCloseEvents = SettingsToolkit.ReadLocalSetting(SettingNames.HideWhenCloseWindow, true);
if (HandleCloseEvents)
{
InitializeTrayIcon();
}

_window.Activate();
}
_window.Activate();
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Desktop/RodelAgent.UI/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
</uap:DefaultTile >
<uap:SplashScreen Image="Assets\Logo\SplashScreen.png" BackgroundColor="#FFFFFF"/>
</uap:VisualElements>
<Extensions>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="rodelagent" DesiredView="useLess" />
</uap:Extension>
</Extensions>
</Application>
</Applications>

Expand Down
13 changes: 13 additions & 0 deletions src/Desktop/RodelAgent.UI/Pages/Internal/PromptTestPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<base:LayoutPageBase
x:Class="RodelAgent.UI.Pages.Internal.PromptTestPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="using:Richasy.WinUI.Share.Base"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:RodelAgent.UI.Pages.Internal"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid />
</base:LayoutPageBase>
14 changes: 14 additions & 0 deletions src/Desktop/RodelAgent.UI/Pages/Internal/PromptTestPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Rodel. All rights reserved.

namespace RodelAgent.UI.Pages.Internal;

/// <summary>
/// 提示词测试.
/// </summary>
public sealed partial class PromptTestPage : LayoutPageBase
{
/// <summary>
/// Initializes a new instance of the <see cref="PromptTestPage"/> class.
/// </summary>
public PromptTestPage() => InitializeComponent();
}
3 changes: 3 additions & 0 deletions src/Desktop/RodelAgent.UI/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1187,4 +1187,7 @@ Choose a library folder and let's get started!</value>
<data name="ZhiPu" xml:space="preserve">
<value>Zhipu AI</value>
</data>
<data name="PromptTest" xml:space="preserve">
<value>Prompt test</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Desktop/RodelAgent.UI/Resources/zh-Hans-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1187,4 +1187,7 @@
<data name="ZhiPu" xml:space="preserve">
<value>智谱 AI</value>
</data>
<data name="PromptTest" xml:space="preserve">
<value>提示词测试</value>
</data>
</root>
6 changes: 5 additions & 1 deletion src/Desktop/RodelAgent.UI/RodelAgent.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
<None Remove="Pages\AudioServicePage.xaml" />
<None Remove="Pages\ChatServicePage.xaml" />
<None Remove="Pages\DrawServicePage.xaml" />
<None Remove="Pages\Internal\PromptTestPage.xaml" />
<None Remove="Pages\RAGPage.xaml" />
<None Remove="Pages\SettingsPage.xaml" />
<None Remove="Pages\Settings\AudioServicesPage.xaml" />
Expand Down Expand Up @@ -234,7 +235,7 @@
<PackageReference Include="NAudio" />
<PackageReference Include="NLog.Extensions.Logging" />
<PackageReference Include="Roman-Numerals" />
<PackageReference Include="Tiktoken"/>
<PackageReference Include="Tiktoken" />
<PackageReference Include="WinUIEx" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
Expand Down Expand Up @@ -641,6 +642,9 @@
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Page Update="Pages\Internal\PromptTestPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Pages\Startup\AudioConfigurationPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using RodelAgent.UI.Forms;
using RodelAgent.UI.Models.Constants;
using RodelAgent.UI.Pages;
using RodelAgent.UI.Pages.Internal;
using RodelAgent.UI.Toolkits;

namespace RodelAgent.UI.ViewModels.Components;
Expand Down Expand Up @@ -148,10 +149,17 @@ private IReadOnlyList<AppNavigationItemViewModel> GetMenuItems()

private IReadOnlyList<AppNavigationItemViewModel> GetFooterItems()
{
return new List<AppNavigationItemViewModel>
var list = new List<AppNavigationItemViewModel>
{
GetItem<SettingsPage>(StringNames.Settings, FluentIcons.Common.Symbol.Settings),
};

if (SettingsToolkit.ReadLocalSetting(SettingNames.IsInternalPromptTest, false))
{
list.Insert(0, GetItem<PromptTestPage>(StringNames.PromptTest, FluentIcons.Common.Symbol.TextBulletListSquareEdit));
}

return list;
}

private AppNavigationItemViewModel GetItem<TPage>(StringNames title, FluentIcons.Common.Symbol symbol, bool isSelected = false)
Expand Down
2 changes: 1 addition & 1 deletion src/Libs/WinUI.Share

0 comments on commit b3d704c

Please sign in to comment.