Skip to content

Commit

Permalink
Partially Added in-app updater functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicPredator committed Feb 7, 2024
1 parent cd7431f commit 55291f1
Show file tree
Hide file tree
Showing 25 changed files with 412 additions and 71 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/ci-devel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.1
uses: microsoft/setup-msbuild@v2

# Add Community Toolkit Labs Repository for some Packages to get Installed
- name: Add CommunityToolkit Labs Package Repository
Expand Down Expand Up @@ -82,11 +82,3 @@ jobs:
retention-days: 10
path: ${{ github.workspace }}\\src\AniMoe.App\Packages\AniMoe.App.msix

- name: Send discord announcement
uses: snorrwe/[email protected]
with:
discord_message: new
discord_token: ${{ secrets.DISCORD_BOT_TOKEN }}
post_file: changelog.md
discord_channel: '1122748057696604163'

8 changes: 8 additions & 0 deletions .github/workflows/ci-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ jobs:
tag_name: ${{ env.APP_VERSION }}
generate_release_notes: true

# Sends a message to the #updates channel on AniMoe's Cafe discord server.
- name: Send discord announcement
uses: snorrwe/[email protected]
with:
discord_message: new
discord_token: ${{ secrets.DISCORD_BOT_TOKEN }}
post_file: changelog.md
discord_channel: '1170356953785061517'
13 changes: 0 additions & 13 deletions .idea/.idea.AniMoe/.idea/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/.idea.AniMoe/.idea/discord.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/.idea.AniMoe/.idea/indexLayout.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/.idea.AniMoe/.idea/vcs.xml

This file was deleted.

6 changes: 3 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## AniMoe Version 0.0.2

### What's new?
- Added a new installer where you can install AniMoe without using any scripts.
- Testing out the automatic updator fucntion.
- Some pakcages bump
- Added a new installer (animoe_setup.exe) where you can install AniMoe without using any scripts.
- Testing out the automatic updator function.
- Some packages bumped.

[GitHub](https://github.com/CosmicPredator/AniMoe) | [Download](https://github.com/CosmicPredator/AniMoe/releases/latest/)
9 changes: 9 additions & 0 deletions src/AniMoe.App/AniMoe.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<None Remove="Controls\MediaSideViewControl.xaml" />
<None Remove="Controls\MediaViewShimmer.xaml" />
<None Remove="Controls\ReviewListView.xaml" />
<None Remove="Controls\SettingsViewControls\UpdateDialog.xaml" />
<None Remove="Controls\StaffListView.xaml" />
<None Remove="Controls\StatsPage.xaml" />
<None Remove="Controls\UserViewControls\UserOverviewPage.xaml" />
Expand All @@ -68,6 +69,7 @@
<None Remove="Views\MediaView.xaml" />
<None Remove="Views\ReviewView.xaml" />
<None Remove="Views\RootWindow.xaml" />
<None Remove="Views\SettingsPages\AboutPage.xaml" />
<None Remove="Views\SettingsView.xaml" />
<None Remove="Views\StaffView.xaml" />
<None Remove="Views\UserView.xaml" />
Expand All @@ -93,6 +95,7 @@
<PackageReference Include="CommunityToolkit.WinUI.UI.Animations" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Behaviors" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Markdown" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Media" Version="7.1.2" />
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.0.118" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.WinUI" Version="2.0.0-rc1" />
Expand Down Expand Up @@ -201,6 +204,12 @@
<None Update="Assets\profile.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Page Update="Controls\SettingsViewControls\UpdateDialog.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Views\SettingsPages\AboutPage.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Views\SettingsView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
6 changes: 6 additions & 0 deletions src/AniMoe.App/AniMoe.App.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<None Update="App.xaml">
<SubType>Designer</SubType>
</None>
<Page Update="Controls\SettingsViewControls\UpdateDialog.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Views\SettingsPages\AboutPage.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Views\SettingsView.xaml">
<SubType>Designer</SubType>
</Page>
Expand Down
3 changes: 2 additions & 1 deletion src/AniMoe.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public static IServiceProvider ConfigureServices()
.AddSingleton<IMdToHtmlParser, MdToHtmlParser>()
.AddSingleton<AnimeListViewModel>()
.AddSingleton<MangaListViewModel>()
.AddSingleton<ExploreViewModel>();
.AddSingleton<ExploreViewModel>()
.AddSingleton<UpdateHandler>();

services.AddHttpClient<IRequestHandler, RequestHandler>();
Log.Information("All Dependencies Hosted");
Expand Down
82 changes: 82 additions & 0 deletions src/AniMoe.App/Controls/SettingsViewControls/UpdateDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentDialog
x:Class="AniMoe.App.Controls.SettingsViewControls.UpdateDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:AniMoe.App.Controls.SettingsViewControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls"
CloseButtonText="Not now"
CornerRadius="10"
Loaded="ContentDialog_Loaded"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
PrimaryButtonStyle="{ThemeResource AccentButtonStyle}"
PrimaryButtonText="Update &amp; Restart"
mc:Ignorable="d">

<ContentDialog.CloseButtonStyle>
<Style TargetType="Button">
<Setter Property="CornerRadius" Value="4" />
</Style>
</ContentDialog.CloseButtonStyle>

<Grid
Width="400"
Margin="0"
RowSpacing="5">

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBlock
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
Style="{ThemeResource TitleTextBlockStyle}"
Text="Update Available!" />

<StackPanel
Grid.Row="1"
Orientation="Vertical"
Spacing="5">
<TextBlock VerticalAlignment="Center">
<Run FontWeight="SemiBold" Text="Version:" />
<Run Text="{x:Bind Model.TagName, Mode=OneWay}" />
</TextBlock>

<TextBlock VerticalAlignment="Center">
<Run FontWeight="SemiBold" Text="Size:" />
<Run x:Name="SizeTextBlock" />
</TextBlock>

<TextBlock
Margin="0,10,0,0"
FontSize="17"
FontWeight="Medium"
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
Text="Changelog:" />

<toolkit:MarkdownTextBlock
x:Name="MdTextBlock"
Background="Transparent"
LinkClicked="MdTextBlock_LinkClicked"
Text="{x:Bind Model.Body}" />

<StackPanel
x:Name="LoaderStackPanel"
Margin="0,10,0,0"
Orientation="Horizontal"
Spacing="10"
Visibility="Collapsed">
<ProgressRing IsIndeterminate="True" />
<TextBlock
VerticalAlignment="Center"
FontSize="16"
FontWeight="SemiBold"
Text="Updating..." />
</StackPanel>
</StackPanel>

</Grid>
</ContentDialog>
56 changes: 56 additions & 0 deletions src/AniMoe.App/Controls/SettingsViewControls/UpdateDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using AniMoe.Updater;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

namespace AniMoe.App.Controls.SettingsViewControls
{
public sealed partial class UpdateDialog : ContentDialog
{
public GithubModel Model;
public UpdateDialog(GithubModel model)
{
this.InitializeComponent();
Model = model;
DataContext = this;
}

private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
args.Cancel = true;
foreach(var i in Model.Assets)
{
if (i.Name.Contains(".msix"))
{
Debug.WriteLine(i.Name);
Debug.WriteLine(i.Size);
Debug.WriteLine(i.BrowserDownloadUrl);
}
}
}

private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
{
double assetSize = Math.Round(
(Model.Assets.First(x => x.Name.Contains(".msix")).Size * 0.000001), 2);
SizeTextBlock.Text = $"{assetSize}MB";
}

private async void MdTextBlock_LinkClicked(object sender, CommunityToolkit.WinUI.UI.Controls.LinkClickedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri(e.Link));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public UserModel Model
get { return (UserModel)GetValue(ModelProperty); }
set { SetValue(ModelProperty, value); }
}
private bool _loadGenreTable = false;
//private bool _loadGenreTable = false;
public static readonly DependencyProperty ModelProperty =
DependencyProperty.Register("Model", typeof(UserModel), typeof(UserOverviewPage), new PropertyMetadata(null));

Expand All @@ -49,7 +49,7 @@ private void ModelPropertyChanged(DependencyObject sender, DependencyProperty dp
{
if (Model.Data.User.Statistics.Anime.Genres.Any())
{
_loadGenreTable = true;
//_loadGenreTable = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/AniMoe.App/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity
Name="AniMoe"
Publisher="CN=Cosmic Predator, O=Cosmic Predator, C=CA"
Version="0.0.1.102" />
Version="0.0.2.0" />

<Properties>
<DisplayName>AniMoe</DisplayName>
Expand Down
71 changes: 71 additions & 0 deletions src/AniMoe.App/ViewModels/UpdateViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using AniMoe.App.Controls.SettingsViewControls;
using AniMoe.Updater;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel;

namespace AniMoe.App.ViewModels
{
public partial class UpdateViewModel : ObservableObject
{

private UpdateHandler handler = App.Current.Services.GetRequiredService<UpdateHandler>();
private XamlRoot _currentXamlRoot;
private DispatcherQueue _dispatcherQueue;

[ObservableProperty]
private string _currentAppVersion;

[ObservableProperty]
private GithubModel _model;

[ObservableProperty]
private string _buttonStatus = "Check for Update";

[ObservableProperty]
private bool _loaderState;

[ObservableProperty]
private bool _updateButtonEnable = true;

[RelayCommand]
private async Task runRequest()
{
LoaderState = true;
Model = await handler.CheckLatestRelease();
LoaderState = false;
if (Model.TagName.CompareTo(CurrentAppVersion) < 0)
{
_dispatcherQueue.TryEnqueue(async () =>
{
UpdateDialog dialog = new(Model);
dialog.XamlRoot = null;
dialog.XamlRoot = _currentXamlRoot;
await dialog.ShowAsync();
});
} else
{
ButtonStatus = "No Updates Available";
UpdateButtonEnable = false;
}
}

public UpdateViewModel(XamlRoot xamlRoot, DispatcherQueue dispatcherQueue)
{
CurrentAppVersion = string.Format("Version: {0}.{1}.{2}",
Package.Current.Id.Version.Major,
Package.Current.Id.Version.Minor,
Package.Current.Id.Version.Build);
_currentXamlRoot = xamlRoot;
_dispatcherQueue = dispatcherQueue;
}
}
}
2 changes: 1 addition & 1 deletion src/AniMoe.App/Views/CharacterView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CharacterView()
this.InitializeComponent();
}

private async void MasterScrollViewer_Loaded(object sender, RoutedEventArgs e)
private void MasterScrollViewer_Loaded(object sender, RoutedEventArgs e)
{
SegmentedBox.SelectionChanged += SegmentedBox_SelectionChanged;
SegmentedBox.SelectedIndex = 0;
Expand Down
Loading

0 comments on commit 55291f1

Please sign in to comment.