Skip to content

Commit

Permalink
Add version and license info
Browse files Browse the repository at this point in the history
  • Loading branch information
sabihoshi committed Apr 7, 2021
1 parent a424348 commit 3914ea7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 9 deletions.
16 changes: 16 additions & 0 deletions GenshinLyreMidiPlayer/Models/GitVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Text.Json.Serialization;

namespace GenshinLyreMidiPlayer.Models
{
public class GitVersion
{
public bool Draft { get; set; }

public bool Prerelease { get; set; }

[JsonPropertyName("tag_name")] public string TagName { get; set; }

public Version Version => new(TagName.Replace("v", string.Empty));
}
}
52 changes: 49 additions & 3 deletions GenshinLyreMidiPlayer/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,74 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Text.Json;
using System.Threading.Tasks;
using GenshinLyreMidiPlayer.Models;
using GenshinLyreMidiPlayer.Views;
using ModernWpf.Controls;
using Stylet;
using StyletIoC;

namespace GenshinLyreMidiPlayer.ViewModels
{
public class MainWindowViewModel : Conductor<IScreen>.StackNavigation
{
private readonly Stack<NavigationViewItem> _history = new();

public MainWindowViewModel(IContainer ioc, IEventAggregator events)
public MainWindowViewModel(IEventAggregator events)
{
SettingsView = new SettingsPageViewModel(events);
PlayerView = new LyrePlayerViewModel(events, SettingsView);

Task.Run(async () =>
{
var client = new HttpClient();
UpdateString += "(Checking for updates)";
IsCheckingUpdate = true;

try
{
var request = new HttpRequestMessage(HttpMethod.Get,
"https://api.github.com/repos/sabihoshi/GenshinLyreMidiPlayer/releases/latest");

var productInfo = new ProductInfoHeaderValue("GenshinLyreMidiPlayer", ProgramVersion?.ToString());

request.Headers.UserAgent.Add(productInfo);

var response = await client.SendAsync(request);
var version = JsonSerializer.Deserialize<GitVersion>(await response.Content.ReadAsStringAsync());
if (version.Version > ProgramVersion && !(version.Draft || version.Prerelease))
UpdateString = $"(Update available! {version.TagName})";
else
UpdateString = string.Empty;
}
catch (Exception)
{
// Ignored
}
finally
{
IsCheckingUpdate = false;
}
});
}

public bool IsCheckingUpdate { get; set; }

public LyrePlayerViewModel PlayerView { get; }

public SettingsPageViewModel SettingsView { get; }

public string Title { get; set; } = "Genshin Lyre MIDI Player";

public string UpdateString { get; set; }

public string VersionString { get; set; } = $"v{ProgramVersion?.ToString(3)}";

private static Version? ProgramVersion { get; } = Assembly.GetExecutingAssembly().GetName().Version;

protected override void OnViewLoaded()
{
// Work around because events do not conform to the signatures Stylet supports
Expand Down
13 changes: 9 additions & 4 deletions GenshinLyreMidiPlayer/Views/MainWindowView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@
ui:WindowHelper.UseModernWindowStyle="True"
ui:TitleBar.ExtendViewIntoTitleBar="True">
<Grid>
<Grid VerticalAlignment="Top" Canvas.ZIndex="1"
<ui:SimpleStackPanel
Orientation="Horizontal" VerticalAlignment="Top" Canvas.ZIndex="1"
Height="{Binding ElementName=NavView, Path=CompactPaneLength}">
<TextBlock
Margin="50,0,0,0"
VerticalAlignment="Center"

Text="{Binding Title}"
Style="{DynamicResource CaptionTextBlockStyle}" />
</Grid>
Style="{DynamicResource CaptionTextBlockStyle}">
<Run Text="{Binding Title}" />
<Run Text="{Binding VersionString}" />
<Run Text="{Binding UpdateString}" />
</TextBlock>
<ui:ProgressRing IsActive="{Binding IsCheckingUpdate}" />
</ui:SimpleStackPanel>

<ui:NavigationView
x:Name="NavView" AlwaysShowHeader="True"
Expand Down
18 changes: 16 additions & 2 deletions GenshinLyreMidiPlayer/Views/SettingsPageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
IsOn="{Binding MergeNotes}" />

<ui:NumberBox
Header="Tolerance (ms)" IsEnabled="{Binding MergeNotes}"
Header="Tolerance (ms)" IsEnabled="{Binding MergeNotes}"
Minimum="0" SpinButtonPlacementMode="Compact"
Value="{Binding MergeMilliseconds}" />
</ui:SimpleStackPanel>
Expand Down Expand Up @@ -68,10 +68,24 @@
</ui:RadioButtons>
</GroupBox>

<GroupBox Header="Transition Style">
<Expander Header="Transition style">
<ui:RadioButtons
ItemsSource="{Binding Transitions}"
SelectedItem="{Binding Transition}" />
</Expander>


<GroupBox Header="License">
<ui:SimpleStackPanel Margin="10">
<TextBlock>
Created by © 2021 sabihoshi under the
<Hyperlink
NavigateUri="https://github.com/sabihoshi/GenshinLyreMidiPlayer/blob/main/LICENSE.md">
MIT License
</Hyperlink>.
</TextBlock>
<TextBlock TextWrapping="Wrap">© All rights reserved by miHoYo Co., Ltd. This project is not affiliated nor endorsed by miHoYo. Genshin Impact™ and other properties belong to their respective owners.</TextBlock>
</ui:SimpleStackPanel>
</GroupBox>
</ui:SimpleStackPanel>
</ScrollViewer>
Expand Down

0 comments on commit 3914ea7

Please sign in to comment.