Skip to content

Commit

Permalink
Fix: Fixed an issue where the Properties window had the wrong icon (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa authored Jan 29, 2024
1 parent 204b26f commit c413174
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 97 deletions.
4 changes: 2 additions & 2 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
35 changes: 33 additions & 2 deletions src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,37 @@ namespace Files.App.Helpers
/// </summary>
public static class AppLifecycleHelper
{
/// <summary>
/// Gets the value that provides application environment or branch name.
/// </summary>
public static AppEnvironment AppEnvironment { get; } =
#if STORE
AppEnvironment.Store;
#elif PREVIEW
AppEnvironment.Preview;
#elif STABLE
AppEnvironment.Stable;
#else
AppEnvironment.Dev;
#endif

/// <summary>
/// Gets application package version.
/// </summary>
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);

/// <summary>
/// Gets application icon path.
/// </summary>
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
});

/// <summary>
/// Initializes the app components.
/// </summary>
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -135,7 +167,6 @@ public static IHost ConfigureHost()
.AddSingleton<IFileTagsService, FileTagsService>()
.AddSingleton<ICommandManager, CommandManager>()
.AddSingleton<IModifiableCommandManager, ModifiableCommandManager>()
.AddSingleton<IApplicationService, ApplicationService>()
.AddSingleton<IStorageService, NativeStorageService>()
.AddSingleton<IFtpStorageService, FtpStorageService>()
.AddSingleton<IAddItemService, AddItemService>()
Expand Down
8 changes: 1 addition & 7 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@ 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();

public IntPtr WindowHandle { get; }

private MainWindow()
{
ApplicationService = new ApplicationService();

WindowHandle = this.GetWindowHandle();

InitializeComponent();
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
38 changes: 0 additions & 38 deletions src/Files.App/Services/ApplicationService.cs

This file was deleted.

4 changes: 1 addition & 3 deletions src/Files.App/Utils/Git/GitHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ internal static class GitHelpers

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

private static readonly IApplicationService _applicationService = Ioc.Default.GetRequiredService<IApplicationService>();

private static readonly FetchOptions _fetchOptions = new()
{
Prune = true
};

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;

Expand Down
5 changes: 2 additions & 3 deletions src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,8 +89,6 @@ public static void OpenPropertiesWindow(IShellPage associatedInstance)
/// <param name="associatedInstance">Associated main window instance</param>
public static void OpenPropertiesWindow(object item, IShellPage associatedInstance)
{
var applicationService = Ioc.Default.GetRequiredService<IApplicationService>();

if (item is null)
return;

Expand Down Expand Up @@ -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),
Expand Down
11 changes: 1 addition & 10 deletions src/Files.App/Utils/Taskbar/SystemTrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,7 @@ private Rect Position
/// </remarks>
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");

Expand Down
4 changes: 1 addition & 3 deletions src/Files.App/ViewModels/Settings/AdvancedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,9 @@ private async Task ImportSettingsAsync()

private async Task ExportSettingsAsync()
{
var applicationService = Ioc.Default.GetRequiredService<IApplicationService>();

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)
Expand Down
4 changes: 1 addition & 3 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

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

// Dependency Injection
UserSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
ApplicationService = Ioc.Default.GetRequiredService<IApplicationService>();
Commands = Ioc.Default.GetRequiredService<ICommandManager>();
WindowContext = Ioc.Default.GetRequiredService<IWindowContext>();
SidebarAdaptiveViewModel = Ioc.Default.GetRequiredService<SidebarViewModel>();
Expand Down Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/SplashScreenPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 0 additions & 24 deletions src/Files.Core/Services/IApplicationService.cs

This file was deleted.

0 comments on commit c413174

Please sign in to comment.