Skip to content

Commit c413174

Browse files
authored
Fix: Fixed an issue where the Properties window had the wrong icon (#14470)
1 parent 204b26f commit c413174

File tree

12 files changed

+44
-97
lines changed

12 files changed

+44
-97
lines changed

src/Files.App/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async Task ActivateAsync()
141141
SystemTrayIcon = new SystemTrayIcon().Show();
142142

143143
// Sleep current instance
144-
Program.Pool = new(0, 1, $"Files-{ApplicationService.AppEnvironment}-Instance");
144+
Program.Pool = new(0, 1, $"Files-{AppLifecycleHelper.AppEnvironment}-Instance");
145145

146146
Thread.Yield();
147147

@@ -230,7 +230,7 @@ private async void Window_Closed(object sender, WindowEventArgs args)
230230
await FilePropertiesHelpers.WaitClosingAll();
231231

232232
// Sleep current instance
233-
Program.Pool = new(0, 1, $"Files-{ApplicationService.AppEnvironment}-Instance");
233+
Program.Pool = new(0, 1, $"Files-{AppLifecycleHelper.AppEnvironment}-Instance");
234234

235235
Thread.Yield();
236236

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Microsoft.Extensions.Logging;
1515
using System.IO;
1616
using System.Text;
17+
using Windows.ApplicationModel;
1718
using Windows.Storage;
1819
using Windows.System;
1920
using Windows.UI.Notifications;
@@ -26,6 +27,37 @@ namespace Files.App.Helpers
2627
/// </summary>
2728
public static class AppLifecycleHelper
2829
{
30+
/// <summary>
31+
/// Gets the value that provides application environment or branch name.
32+
/// </summary>
33+
public static AppEnvironment AppEnvironment { get; } =
34+
#if STORE
35+
AppEnvironment.Store;
36+
#elif PREVIEW
37+
AppEnvironment.Preview;
38+
#elif STABLE
39+
AppEnvironment.Stable;
40+
#else
41+
AppEnvironment.Dev;
42+
#endif
43+
44+
/// <summary>
45+
/// Gets application package version.
46+
/// </summary>
47+
public static Version AppVersion { get; } =
48+
new(Package.Current.Id.Version.Major, Package.Current.Id.Version.Minor, Package.Current.Id.Version.Build, Package.Current.Id.Version.Revision);
49+
50+
/// <summary>
51+
/// Gets application icon path.
52+
/// </summary>
53+
public static string AppIconPath { get; } =
54+
SystemIO.Path.Combine(Package.Current.InstalledLocation.Path, AppEnvironment switch
55+
{
56+
AppEnvironment.Dev => Constants.AssetPaths.DevLogo,
57+
AppEnvironment.Preview => Constants.AssetPaths.PreviewLogo,
58+
_ => Constants.AssetPaths.StableLogo
59+
});
60+
2961
/// <summary>
3062
/// Initializes the app components.
3163
/// </summary>
@@ -103,7 +135,7 @@ public static void ConfigureAppCenter()
103135
public static IHost ConfigureHost()
104136
{
105137
return Host.CreateDefaultBuilder()
106-
.UseEnvironment(ApplicationService.AppEnvironment.ToString())
138+
.UseEnvironment(AppLifecycleHelper.AppEnvironment.ToString())
107139
.ConfigureLogging(builder => builder
108140
.AddProvider(new FileLoggerProvider(Path.Combine(ApplicationData.Current.LocalFolder.Path, "debug.log")))
109141
.SetMinimumLevel(LogLevel.Information))
@@ -135,7 +167,6 @@ public static IHost ConfigureHost()
135167
.AddSingleton<IFileTagsService, FileTagsService>()
136168
.AddSingleton<ICommandManager, CommandManager>()
137169
.AddSingleton<IModifiableCommandManager, ModifiableCommandManager>()
138-
.AddSingleton<IApplicationService, ApplicationService>()
139170
.AddSingleton<IStorageService, NativeStorageService>()
140171
.AddSingleton<IFtpStorageService, FtpStorageService>()
141172
.AddSingleton<IAddItemService, AddItemService>()

src/Files.App/MainWindow.xaml.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@ namespace Files.App
1919
{
2020
public sealed partial class MainWindow : WindowEx
2121
{
22-
private readonly IApplicationService ApplicationService;
23-
24-
private MainPageViewModel mainPageViewModel;
25-
2622
private static MainWindow? _Instance;
2723
public static MainWindow Instance => _Instance ??= new();
2824

2925
public IntPtr WindowHandle { get; }
3026

3127
private MainWindow()
3228
{
33-
ApplicationService = new ApplicationService();
34-
3529
WindowHandle = this.GetWindowHandle();
3630

3731
InitializeComponent();
@@ -49,7 +43,7 @@ private void EnsureEarlyWindow()
4943
MinWidth = 516;
5044

5145
AppWindow.Title = "Files";
52-
AppWindow.SetIcon(Path.Combine(Package.Current.InstalledLocation.Path, ApplicationService.AppIcoPath));
46+
AppWindow.SetIcon(AppLifecycleHelper.AppIconPath);
5347
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
5448
AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
5549
AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

src/Files.App/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal sealed class Program
2727

2828
static Program()
2929
{
30-
var pool = new Semaphore(0, 1, $"Files-{ApplicationService.AppEnvironment}-Instance", out var isNew);
30+
var pool = new Semaphore(0, 1, $"Files-{AppLifecycleHelper.AppEnvironment}-Instance", out var isNew);
3131

3232
if (!isNew)
3333
{

src/Files.App/Services/ApplicationService.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Files.App/Utils/Git/GitHelpers.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ internal static class GitHelpers
3131

3232
private static readonly IDialogService _dialogService = Ioc.Default.GetRequiredService<IDialogService>();
3333

34-
private static readonly IApplicationService _applicationService = Ioc.Default.GetRequiredService<IApplicationService>();
35-
3634
private static readonly FetchOptions _fetchOptions = new()
3735
{
3836
Prune = true
3937
};
4038

4139
private static readonly PullOptions _pullOptions = new();
4240

43-
private static readonly string _clientId = _applicationService.Environment is AppEnvironment.Store or AppEnvironment.Stable or AppEnvironment.Preview
41+
private static readonly string _clientId = AppLifecycleHelper.AppEnvironment is AppEnvironment.Store or AppEnvironment.Stable or AppEnvironment.Preview
4442
? CLIENT_ID_SECRET
4543
: string.Empty;
4644

src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.UI.Xaml.Media.Animation;
99
using Microsoft.Windows.ApplicationModel.Resources;
1010
using System.Collections.Concurrent;
11+
using Windows.ApplicationModel;
1112
using Windows.Graphics;
1213

1314
namespace Files.App.Utils.Storage
@@ -88,8 +89,6 @@ public static void OpenPropertiesWindow(IShellPage associatedInstance)
8889
/// <param name="associatedInstance">Associated main window instance</param>
8990
public static void OpenPropertiesWindow(object item, IShellPage associatedInstance)
9091
{
91-
var applicationService = Ioc.Default.GetRequiredService<IApplicationService>();
92-
9392
if (item is null)
9493
return;
9594

@@ -120,7 +119,7 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
120119
appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
121120
appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
122121

123-
appWindow.SetIcon(applicationService.AppIcoPath);
122+
appWindow.SetIcon(AppLifecycleHelper.AppIconPath);
124123

125124
frame.Navigate(
126125
typeof(Views.Properties.MainPropertiesPage),

src/Files.App/Utils/Taskbar/SystemTrayIcon.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,7 @@ private Rect Position
131131
/// </remarks>
132132
public SystemTrayIcon()
133133
{
134-
string appIcoPath = ApplicationService.AppEnvironment switch
135-
{
136-
AppEnvironment.Dev => Constants.AssetPaths.DevLogo,
137-
AppEnvironment.Preview => Constants.AssetPaths.PreviewLogo,
138-
_ => Constants.AssetPaths.StableLogo
139-
};
140-
141-
var iconPath = SystemIO.Path.Combine(Package.Current.InstalledLocation.Path, appIcoPath);
142-
143-
_Icon = new(iconPath);
134+
_Icon = new(AppLifecycleHelper.AppIconPath);
144135
_Tooltip = Package.Current.DisplayName;
145136
_taskbarRestartMessageId = PInvoke.RegisterWindowMessage("TaskbarCreated");
146137

src/Files.App/ViewModels/Settings/AdvancedViewModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,9 @@ private async Task ImportSettingsAsync()
198198

199199
private async Task ExportSettingsAsync()
200200
{
201-
var applicationService = Ioc.Default.GetRequiredService<IApplicationService>();
202-
203201
FileSavePicker filePicker = InitializeWithWindow(new FileSavePicker());
204202
filePicker.FileTypeChoices.Add("Zip File", new[] { ".zip" });
205-
filePicker.SuggestedFileName = $"Files_{applicationService.AppVersion}";
203+
filePicker.SuggestedFileName = $"Files_{AppLifecycleHelper.AppVersion}";
206204

207205
StorageFile file = await filePicker.PickSaveFileAsync();
208206
if (file is not null)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ namespace Files.App.Views
2626
public sealed partial class MainPage : Page
2727
{
2828
public IUserSettingsService UserSettingsService { get; }
29-
public IApplicationService ApplicationService { get; }
3029

3130
public ICommandManager Commands { get; }
3231

@@ -53,7 +52,6 @@ public MainPage()
5352

5453
// Dependency Injection
5554
UserSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
56-
ApplicationService = Ioc.Default.GetRequiredService<IApplicationService>();
5755
Commands = Ioc.Default.GetRequiredService<ICommandManager>();
5856
WindowContext = Ioc.Default.GetRequiredService<IWindowContext>();
5957
SidebarAdaptiveViewModel = Ioc.Default.GetRequiredService<SidebarViewModel>();
@@ -302,7 +300,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
302300
// ToDo put this in a StartupPromptService
303301
if
304302
(
305-
ApplicationService.Environment is not AppEnvironment.Dev &&
303+
AppLifecycleHelper.AppEnvironment is not AppEnvironment.Dev &&
306304
isAppRunningAsAdmin &&
307305
UserSettingsService.ApplicationSettingsService.ShowRunningAsAdminPrompt
308306
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Files.App.Views
1212
public sealed partial class SplashScreenPage : Page
1313
{
1414
private string BranchLabel =>
15-
ApplicationService.AppEnvironment switch
15+
AppLifecycleHelper.AppEnvironment switch
1616
{
1717
AppEnvironment.Dev => "Dev",
1818
AppEnvironment.Preview => "Preview",

src/Files.Core/Services/IApplicationService.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)