Skip to content

Commit

Permalink
feat: 完善 UI
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull committed Mar 21, 2024
1 parent 86bb365 commit 6f9bb1c
Show file tree
Hide file tree
Showing 18 changed files with 333 additions and 75 deletions.
18 changes: 10 additions & 8 deletions OpenGptChat.Avalonia/App.axaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:fluent-styling="using:FluentAvalonia.Styling"
x:Class="OpenGptChat.App"
xmlns:local="using:OpenGptChat"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>

<Application.Styles>
<FluentTheme />
</Application.Styles>
<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>

<Application.Styles>
<!--<FluentTheme/>-->
<fluent-styling:FluentAvaloniaTheme/>
</Application.Styles>
</Application>
Binary file added OpenGptChat.Avalonia/Assets/openai.ico
Binary file not shown.
8 changes: 7 additions & 1 deletion OpenGptChat.Avalonia/OpenGptChat.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@
<AvaloniaResource Include="Assets\**" />
</ItemGroup>

<ItemGroup>
<None Remove="Assets\openai.ico" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.10" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.10" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.10.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="FluentAvaloniaUI" Version="2.0.5" />
<PackageReference Include="LiteDB" Version="5.0.19" />
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
<PackageReference Include="OpenAI-DotNet" Version="7.7.6" />
</ItemGroup>


Expand Down
8 changes: 8 additions & 0 deletions OpenGptChat.Avalonia/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ internal sealed class Program
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.UsePlatformDetect()
//.With(new Win32PlatformOptions()
//{
// CompositionMode = new[]
// {
// Win32CompositionMode.WinUIComposition,
// }
//})
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
Expand Down
16 changes: 16 additions & 0 deletions OpenGptChat.Avalonia/Services/ChatService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenGptChat.Services
{
public class ChatService
{
public ChatService()
{

}
}
}
13 changes: 13 additions & 0 deletions OpenGptChat.Avalonia/Services/ConfigService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenGptChat.Services
{
public class ConfigService
{

}
}
27 changes: 26 additions & 1 deletion OpenGptChat.Avalonia/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using OpenGptChat.Models;

namespace OpenGptChat.ViewModels
Expand All @@ -9,6 +11,29 @@ public partial class MainPageViewModel : ViewModelBase
public ObservableCollection<ChatSession> Sessions { get; } = new();

[ObservableProperty]
private ChatSession? selectedSession;
private ChatSession? _selectedSession;

[ObservableProperty]
private string _textInput = string.Empty;

[RelayCommand]
public async Task Send()

Check warning on line 20 in OpenGptChat.Avalonia/ViewModels/MainPageViewModel.cs

View workflow job for this annotation

GitHub Actions / Build on Windows x64

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
#if DEBUG
if (SelectedSession is not ChatSession selectedSession)
return;
if (string.IsNullOrWhiteSpace(TextInput))
return;

selectedSession.Messages.Add(
new ChatMessage()
{
Title = "Me",
MessageText = TextInput,
});

TextInput = string.Empty;
#endif
}
}
}
5 changes: 4 additions & 1 deletion OpenGptChat.Avalonia/Views/Controls/ChatMessage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:md="https://github.com/whistyun/Markdown.Avalonia"
xmlns:fluent="using:FluentAvalonia.UI.Controls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="OpenGptChat.Views.Controls.ChatMessage"
x:Name="root">
<StackPanel Spacing="{CompiledBinding #root.Spacing}">
<TextBlock Text="{CompiledBinding #root.Title}"
HorizontalAlignment="{CompiledBinding #root.HorizontalAlignment}"/>
<Border BorderThickness="{CompiledBinding #root.MessageBorderThickness}"

<Border Background="{CompiledBinding #root.MessageBackground}"
BorderThickness="{CompiledBinding #root.MessageBorderThickness}"
BorderBrush="{CompiledBinding #root.MessageBorderBrush}"
CornerRadius="{CompiledBinding #root.MessageCornerRadius}"
Padding="{CompiledBinding #root.MessagePadding}">
Expand Down
18 changes: 18 additions & 0 deletions OpenGptChat.Avalonia/Views/Controls/ChatMessage.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public partial class ChatMessage : UserControl
public static readonly StyledProperty<string> MessageTextProperty =
AvaloniaProperty.Register<ChatMessage, string>(nameof(MessageText), defaultValue: "Content");

public static readonly StyledProperty<IBrush> MessageForegroundProperty =
AvaloniaProperty.Register<ChatMessage, IBrush>(nameof(MessageForeground));

public static readonly StyledProperty<IBrush> MessageBackgroundProperty =
AvaloniaProperty.Register<ChatMessage, IBrush>(nameof(MessageBackground));

public static readonly StyledProperty<Thickness> MessagePaddingProperty =
AvaloniaProperty.Register<ChatMessage, Thickness>(nameof(MessagePadding), defaultValue: new Thickness(5, 0));

Expand Down Expand Up @@ -42,6 +48,18 @@ public string MessageText
set => SetValue(MessageTextProperty, value);
}

public IBrush MessageForeground
{
get => GetValue(MessageForegroundProperty);
set => SetValue(MessageForegroundProperty, value);
}

public IBrush MessageBackground
{
get => GetValue(MessageBackgroundProperty);
set => SetValue(MessageBackgroundProperty, value);
}

public Thickness MessagePadding
{
get => GetValue(MessagePaddingProperty);
Expand Down
10 changes: 6 additions & 4 deletions OpenGptChat.Avalonia/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="using:OpenGptChat.Views.Pages"
mc:Ignorable="d" d:DesignWidth="850" d:DesignHeight="550"
Width="850" Height="550"
mc:Ignorable="d" d:DesignWidth="850" d:DesignHeight="560"
Width="850" Height="560"
x:Class="OpenGptChat.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="OpenGptChat.Avalonia">
Background="Transparent"
TransparencyLevelHint="Mica"
Icon="/Assets/openai.ico"
Title="OpenGptChat">

<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
Expand Down
Loading

0 comments on commit 6f9bb1c

Please sign in to comment.