From b77527658c29bcec2274f40dcc42c6e9651a7da1 Mon Sep 17 00:00:00 2001 From: Yaser Moradi Date: Fri, 23 Feb 2024 08:30:27 +0100 Subject: [PATCH] feat(templates): add check for updates to boilerplate maui #6915 (#6916) --- .../Resources/AppStrings.Designer.cs | 18 +++++++++ .../Resources/AppStrings.fr.resx | 6 +++ .../Resources/AppStrings.resx | 6 +++ .../Boilerplate.Client.Maui.csproj | 4 +- .../Boilerplate.Client.Maui/MainPage.xaml.cs | 38 +++++++++++++++++++ .../Boilerplate.Client.Maui/MauiProgram.cs | 2 + 6 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.Designer.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.Designer.cs index 5a6530e243..761fc9b846 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.Designer.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.Designer.cs @@ -763,6 +763,15 @@ public static string NewPassword { } } + /// + /// Looks up a localized string similar to New version is available. + /// + public static string NewVersionIsAvailable { + get { + return ResourceManager.GetString("NewVersionIsAvailable", resourceCulture); + } + } + /// /// Looks up a localized string similar to No. /// @@ -1312,6 +1321,15 @@ public static string UpdateConcurrencyException { } } + /// + /// Looks up a localized string similar to Would you like to update to the new version?. + /// + public static string UpdateToNewVersion { + get { + return ResourceManager.GetString("UpdateToNewVersion", resourceCulture); + } + } + /// /// Looks up a localized string similar to Upload a new profile image. /// diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.fr.resx b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.fr.resx index 048c3dc27c..d13cc1eb33 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.fr.resx +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.fr.resx @@ -564,4 +564,10 @@ Les produits comptent + + Une nouvelle version est disponible + + + Souhaitez-vous mettre à jour vers la nouvelle version? + \ No newline at end of file diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.resx b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.resx index 9f6b5000ce..9b8a670d7a 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.resx +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Shared/Resources/AppStrings.resx @@ -450,6 +450,12 @@ Please confirm your email by clicking on the link. Update + + + New version is available + + + Would you like to update to the new version? diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/Boilerplate.Client.Maui.csproj b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/Boilerplate.Client.Maui.csproj index 07493381be..ef566da72e 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/Boilerplate.Client.Maui.csproj +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/Boilerplate.Client.Maui.csproj @@ -104,6 +104,7 @@ + @@ -119,7 +120,6 @@ - + diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MainPage.xaml.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MainPage.xaml.cs index cb4241b7ce..ecaf727474 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MainPage.xaml.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MainPage.xaml.cs @@ -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, @@ -13,6 +16,7 @@ public MainPage(IExceptionHandler exceptionHandler, { this.exceptionHandler = exceptionHandler; this.deviceCoordinator = deviceCoordinator; + this.storageService = storageService; InitializeComponent(); @@ -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(); + } + } + } + } } diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MauiProgram.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MauiProgram.cs index 2daa302856..e7605edca9 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MauiProgram.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Maui/MauiProgram.cs @@ -1,5 +1,6 @@ //-:cnd:noEmit using Boilerplate.Client.Core; +using Maui.AppStores; using Microsoft.Maui.LifecycleEvents; namespace Boilerplate.Client.Maui; @@ -14,6 +15,7 @@ public static MauiApp CreateMauiApp() builder .UseMauiApp() + .UseAppStoreInfo() .Configuration.AddClientConfigurations(); builder.ConfigureServices();