diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs
index 56361f23800a..5b3725fb7efe 100644
--- a/src/Files.App/App.xaml.cs
+++ b/src/Files.App/App.xaml.cs
@@ -141,7 +141,7 @@ async Task ActivateAsync()
SystemTrayIcon = new SystemTrayIcon().Show();
// Sleep current instance
- Program.Pool = new(0, 1, $"Files-{ApplicationService.AppEnvironment}-Instance");
+ Program.Pool = new(0, 1, $"Files-{AppLifecycleHelper.AppEnvironment}-Instance");
Thread.Yield();
@@ -230,7 +230,7 @@ private async void Window_Closed(object sender, WindowEventArgs args)
await FilePropertiesHelpers.WaitClosingAll();
// Sleep current instance
- Program.Pool = new(0, 1, $"Files-{ApplicationService.AppEnvironment}-Instance");
+ Program.Pool = new(0, 1, $"Files-{AppLifecycleHelper.AppEnvironment}-Instance");
Thread.Yield();
diff --git a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs
index 3ca342a3d309..811d8c59e9f6 100644
--- a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs
+++ b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs
@@ -14,6 +14,7 @@
using Microsoft.Extensions.Logging;
using System.IO;
using System.Text;
+using Windows.ApplicationModel;
using Windows.Storage;
using Windows.System;
using Windows.UI.Notifications;
@@ -26,6 +27,37 @@ namespace Files.App.Helpers
///
public static class AppLifecycleHelper
{
+ ///
+ /// Gets the value that provides application environment or branch name.
+ ///
+ public static AppEnvironment AppEnvironment { get; } =
+#if STORE
+ AppEnvironment.Store;
+#elif PREVIEW
+ AppEnvironment.Preview;
+#elif STABLE
+ AppEnvironment.Stable;
+#else
+ AppEnvironment.Dev;
+#endif
+
+ ///
+ /// Gets application package version.
+ ///
+ public static Version AppVersion { get; } =
+ new(Package.Current.Id.Version.Major, Package.Current.Id.Version.Minor, Package.Current.Id.Version.Build, Package.Current.Id.Version.Revision);
+
+ ///
+ /// Gets application icon path.
+ ///
+ public static string AppIconPath { get; } =
+ SystemIO.Path.Combine(Package.Current.InstalledLocation.Path, AppEnvironment switch
+ {
+ AppEnvironment.Dev => Constants.AssetPaths.DevLogo,
+ AppEnvironment.Preview => Constants.AssetPaths.PreviewLogo,
+ _ => Constants.AssetPaths.StableLogo
+ });
+
///
/// Initializes the app components.
///
@@ -103,7 +135,7 @@ public static void ConfigureAppCenter()
public static IHost ConfigureHost()
{
return Host.CreateDefaultBuilder()
- .UseEnvironment(ApplicationService.AppEnvironment.ToString())
+ .UseEnvironment(AppLifecycleHelper.AppEnvironment.ToString())
.ConfigureLogging(builder => builder
.AddProvider(new FileLoggerProvider(Path.Combine(ApplicationData.Current.LocalFolder.Path, "debug.log")))
.SetMinimumLevel(LogLevel.Information))
@@ -135,7 +167,6 @@ public static IHost ConfigureHost()
.AddSingleton()
.AddSingleton()
.AddSingleton()
- .AddSingleton()
.AddSingleton()
.AddSingleton()
.AddSingleton()
diff --git a/src/Files.App/MainWindow.xaml.cs b/src/Files.App/MainWindow.xaml.cs
index 0057f682894d..e4f9551de00d 100644
--- a/src/Files.App/MainWindow.xaml.cs
+++ b/src/Files.App/MainWindow.xaml.cs
@@ -19,10 +19,6 @@ namespace Files.App
{
public sealed partial class MainWindow : WindowEx
{
- private readonly IApplicationService ApplicationService;
-
- private MainPageViewModel mainPageViewModel;
-
private static MainWindow? _Instance;
public static MainWindow Instance => _Instance ??= new();
@@ -30,8 +26,6 @@ public sealed partial class MainWindow : WindowEx
private MainWindow()
{
- ApplicationService = new ApplicationService();
-
WindowHandle = this.GetWindowHandle();
InitializeComponent();
@@ -49,7 +43,7 @@ private void EnsureEarlyWindow()
MinWidth = 516;
AppWindow.Title = "Files";
- AppWindow.SetIcon(Path.Combine(Package.Current.InstalledLocation.Path, ApplicationService.AppIcoPath));
+ AppWindow.SetIcon(AppLifecycleHelper.AppIconPath);
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
diff --git a/src/Files.App/Program.cs b/src/Files.App/Program.cs
index cc56c6a8f3be..5b1c739948cf 100644
--- a/src/Files.App/Program.cs
+++ b/src/Files.App/Program.cs
@@ -27,7 +27,7 @@ internal sealed class Program
static Program()
{
- var pool = new Semaphore(0, 1, $"Files-{ApplicationService.AppEnvironment}-Instance", out var isNew);
+ var pool = new Semaphore(0, 1, $"Files-{AppLifecycleHelper.AppEnvironment}-Instance", out var isNew);
if (!isNew)
{
diff --git a/src/Files.App/Services/ApplicationService.cs b/src/Files.App/Services/ApplicationService.cs
deleted file mode 100644
index b9148741640e..000000000000
--- a/src/Files.App/Services/ApplicationService.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using Windows.ApplicationModel;
-
-namespace Files.App.Services
-{
- ///
- internal sealed class ApplicationService : IApplicationService
- {
- // Workaround to help improve code clarity
- internal static readonly AppEnvironment AppEnvironment =
-#if STORE
- AppEnvironment.Store;
-#elif PREVIEW
- AppEnvironment.Preview;
-#elif STABLE
- AppEnvironment.Stable;
-#else
- AppEnvironment.Dev;
-#endif
-
- ///
- public AppEnvironment Environment { get; } = AppEnvironment;
-
- ///
- public Version AppVersion { get; } = new(
- Package.Current.Id.Version.Major,
- Package.Current.Id.Version.Minor,
- Package.Current.Id.Version.Build,
- Package.Current.Id.Version.Revision);
-
- ///
- public string AppIcoPath { get; } = AppEnvironment switch
- {
- AppEnvironment.Dev => Constants.AssetPaths.DevLogo,
- AppEnvironment.Preview => Constants.AssetPaths.PreviewLogo,
- _ => Constants.AssetPaths.StableLogo
- };
- }
-}
diff --git a/src/Files.App/Utils/Git/GitHelpers.cs b/src/Files.App/Utils/Git/GitHelpers.cs
index aed15ef08641..ec05f54e6ad7 100644
--- a/src/Files.App/Utils/Git/GitHelpers.cs
+++ b/src/Files.App/Utils/Git/GitHelpers.cs
@@ -31,8 +31,6 @@ internal static class GitHelpers
private static readonly IDialogService _dialogService = Ioc.Default.GetRequiredService();
- private static readonly IApplicationService _applicationService = Ioc.Default.GetRequiredService();
-
private static readonly FetchOptions _fetchOptions = new()
{
Prune = true
@@ -40,7 +38,7 @@ internal static class GitHelpers
private static readonly PullOptions _pullOptions = new();
- private static readonly string _clientId = _applicationService.Environment is AppEnvironment.Store or AppEnvironment.Stable or AppEnvironment.Preview
+ private static readonly string _clientId = AppLifecycleHelper.AppEnvironment is AppEnvironment.Store or AppEnvironment.Stable or AppEnvironment.Preview
? CLIENT_ID_SECRET
: string.Empty;
diff --git a/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs b/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs
index a7b40207ba74..a24a0f9efe06 100644
--- a/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs
+++ b/src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs
@@ -8,6 +8,7 @@
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.Windows.ApplicationModel.Resources;
using System.Collections.Concurrent;
+using Windows.ApplicationModel;
using Windows.Graphics;
namespace Files.App.Utils.Storage
@@ -88,8 +89,6 @@ public static void OpenPropertiesWindow(IShellPage associatedInstance)
/// Associated main window instance
public static void OpenPropertiesWindow(object item, IShellPage associatedInstance)
{
- var applicationService = Ioc.Default.GetRequiredService();
-
if (item is null)
return;
@@ -120,7 +119,7 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
- appWindow.SetIcon(applicationService.AppIcoPath);
+ appWindow.SetIcon(AppLifecycleHelper.AppIconPath);
frame.Navigate(
typeof(Views.Properties.MainPropertiesPage),
diff --git a/src/Files.App/Utils/Taskbar/SystemTrayIcon.cs b/src/Files.App/Utils/Taskbar/SystemTrayIcon.cs
index 1bf0e530fe5a..af10341f2d91 100644
--- a/src/Files.App/Utils/Taskbar/SystemTrayIcon.cs
+++ b/src/Files.App/Utils/Taskbar/SystemTrayIcon.cs
@@ -131,16 +131,7 @@ private Rect Position
///
public SystemTrayIcon()
{
- string appIcoPath = ApplicationService.AppEnvironment switch
- {
- AppEnvironment.Dev => Constants.AssetPaths.DevLogo,
- AppEnvironment.Preview => Constants.AssetPaths.PreviewLogo,
- _ => Constants.AssetPaths.StableLogo
- };
-
- var iconPath = SystemIO.Path.Combine(Package.Current.InstalledLocation.Path, appIcoPath);
-
- _Icon = new(iconPath);
+ _Icon = new(AppLifecycleHelper.AppIconPath);
_Tooltip = Package.Current.DisplayName;
_taskbarRestartMessageId = PInvoke.RegisterWindowMessage("TaskbarCreated");
diff --git a/src/Files.App/ViewModels/Settings/AdvancedViewModel.cs b/src/Files.App/ViewModels/Settings/AdvancedViewModel.cs
index 5f9117c5466a..e90dcb2b5a6d 100644
--- a/src/Files.App/ViewModels/Settings/AdvancedViewModel.cs
+++ b/src/Files.App/ViewModels/Settings/AdvancedViewModel.cs
@@ -198,11 +198,9 @@ private async Task ImportSettingsAsync()
private async Task ExportSettingsAsync()
{
- var applicationService = Ioc.Default.GetRequiredService();
-
FileSavePicker filePicker = InitializeWithWindow(new FileSavePicker());
filePicker.FileTypeChoices.Add("Zip File", new[] { ".zip" });
- filePicker.SuggestedFileName = $"Files_{applicationService.AppVersion}";
+ filePicker.SuggestedFileName = $"Files_{AppLifecycleHelper.AppVersion}";
StorageFile file = await filePicker.PickSaveFileAsync();
if (file is not null)
diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs
index 40079660cb9c..60c092673d05 100644
--- a/src/Files.App/Views/MainPage.xaml.cs
+++ b/src/Files.App/Views/MainPage.xaml.cs
@@ -26,7 +26,6 @@ namespace Files.App.Views
public sealed partial class MainPage : Page
{
public IUserSettingsService UserSettingsService { get; }
- public IApplicationService ApplicationService { get; }
public ICommandManager Commands { get; }
@@ -53,7 +52,6 @@ public MainPage()
// Dependency Injection
UserSettingsService = Ioc.Default.GetRequiredService();
- ApplicationService = Ioc.Default.GetRequiredService();
Commands = Ioc.Default.GetRequiredService();
WindowContext = Ioc.Default.GetRequiredService();
SidebarAdaptiveViewModel = Ioc.Default.GetRequiredService();
@@ -302,7 +300,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
// ToDo put this in a StartupPromptService
if
(
- ApplicationService.Environment is not AppEnvironment.Dev &&
+ AppLifecycleHelper.AppEnvironment is not AppEnvironment.Dev &&
isAppRunningAsAdmin &&
UserSettingsService.ApplicationSettingsService.ShowRunningAsAdminPrompt
)
diff --git a/src/Files.App/Views/SplashScreenPage.xaml.cs b/src/Files.App/Views/SplashScreenPage.xaml.cs
index da9e23d82aa0..0ca92069809b 100644
--- a/src/Files.App/Views/SplashScreenPage.xaml.cs
+++ b/src/Files.App/Views/SplashScreenPage.xaml.cs
@@ -12,7 +12,7 @@ namespace Files.App.Views
public sealed partial class SplashScreenPage : Page
{
private string BranchLabel =>
- ApplicationService.AppEnvironment switch
+ AppLifecycleHelper.AppEnvironment switch
{
AppEnvironment.Dev => "Dev",
AppEnvironment.Preview => "Preview",
diff --git a/src/Files.Core/Services/IApplicationService.cs b/src/Files.Core/Services/IApplicationService.cs
deleted file mode 100644
index fcc6d45421ad..000000000000
--- a/src/Files.Core/Services/IApplicationService.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-namespace Files.Core.Services
-{
- ///
- /// A service that interacts with common app-related APIs.
- ///
- public interface IApplicationService
- {
- ///
- /// Gets the application build environment.
- ///
- AppEnvironment Environment { get; }
-
- ///
- /// Gets the version of the app.
- ///
- Version AppVersion { get; }
-
- ///
- /// Gets the path at which the App Logo is located.
- ///
- [Obsolete("This is a bad way of accessing the logo. Use something more abstract instead, and ideally move it out of this interface.")]
- string AppIcoPath { get; }
- }
-}