Skip to content

Commit

Permalink
Merge pull request #65 from Kurokitu/UpdateCheck
Browse files Browse the repository at this point in the history
UpdateLog更换为Markdown并封装了新的弹窗组件
  • Loading branch information
LiuYunPlayer authored Jul 20, 2024
2 parents dfaa609 + 92dddc6 commit 65fdfa0
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 7 deletions.
55 changes: 55 additions & 0 deletions TuneLab/GUI/UpdateDialog.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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"
mc:Ignorable="d" d:DesignWidth="432" d:DesignHeight="604"
x:Class="TuneLab.GUI.UpdateDialog"
Title="TuneLab"
Width="432"
Height="604"
ExtendClientAreaChromeHints="NoChrome"
ExtendClientAreaTitleBarHeightHint="40"
ExtendClientAreaToDecorationsHint="True">
<Window.Styles>
<Style Selector="TitleBar">
<Setter Property="Background" Value="DarkGray"/>
<Setter Property="Foreground" Value="White"/>
</Style>
<Style Selector="Window">
<Setter Property="CornerRadius" Value="12"/>
</Style>
</Window.Styles>

<DockPanel Margin="0">
<Grid DockPanel.Dock="Top" x:Name="TitleBar" Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<StackPanel Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Horizontal" IsHitTestVisible="False">
<Label x:Name="TitleLabel" Content="Update" FontWeight="Bold" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" />
</StackPanel>
</Grid>

<ContentControl x:Name="Content">
<Grid Margin="0" x:Name="ContentGrid">
<Grid.RowDefinitions>
<RowDefinition MinHeight="40" />
<RowDefinition MinHeight="452" />
<RowDefinition Height="56" />
</Grid.RowDefinitions>

<StackPanel Grid.Row="0" Orientation="Vertical" Margin="12,0" VerticalAlignment="Center" x:Name="MessageStackPanel">
<SelectableTextBlock x:Name="MessageTextBlock" Text="This is a modal window." Foreground="White" TextWrapping="Wrap" TextAlignment="Start" FontSize="14" Padding="0" Margin="0" />
</StackPanel>

<StackPanel Grid.Row="1" Orientation="Vertical" Margin="12,0" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="MarkDownStackPanel">
<md:MarkdownScrollViewer x:Name="MarkDownScrollViewer" />
</StackPanel>

<Grid Grid.Row="2" x:Name="ButtonsPanel" Margin="0, 0, 0, 16"/>
</Grid>
</ContentControl>
</DockPanel>
</Window>
78 changes: 78 additions & 0 deletions TuneLab/GUI/UpdateDialog.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using System;
using TuneLab.Utils;
using Button = TuneLab.GUI.Components.Button;
using Markdown.Avalonia;
using TuneLab.I18N;

namespace TuneLab.GUI;

internal partial class UpdateDialog : Window
{
public enum ButtonType
{
Primary,
Normal
}

private Grid titleBar;
private Label titleLabel;
private SelectableTextBlock messageTextBlock;
private MarkdownScrollViewer markDownScrollViewer;

public UpdateDialog()
{
InitializeComponent();
Focusable = true;
CanResize = false;
WindowState = WindowState.Normal;
WindowStartupLocation = WindowStartupLocation.CenterScreen;
Topmost = true;

this.DataContext = this;
this.Background = Style.BACK.ToBrush();
Content.Background = Style.INTERFACE.ToBrush();

titleBar = this.FindControl<Grid>("TitleBar") ?? throw new InvalidOperationException("TitleBar not found");
titleLabel = this.FindControl<Label>("TitleLabel") ?? throw new InvalidOperationException("TitleLabel not found");
messageTextBlock = this.FindControl<SelectableTextBlock>("MessageTextBlock") ?? throw new InvalidOperationException("MessageTextBlock not found");
markDownScrollViewer = this.FindControl<MarkdownScrollViewer>("MarkDownScrollViewer") ?? throw new InvalidOperationException("MarkDownScrollViewer not found");

titleLabel.Content = "Update Available".Tr(TC.Dialog);
}

public void SetMessage(string message)
{
messageTextBlock.Text = message;
}

public void SetMDMessage(string message)
{
markDownScrollViewer.Markdown = message;
}

public Button AddButton(string text, ButtonType type)
{
ButtonsPanel.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
var button = new Button() { MinWidth = 96, Height = 40 };

if (type == ButtonType.Primary)
button.AddContent(new() { Item = new BorderItem() { CornerRadius = 6 }, ColorSet = new() { Color = Style.BUTTON_PRIMARY, HoveredColor = Style.BUTTON_PRIMARY_HOVER } });

if (type == ButtonType.Normal)
button.AddContent(new() { Item = new BorderItem() { CornerRadius = 6 }, ColorSet = new() { Color = Style.BUTTON_NORMAL, HoveredColor = Style.BUTTON_NORMAL_HOVER } });

button.AddContent(new() { Item = new TextItem() { Text = text }, ColorSet = new() { Color = type == ButtonType.Primary ? Colors.White : Style.LIGHT_WHITE } });

button.Clicked += Close;
var buttonStack = new StackPanel() { Orientation = Avalonia.Layout.Orientation.Horizontal, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center, Children = { button }, Height = 40, Margin = new(0) };

Grid.SetColumn(buttonStack, ButtonsPanel.ColumnDefinitions.Count - 1);
ButtonsPanel.Children.Add(buttonStack);

return button;
}
}

1 change: 1 addition & 0 deletions TuneLab/TuneLab.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<PackageReference Include="BunLabs.NAudio.Flac" Version="2.0.1" />
<PackageReference Include="Flurl.Http" Version="4.0.2" />
<PackageReference Include="IkG2p" Version="1.0.2" />
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.6" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
13 changes: 6 additions & 7 deletions TuneLab/UI/MainWindow/Editor/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,13 @@ public async void InstallExtensions(IEnumerable<string> files)

private async void UpdateDialog(UpdateInfo mUpdateCheck, bool IsAutoCheck)
{
var dialog = new Dialog();
dialog.SetTitle("Update Available".Tr(TC.Dialog));
dialog.SetMessage("Version".Tr(TC.Dialog) + $": {mUpdateCheck.version}\n" + "Public Date".Tr(TC.Dialog) + $": {mUpdateCheck.publishedAt}\n\n{mUpdateCheck.description}");
dialog.SetTextAlignment(Avalonia.Media.TextAlignment.Left);
var dialog = new UpdateDialog();
dialog.SetMessage("Version".Tr(TC.Dialog) + $": {mUpdateCheck.version}\n" + "Public Date".Tr(TC.Dialog) + $": {mUpdateCheck.publishedAt}");
dialog.SetMDMessage(mUpdateCheck.description ?? "");
if (IsAutoCheck)
dialog.AddButton("Ignore".Tr(TC.Dialog), Dialog.ButtonType.Normal).Clicked += () => AppUpdateManager.SaveIgnoreVersion(mUpdateCheck.version);
dialog.AddButton("Later".Tr(TC.Dialog), Dialog.ButtonType.Normal);
dialog.AddButton("Download".Tr(TC.Dialog), Dialog.ButtonType.Primary).Clicked += () =>
dialog.AddButton("Ignore".Tr(TC.Dialog), GUI.UpdateDialog.ButtonType.Normal).Clicked += () => AppUpdateManager.SaveIgnoreVersion(mUpdateCheck.version);
dialog.AddButton("Later".Tr(TC.Dialog), GUI.UpdateDialog.ButtonType.Normal);
dialog.AddButton("Download".Tr(TC.Dialog), GUI.UpdateDialog.ButtonType.Primary).Clicked += () =>
{
ProcessHelper.OpenUrl(mUpdateCheck.url);
};
Expand Down

0 comments on commit 65fdfa0

Please sign in to comment.