Skip to content

Commit

Permalink
feat(templates): add check for updates to boilerplate maui #6915 (#6916)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi authored Feb 23, 2024
1 parent 2dc6e48 commit b775276
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,10 @@
<data name="ProductsCount" xml:space="preserve">
<value>Les produits comptent</value>
</data>
<data name="NewVersionIsAvailable" xml:space="preserve">
<value>Une nouvelle version est disponible</value>
</data>
<data name="UpdateToNewVersion" xml:space="preserve">
<value>Souhaitez-vous mettre à jour vers la nouvelle version?</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ Please confirm your email by clicking on the link.</value>
</data>
<data name="Update" xml:space="preserve">
<value>Update</value>
</data>
<data name="NewVersionIsAvailable" xml:space="preserve">
<value>New version is available</value>
</data>
<data name="UpdateToNewVersion" xml:space="preserve">
<value>Would you like to update to the new version?</value>
</data>
<!--#if (sample == "Todo") -->
<data name="TodoAddPlaceholder" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.7" />
<PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.7" />
<PackageReference Include="Oscore.Maui.AppStoreInfo" Version="1.0.3" />
<PackageReference Include="Plugin.StoreReview" Version="6.0.0" />
</ItemGroup>

Expand All @@ -119,7 +120,6 @@
</PropertyGroup>

<Target Name="BeforeBuildTasks" BeforeTargets="BeforeBuild">
<Error Text="Enable long paths in Windows. https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell#enable-long-paths-in-windows-10-version-1607-and-later"
Condition=" $([MSBuild]::IsOSPlatform('windows')) AND $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem', 'LongPathsEnabled', null, RegistryView.Registry64)) != '1' " />
<Error Text="Enable long paths in Windows. https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell#enable-long-paths-in-windows-10-version-1607-and-later" Condition=" $([MSBuild]::IsOSPlatform('windows')) AND $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem', 'LongPathsEnabled', null, RegistryView.Registry64)) != '1' " />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//-:cnd:noEmit
using Maui.AppStores;

namespace Boilerplate.Client.Maui;

public partial class MainPage
{
private readonly IExceptionHandler exceptionHandler;
private readonly IBitDeviceCoordinator deviceCoordinator;
private readonly IStorageService storageService;

public MainPage(IExceptionHandler exceptionHandler,
IBitDeviceCoordinator deviceCoordinator,
Expand All @@ -13,6 +16,7 @@ public MainPage(IExceptionHandler exceptionHandler,
{
this.exceptionHandler = exceptionHandler;
this.deviceCoordinator = deviceCoordinator;
this.storageService = storageService;

InitializeComponent();

Expand Down Expand Up @@ -119,4 +123,38 @@ private void SetupStatusBar()
}
});
}

protected override async void OnAppearing()
{
try
{
base.OnAppearing();

await CheckForUpdates();
}
catch (Exception exp)
{
exceptionHandler.Handle(exp);
}
}

private async Task CheckForUpdates()
{
await Task.Delay(TimeSpan.FromSeconds(3)); // No rush to check for updates.

if (await AppStoreInfo.Current.IsUsingLatestVersionAsync() is false)
{
if (await storageService.GetItem($"{AppInfo.Version}_UpdateFromVersionIsRequested") is not "true")
{
await storageService.SetItem($"{AppInfo.Version}_UpdateFromVersionIsRequested", "true");

// It's an opportune moment to request an update. (:
// https://github.com/oscoreio/Maui.AppStoreInfo
if (await DisplayAlert(AppStrings.NewVersionIsAvailable, AppStrings.UpdateToNewVersion, AppStrings.Yes, AppStrings.No) is true)
{
await AppStoreInfo.Current.OpenApplicationInStoreAsync();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//-:cnd:noEmit
using Boilerplate.Client.Core;
using Maui.AppStores;
using Microsoft.Maui.LifecycleEvents;

namespace Boilerplate.Client.Maui;
Expand All @@ -14,6 +15,7 @@ public static MauiApp CreateMauiApp()

builder
.UseMauiApp<App>()
.UseAppStoreInfo()
.Configuration.AddClientConfigurations();

builder.ConfigureServices();
Expand Down

0 comments on commit b775276

Please sign in to comment.