Skip to content

Commit

Permalink
增加maui项目,测试AutoUpdate的跨平台可用性
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneConan committed Mar 13, 2022
1 parent f82376c commit 8678987
Show file tree
Hide file tree
Showing 20 changed files with 546 additions and 374 deletions.
33 changes: 13 additions & 20 deletions src/AutoUpdate.MauiApp-Sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
using Application = Microsoft.Maui.Controls.Application;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace AutoUpdate.MauiApp_Sample
namespace AutoUpdate.MauiApp_Sample;

public partial class App : Application
{
public partial class App : Application
{
public App()
{
InitializeComponent();
}
public App()
{
InitializeComponent();

protected override Window CreateWindow(IActivationState activationState)
{
string args = @"eyJDbGllbnRUeXBlIjoxLCJBcHBOYW1lIjoiQXV0b1VwZGF0ZS5NYXVpQXBwLVNhbXBsZSIsIk1haW5BcHBOYW1lIjpudWxsLCJJbnN0YWxsUGF0aCI6IkQ6XFx1cGRhdGVfdGVzdCIsIkNsaWVudFZlcnNpb24iOiIxLjEuMSIsIkxhc3RWZXJzaW9uIjoiMS4xLjUiLCJVcGRhdGVMb2dVcmwiOiJodHRwczovL3d3dy5iYWlkdS5jb20vIiwiSXNVcGRhdGUiOmZhbHNlLCJVcGRhdGVVcmwiOiJodHRwOi8vMTI3LjAuMC4xOjUwMDEvdmVyc2lvbnMvMS8xLjEuMSIsIlZhbGlkYXRlVXJsIjpudWxsLCJNYWluVXBkYXRlVXJsIjpudWxsLCJNYWluVmFsaWRhdGVVcmwiOm51bGwsIlVwZGF0ZVZlcnNpb25zIjpbeyJQdWJUaW1lIjoxNjI2NzExNzYwLCJOYW1lIjpudWxsLCJNRDUiOiJmNjk4ZjkwMzJjMGQ1NDAxYmFjZDNiMGY1MzA5OTYxOCIsIlZlcnNpb24iOiIxLjEuMyIsIlVybCI6bnVsbCwiSXNVblppcCI6ZmFsc2V9LHsiUHViVGltZSI6MTYyNjcxMTgyMCwiTmFtZSI6bnVsbCwiTUQ1IjoiNmExMDQ2YTY2Y2VkZjUwOWJmYjJhNzcxYjJhN2E2NGUiLCJWZXJzaW9uIjoiMS4xLjQiLCJVcmwiOm51bGwsIklzVW5aaXAiOmZhbHNlfSx7IlB1YlRpbWUiOjE2MjY3MTE4ODAsIk5hbWUiOm51bGwsIk1ENSI6Ijc2ODljNDcyY2U3M2E0YjhmMWI3Yzc5MTczMTMzN2UxIiwiVmVyc2lvbiI6IjEuMS41IiwiVXJsIjpudWxsLCJJc1VuWmlwIjpmYWxzZX1dfQ==";
MainPage = new MainPage();

#if WINDOWS
//var args = activationState.LaunchActivatedEventArgs.Arguments;
MainPage = new MainPage(args);
#endif
return base.CreateWindow(activationState);
}
}
}
52 changes: 43 additions & 9 deletions src/AutoUpdate.MauiApp-Sample/AutoUpdate.MauiApp-Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
<RootNamespace>AutoUpdate.MauiApp_Sample</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>

<!-- Display name -->
<ApplicationTitle>AutoUpdate.MauiApp-Sample</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.AutoUpdate.MauiApp_Sample</ApplicationId>
<ApplicationId>com.companyname.autoupdate.mauiapp_sample</ApplicationId>

<!-- Versions -->
<ApplicationVersion>1</ApplicationVersion>
Expand Down Expand Up @@ -44,20 +45,53 @@

<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
<!-- Required - WinUI does not yet have buildTransitive for everything -->
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0-preview3" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.0.29-preview3" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.0.30" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GeneralUpdate.Common" Version="1.0.0" />
<PackageReference Include="GeneralUpdate.Core" Version="3.6.10" />
<PackageReference Include="GeneralUpdate.Zip" Version="1.0.0" />
<PackageReference Include="Refractored.MvvmHelpers" Version="1.6.2" />
<None Remove="Resources\bot.jpg" />
<None Remove="Resources\GU.jpg" />
</ItemGroup>

<ItemGroup>
<Content Include="Resources\bot.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\GU.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>


<ItemGroup>
<PackageReference Include="Refractored.MvvmHelpers" Version="1.6.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GeneralUpdate.Common\GeneralUpdate.Common.csproj" />
<ProjectReference Include="..\GeneralUpdate.Core\GeneralUpdate.Core.csproj" />
<ProjectReference Include="..\GeneralUpdate.Zip\GeneralUpdate.Zip.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
<OutputType>WinExe</OutputType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>

</Project>
105 changes: 71 additions & 34 deletions src/AutoUpdate.MauiApp-Sample/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,99 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AutoUpdate.MauiApp_Sample.MainPage"
Title="Update-APP"
BackgroundColor="{DynamicResource SecondaryColor}">

<ScrollView>
<Grid RowSpacing="25" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto"
Padding="{OnPlatform Android='30,60,30,30', Default='30'}">

<ProgressBar></ProgressBar>

<Button
Text="Test launch update."
FontAttributes="Bold"
Grid.Row="0"
SemanticProperties.Hint="Click"
HorizontalOptions="Center" Command="{Binding LaunchCommand}" />
<Grid RowSpacing="25" RowDefinitions="Auto,Auto,Auto,Auto,*"
Padding="{OnPlatform iOS='30,60,30,30', Default='30'}">
<!--<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>-->
<!--<ProgressBar Height="30" Width="350" VerticalAlignment="Bottom" Minimum="{Binding ProgressMin}" Maximum="{Binding ProgressMax}" Value="{Binding ProgressVal}"></ProgressBar>-->
<Grid Grid.Row="1" Margin="00,15,0,0">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="1" Text="Download statistics:" FontSize="14" Margin="5">
</Label>
<Label x:Name="Tips1" />

<Label Grid.Row="1" Text="Download progress:" Grid.Column="1" Margin="5" FontSize="14" >
</Label>
<Label x:Name="Tips2" />

<Label
Grid.Row="1"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
Text="{Binding Tips1}"
<Label Grid.Row="2" Grid.ColumnSpan="2" FontSize="14" Margin="5">
</Label>
<Label x:Name="Tips3" />

<Label Grid.Row="3" x:Name="Tips4" Grid.Column="1" Margin="5"/>
<Label Grid.Row="4" x:Name="Tips5" Grid.Column="1" Margin="5"/>
<Label Grid.Row="5" x:Name="Tips6" Grid.Column="1" Margin="5"/>
</Grid>


<!--<Image Grid.Row="4"
Source="bot.png"
WidthRequest="250"
HeightRequest="310"
HorizontalOptions="Center" />
<Image Grid.Row="4"
Source="GU.png"
WidthRequest="250"
HeightRequest="310"
HorizontalOptions="Center" />-->


<Label
Grid.Row="2"
Text="Hello, World!"
Grid.Row="0"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
Text="{Binding Tips2}"
HorizontalOptions="Center" />

<Label
Grid.Row="3"
Text="Welcome to AutoUpdate MauiApp-Sample"
Grid.Row="1"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
Text="{Binding Tips3}"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
FontSize="18"
HorizontalOptions="Center" />

<Label
Grid.Row="4"
Text="{Binding Tips4}"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
Text="Check for Update Current Count: 0"
Grid.Row="2"
FontSize="18"
FontAttributes="Bold"
x:Name="CounterLabel"
HorizontalOptions="Center" />

<Label
Grid.Row="5"
Text="{Binding Tips5}"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
<Button
Text="Click for Update!"
FontAttributes="Bold"
Grid.Row="3"
SemanticProperties.Hint=""
Clicked="OnCounterClicked"
HorizontalOptions="Center" />

<Label
Grid.Row="6"
Text="{Binding Tips6}"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
<Image Grid.Row="4"
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
WidthRequest="250"
HeightRequest="310"
HorizontalOptions="Center" />

</Grid>
</ScrollView>
</ContentPage>
110 changes: 101 additions & 9 deletions src/AutoUpdate.MauiApp-Sample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,111 @@
using AutoUpdate.MauiApp_Sample.ViewModels;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Essentials;
using GeneralUpdate.Common.Models;
using GeneralUpdate.Core;
using GeneralUpdate.Core.Strategys;
using GeneralUpdate.Core.Update;
using MvvmHelpers;
using Newtonsoft.Json;
using System;
using System.Text;
using System.Windows;

namespace AutoUpdate.MauiApp_Sample
namespace AutoUpdate.MauiApp_Sample;

public partial class MainPage : ContentPage
{
public partial class MainPage : ContentPage
int count = 0;

public MainPage()
{
InitializeComponent();
}

private void OnCounterClicked(object sender, EventArgs e)
{
count++;
CounterLabel.Text = $"Check for Update Current Count: {count}";

SemanticScreenReader.Announce(CounterLabel.Text);

var args = "eyJDbGllbnRUeXBlIjoxLCJBcHBOYW1lIjoiQXV0b1VwZGF0ZS5UZXN0IiwiTWFpbkFwcE5hbWUiOm51bGwsIkluc3RhbGxQYXRoIjoiRDpcXHVwZGF0ZV90ZXN0IiwiQ2xpZW50VmVyc2lvbiI6IjEuMS4xIiwiTGFzdFZlcnNpb24iOiIxLjEuNSIsIlVwZGF0ZUxvZ1VybCI6Imh0dHBzOi8vd3d3LmJhaWR1LmNvbS8iLCJJc1VwZGF0ZSI6ZmFsc2UsIlVwZGF0ZVVybCI6Imh0dHA6Ly8xMjcuMC4wLjE6NTAwMS92ZXJzaW9ucy8xLzEuMS4xIiwiVmFsaWRhdGVVcmwiOm51bGwsIk1haW5VcGRhdGVVcmwiOm51bGwsIk1haW5WYWxpZGF0ZVVybCI6bnVsbCwiVXBkYXRlVmVyc2lvbnMiOlt7IlB1YlRpbWUiOjE2MjY3MTE3NjAsIk5hbWUiOm51bGwsIk1ENSI6ImY2OThmOTAzMmMwZDU0MDFiYWNkM2IwZjUzMDk5NjE4IiwiVmVyc2lvbiI6IjEuMS4zIiwiVXJsIjpudWxsLCJJc1VuWmlwIjpmYWxzZX0seyJQdWJUaW1lIjoxNjI2NzExODIwLCJOYW1lIjpudWxsLCJNRDUiOiI2YTEwNDZhNjZjZWRmNTA5YmZiMmE3NzFiMmE3YTY0ZSIsIlZlcnNpb24iOiIxLjEuNCIsIlVybCI6bnVsbCwiSXNVblppcCI6ZmFsc2V9LHsiUHViVGltZSI6MTYyNjcxMTg4MCwiTmFtZSI6bnVsbCwiTUQ1IjoiNzY4OWM0NzJjZTczYTRiOGYxYjdjNzkxNzMxMzM3ZTEiLCJWZXJzaW9uIjoiMS4xLjUiLCJVcmwiOm51bGwsIklzVW5aaXAiOmZhbHNlfV19";
var bootStrap = new GeneralUpdateBootstrap();
bootStrap.MutiAllDownloadCompleted += OnMutiAllDownloadCompleted;
bootStrap.MutiDownloadCompleted += OnMutiDownloadCompleted;
bootStrap.MutiDownloadError += OnMutiDownloadError;
bootStrap.MutiDownloadProgressChanged += OnMutiDownloadProgressChanged;
bootStrap.MutiDownloadStatistics += OnMutiDownloadStatistics;
bootStrap.Exception += OnException;
bootStrap.Strategy<DefaultStrategy>().
Option(UpdateOption.DownloadTimeOut, 60).
Option(UpdateOption.Format, "zip").
RemoteAddressBase64(args);
bootStrap.LaunchAsync();
}


private void OnMutiDownloadStatistics(object sender, GeneralUpdate.Core.Update.MutiDownloadStatisticsEventArgs e)
{
Tips1.Text = $" { e.Speed } , { e.Remaining }";
}

private void OnMutiDownloadProgressChanged(object sender, GeneralUpdate.Core.Update.MutiDownloadProgressChangedEventArgs e)
{
switch (e.Type)
{
case ProgressType.Check:
if (!string.IsNullOrEmpty(e.Message))
{
Tips5.Text = e.Message;
}
break;
case ProgressType.Donwload:
//ProgressVal = e.BytesReceived;
//if (ProgressMax != e.TotalBytesToReceive)
//{
// ProgressMax = e.TotalBytesToReceive;
//}
Tips2.Text = $" { Math.Round(e.ProgressValue * 100, 2) }% , Receivedbyte:{ e.BytesReceived }M ,Totalbyte:{ e.TotalBytesToReceive }M";
break;
case ProgressType.Updatefile:
break;
case ProgressType.Done:
break;
case ProgressType.Fail:
break;
default:
break;
}
}

private void OnMutiDownloadCompleted(object sender, GeneralUpdate.Core.Update.MutiDownloadCompletedEventArgs e)
{
public MainPage() { InitializeComponent(); }
//Tips3 = $"{ e.Version.Name } download completed.";
}

public MainPage(string prameter)
private void OnMutiAllDownloadCompleted(object sender, GeneralUpdate.Core.Update.MutiAllDownloadCompletedEventArgs e)
{
if (e.IsAllDownloadCompleted)
{
Tips4.Text = "AllDownloadCompleted";
}
else
{
InitializeComponent();
BindingContext = new MainViewModel(prameter);
//wpf - DataContext
//foreach (var version in e.FailedVersions)
//{
// Debug.Write($"{ version.Item1.Name }");
//}
}
}

private void OnMutiDownloadError(object sender, GeneralUpdate.Core.Update.MutiDownloadErrorEventArgs e)
{

//Tips5 = $"{ e.Version.Name },{ e.Exception.Message }.";
}

private void OnException(object sender, GeneralUpdate.Core.Update.ExceptionEventArgs e)
{
Tips6.Text = $"{ e.Exception.Message }";
}
}

0 comments on commit 8678987

Please sign in to comment.