Skip to content

Commit

Permalink
支持多会话管理
Browse files Browse the repository at this point in the history
支持对话记录懒加载
优化性能
增加开机自启动设置
  • Loading branch information
239573049 committed Jan 8, 2025
1 parent a054cb9 commit 44d15e9
Show file tree
Hide file tree
Showing 28 changed files with 510 additions and 137 deletions.
16 changes: 16 additions & 0 deletions src/ChatBox.Desktop.Macos/MacisAutoStartService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ChatBox.Service;

namespace ChatBox.Desktop;

public class MacisAutoStartService : IAutoStartService
{
public bool IsAutoStart()
{
return false;
}

public bool SetAutoStart(Boolean isAutoStart)
{
return false;
}
}
5 changes: 4 additions & 1 deletion src/ChatBox.Desktop.Macos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public static void Main(string[] args)
try
{
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
HostApplication.Builder();
HostApplication.Builder((services) =>
{
services.AddSingleton<IAutoStartService, MacisAutoStartService>();
});
NSApplication.Init();
NSApplication.SharedApplication.Delegate = new AppDelegate();
NSApplication.Main(args);
Expand Down
8 changes: 6 additions & 2 deletions src/ChatBox.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Avalonia;
using System;
using ChatBox.Desktop.Services;
using ChatBox.Service;
using Microsoft.Extensions.DependencyInjection;
#if DEBUG
using Nlnet.Avalonia.DevTools;
#endif

namespace ChatBox.Desktop;

sealed class Program
Expand All @@ -14,8 +16,10 @@ public static void Main(string[] args)
{
try
{

HostApplication.Builder();
HostApplication.Builder((services) =>
{
services.AddSingleton<IAutoStartService, WindowAutoStartService>();
});


CrossPlatformCustomProtocolHelper.RegisterCustomProtocol();
Expand Down
48 changes: 48 additions & 0 deletions src/ChatBox.Desktop/Services/WindowAutoStartService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Diagnostics;
using System.Reflection;
using ChatBox.Service;

namespace ChatBox.Desktop.Services;

public class WindowAutoStartService : IAutoStartService
{
public bool IsAutoStart()
{
// 判断当前window系统否存在开机启动
using var userRunKey =
Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);


string exePath = Process.GetCurrentProcess().MainModule.FileName;
string exeName = Assembly.GetExecutingAssembly().GetName().Name;


object runValue = userRunKey.GetValue(exeName);
if (runValue != null &&
string.Equals(runValue.ToString(), $"\"{exePath}\"", StringComparison.OrdinalIgnoreCase))
{
return true;
}

return false;
}

public bool SetAutoStart(bool isAutoStart)
{
string exePath = Process.GetCurrentProcess().MainModule.FileName;
string exeName = Assembly.GetExecutingAssembly().GetName().Name;
using var key =
Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (isAutoStart)
{
key.SetValue(exeName, $"\"{exePath}\"");
}
else
{
key.DeleteValue(exeName, false);
}

return true;
}
}
6 changes: 5 additions & 1 deletion src/ChatBox.IOS/Main.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using ChatBox.Service;
using Microsoft.Extensions.DependencyInjection;
using UIKit;

Expand All @@ -10,7 +11,10 @@ static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
HostApplication.Builder();
HostApplication.Builder((collection =>
{
collection.AddSingleton<IAutoStartService, NullAutoStartService>();
}));
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
2 changes: 1 addition & 1 deletion src/ChatBox/ChatBox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="Dapper.AOT" Version="1.0.31"/>
<PackageReference Include="FluentAvaloniaUI" Version="2.2.0"/>
<PackageReference Include="LucideAvalonia" Version="1.6.1" />
<PackageReference Include="MarkdownAIRender" Version="0.1.15" />
<PackageReference Include="MarkdownAIRender" Version="0.1.16" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.0"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0"/>
<PackageReference Include="Microsoft.SemanticKernel.Abstractions" Version="1.32.0"/>
Expand Down
6 changes: 5 additions & 1 deletion src/ChatBox/Controls/ActionBar/ActionBar.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
Height="35"
ColumnDefinitions="Auto,Auto,Auto,Auto,*">
<controls1:Model
Cursor="Hand"
Margin="0,4,5,0"
Grid.Column="0">
</controls1:Model>
<Button
Cursor="Hand"
Margin="5,0,5,0"
Grid.Column="1">
<TextBlock
Expand All @@ -34,6 +36,7 @@
</Button>
<Button
Click="NewSessionButton_Click"
Cursor="Hand"
IsEnabled="{Binding !IsGenerating}"
ToolTip.Tip="{markup:I18n {x:Static language:ChatInput.NewSessionTitle}}"
Margin="5,0,5,0"
Expand All @@ -46,7 +49,8 @@
Click="DeleteButton_Click"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Grid.Column="6">
Cursor="Hand"
Grid.Column="4">
<controls:SymbolIcon
Foreground="Red"
Symbol="Delete" Width="15">
Expand Down
3 changes: 3 additions & 0 deletions src/ChatBox/Controls/ChatInput.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Border Padding="5" Grid.Row="3">
<Grid ColumnDefinitions="Auto,*">
<Button
Cursor="Hand"
Click="OpenFile">
<controls:SymbolIcon
Symbol="OpenFile" Width="15">
Expand All @@ -69,6 +70,7 @@
Grid.Column="1">
<ComboBox
VerticalAlignment="Center"
Cursor="Hand"
IsEnabled="{Binding !IsGenerating}"
HorizontalAlignment="Right"
SelectedIndex="0"
Expand All @@ -89,6 +91,7 @@
</ComboBox>
<Button Grid.Column="1" Click="Submit"
VerticalAlignment="Center"
Cursor="Hand"
HorizontalAlignment="Right"
IsEnabled="{Binding !IsGenerating}"
Background="Transparent"
Expand Down
Loading

0 comments on commit 44d15e9

Please sign in to comment.