Skip to content

Commit

Permalink
Move some methods to AppLifecycleHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Feb 7, 2025
1 parent 5b57e0a commit 6b08e4b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 38 deletions.
33 changes: 0 additions & 33 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Win32;
using Microsoft.Windows.AppLifecycle;
using Windows.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
Expand All @@ -18,38 +17,6 @@ namespace Files.App
/// </summary>
public partial class App : Application
{
internal readonly static string AppInformationKey = @$"Software\Files Community\{Package.Current.Id.Name}\v1\AppInformation";

public static bool IsAppUpdated { get; }
public static bool IsFirstRun { get; }
public static long TotalLaunchCount { get; }

static App()
{
using var infoKey = Registry.CurrentUser.CreateSubKey(AppInformationKey);
var version = infoKey.GetValue("LastLaunchVersion");
var launchCount = infoKey.GetValue("TotalLaunchCount");
if (version is null)
{
IsAppUpdated = true;
IsFirstRun = true;
}
else
{
IsAppUpdated = version.ToString() != Package.Current.Id.Version.ToString();
}
if (launchCount is long l)
{
TotalLaunchCount = l + 1;
}
else
{
TotalLaunchCount = 1;
}
infoKey.SetValue("LastLaunchVersion", Package.Current.Id.Version.ToString()!);
infoKey.SetValue("TotalLaunchCount", TotalLaunchCount);
}

public static SystemTrayIcon? SystemTrayIcon { get; private set; }

public static TaskCompletionSource? SplashScreenLoadingTCS { get; private set; }
Expand Down
37 changes: 37 additions & 0 deletions src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Win32;
using Sentry;
using Sentry.Protocol;
using System.IO;
Expand All @@ -26,6 +27,42 @@ namespace Files.App.Helpers
/// </summary>
public static class AppLifecycleHelper
{
private readonly static string AppInformationKey = @$"Software\Files Community\{Package.Current.Id.Name}\v1\AppInformation";

/// <summary>
/// Gets the value that indicates whether the app is updated.
/// </summary>
public static bool IsAppUpdated { get; }

/// <summary>
/// Gets the value that indicates whether the app is running for the first time.
/// </summary>
public static bool IsFirstRun { get; }

/// <summary>
/// Gets the value that indicates the total launch count of the app.
/// </summary>
public static long TotalLaunchCount { get; }

static AppLifecycleHelper()
{
using var infoKey = Registry.CurrentUser.CreateSubKey(AppInformationKey);
var version = infoKey.GetValue("LastLaunchVersion");
var launchCount = infoKey.GetValue("TotalLaunchCount");
if (version is null)
{
IsAppUpdated = true;
IsFirstRun = true;
}
else
{
IsAppUpdated = version.ToString() != Package.Current.Id.Version.ToString();
}
TotalLaunchCount = launchCount is long l ? l + 1 : 1;
infoKey.SetValue("LastLaunchVersion", Package.Current.Id.Version.ToString()!);
infoKey.SetValue("TotalLaunchCount", TotalLaunchCount);
}

/// <summary>
/// Gets the value that provides application environment or branch name.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Services/App/AppUpdateNoneService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class DummyUpdateService : ObservableObject, IUpdateService

public bool IsUpdating => false;

public bool IsAppUpdated => App.IsAppUpdated;
public bool IsAppUpdated => AppLifecycleHelper.IsAppUpdated;

private bool _areReleaseNotesAvailable = false;
public bool AreReleaseNotesAvailable
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Services/App/AppUpdateSideloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public bool IsUpdating

public bool IsAppUpdated
{
get => App.IsAppUpdated;
get => AppLifecycleHelper.IsAppUpdated;
}

private bool _areReleaseNotesAvailable = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Services/App/AppUpdateStoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public bool IsUpdating

public bool IsAppUpdated
{
get => App.IsAppUpdated;
get => AppLifecycleHelper.IsAppUpdated;
}

private bool _areReleaseNotesAvailable = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Utils/Global/QuickAccessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task InitializeAsync()
{
PinnedItemsModified += Model.LoadAsync;

if (!Model.PinnedFolders.Contains(Constants.UserEnvironmentPaths.RecycleBinPath) && App.IsFirstRun)
if (!Model.PinnedFolders.Contains(Constants.UserEnvironmentPaths.RecycleBinPath) && AppLifecycleHelper.IsFirstRun)
await QuickAccessService.PinToSidebarAsync(Constants.UserEnvironmentPaths.RecycleBinPath);

await Model.LoadAsync();
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ AppLifecycleHelper.AppEnvironment is not AppEnvironment.Dev &&
if (Package.Current.Id.Name != "49306atecsolution.FilesUWP" || UserSettingsService.ApplicationSettingsService.ClickedToReviewApp)
return;

var totalLaunchCount = App.TotalLaunchCount;
var totalLaunchCount = AppLifecycleHelper.TotalLaunchCount;
if (totalLaunchCount is 50 or 200)
{
// Prompt user to review app in the Store
Expand Down

0 comments on commit 6b08e4b

Please sign in to comment.