Skip to content

Commit 6b08e4b

Browse files
committed
Move some methods to AppLifecycleHelper
1 parent 5b57e0a commit 6b08e4b

File tree

7 files changed

+42
-38
lines changed

7 files changed

+42
-38
lines changed

src/Files.App/App.xaml.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Microsoft.Extensions.Logging;
66
using Microsoft.UI.Xaml;
77
using Microsoft.UI.Xaml.Controls;
8-
using Microsoft.Win32;
98
using Microsoft.Windows.AppLifecycle;
109
using Windows.ApplicationModel;
1110
using Windows.ApplicationModel.DataTransfer;
@@ -18,38 +17,6 @@ namespace Files.App
1817
/// </summary>
1918
public partial class App : Application
2019
{
21-
internal readonly static string AppInformationKey = @$"Software\Files Community\{Package.Current.Id.Name}\v1\AppInformation";
22-
23-
public static bool IsAppUpdated { get; }
24-
public static bool IsFirstRun { get; }
25-
public static long TotalLaunchCount { get; }
26-
27-
static App()
28-
{
29-
using var infoKey = Registry.CurrentUser.CreateSubKey(AppInformationKey);
30-
var version = infoKey.GetValue("LastLaunchVersion");
31-
var launchCount = infoKey.GetValue("TotalLaunchCount");
32-
if (version is null)
33-
{
34-
IsAppUpdated = true;
35-
IsFirstRun = true;
36-
}
37-
else
38-
{
39-
IsAppUpdated = version.ToString() != Package.Current.Id.Version.ToString();
40-
}
41-
if (launchCount is long l)
42-
{
43-
TotalLaunchCount = l + 1;
44-
}
45-
else
46-
{
47-
TotalLaunchCount = 1;
48-
}
49-
infoKey.SetValue("LastLaunchVersion", Package.Current.Id.Version.ToString()!);
50-
infoKey.SetValue("TotalLaunchCount", TotalLaunchCount);
51-
}
52-
5320
public static SystemTrayIcon? SystemTrayIcon { get; private set; }
5421

5522
public static TaskCompletionSource? SplashScreenLoadingTCS { get; private set; }

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Hosting;
1111
using Microsoft.Extensions.Logging;
12+
using Microsoft.Win32;
1213
using Sentry;
1314
using Sentry.Protocol;
1415
using System.IO;
@@ -26,6 +27,42 @@ namespace Files.App.Helpers
2627
/// </summary>
2728
public static class AppLifecycleHelper
2829
{
30+
private readonly static string AppInformationKey = @$"Software\Files Community\{Package.Current.Id.Name}\v1\AppInformation";
31+
32+
/// <summary>
33+
/// Gets the value that indicates whether the app is updated.
34+
/// </summary>
35+
public static bool IsAppUpdated { get; }
36+
37+
/// <summary>
38+
/// Gets the value that indicates whether the app is running for the first time.
39+
/// </summary>
40+
public static bool IsFirstRun { get; }
41+
42+
/// <summary>
43+
/// Gets the value that indicates the total launch count of the app.
44+
/// </summary>
45+
public static long TotalLaunchCount { get; }
46+
47+
static AppLifecycleHelper()
48+
{
49+
using var infoKey = Registry.CurrentUser.CreateSubKey(AppInformationKey);
50+
var version = infoKey.GetValue("LastLaunchVersion");
51+
var launchCount = infoKey.GetValue("TotalLaunchCount");
52+
if (version is null)
53+
{
54+
IsAppUpdated = true;
55+
IsFirstRun = true;
56+
}
57+
else
58+
{
59+
IsAppUpdated = version.ToString() != Package.Current.Id.Version.ToString();
60+
}
61+
TotalLaunchCount = launchCount is long l ? l + 1 : 1;
62+
infoKey.SetValue("LastLaunchVersion", Package.Current.Id.Version.ToString()!);
63+
infoKey.SetValue("TotalLaunchCount", TotalLaunchCount);
64+
}
65+
2966
/// <summary>
3067
/// Gets the value that provides application environment or branch name.
3168
/// </summary>

src/Files.App/Services/App/AppUpdateNoneService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal sealed class DummyUpdateService : ObservableObject, IUpdateService
88

99
public bool IsUpdating => false;
1010

11-
public bool IsAppUpdated => App.IsAppUpdated;
11+
public bool IsAppUpdated => AppLifecycleHelper.IsAppUpdated;
1212

1313
private bool _areReleaseNotesAvailable = false;
1414
public bool AreReleaseNotesAvailable

src/Files.App/Services/App/AppUpdateSideloadService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public bool IsUpdating
5555

5656
public bool IsAppUpdated
5757
{
58-
get => App.IsAppUpdated;
58+
get => AppLifecycleHelper.IsAppUpdated;
5959
}
6060

6161
private bool _areReleaseNotesAvailable = false;

src/Files.App/Services/App/AppUpdateStoreService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public bool IsUpdating
3636

3737
public bool IsAppUpdated
3838
{
39-
get => App.IsAppUpdated;
39+
get => AppLifecycleHelper.IsAppUpdated;
4040
}
4141

4242
private bool _areReleaseNotesAvailable = false;

src/Files.App/Utils/Global/QuickAccessManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task InitializeAsync()
4343
{
4444
PinnedItemsModified += Model.LoadAsync;
4545

46-
if (!Model.PinnedFolders.Contains(Constants.UserEnvironmentPaths.RecycleBinPath) && App.IsFirstRun)
46+
if (!Model.PinnedFolders.Contains(Constants.UserEnvironmentPaths.RecycleBinPath) && AppLifecycleHelper.IsFirstRun)
4747
await QuickAccessService.PinToSidebarAsync(Constants.UserEnvironmentPaths.RecycleBinPath);
4848

4949
await Model.LoadAsync();

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ AppLifecycleHelper.AppEnvironment is not AppEnvironment.Dev &&
312312
if (Package.Current.Id.Name != "49306atecsolution.FilesUWP" || UserSettingsService.ApplicationSettingsService.ClickedToReviewApp)
313313
return;
314314

315-
var totalLaunchCount = App.TotalLaunchCount;
315+
var totalLaunchCount = AppLifecycleHelper.TotalLaunchCount;
316316
if (totalLaunchCount is 50 or 200)
317317
{
318318
// Prompt user to review app in the Store

0 commit comments

Comments
 (0)