Skip to content

Commit

Permalink
set window icon/title and use centralized logger (microsoft#30091)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti committed Dec 9, 2023
1 parent 9e03386 commit f30438b
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 96 deletions.
78 changes: 0 additions & 78 deletions src/modules/peek/Peek.Common/Helpers/Logger.cs

This file was deleted.

4 changes: 1 addition & 3 deletions src/modules/peek/Peek.Common/Models/FileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Peek.Common.Extensions;
using Peek.Common.Helpers;
using ManagedCommon;
using Windows.Storage;

#nullable enable
Expand Down
4 changes: 1 addition & 3 deletions src/modules/peek/Peek.Common/Models/FolderItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Peek.Common.Extensions;
using Peek.Common.Helpers;
using ManagedCommon;
using Windows.Storage;

#nullable enable
Expand Down
1 change: 1 addition & 0 deletions src/modules/peek/Peek.Common/Peek.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

using System;
using System.Threading.Tasks;
using ManagedCommon;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Web.WebView2.Core;
using Peek.Common.Constants;
using Peek.Common.Helpers;
using Windows.ApplicationModel.DataTransfer;
using Windows.System;
using Windows.UI;
Expand Down
1 change: 1 addition & 0 deletions src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using ManagedCommon;
using Microsoft.PowerToys.Telemetry;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using ManagedCommon;
using Microsoft.UI.Xaml.Media.Imaging;
using Peek.Common;
using Peek.Common.Helpers;
using Peek.Common.Models;
using Peek.FilePreviewer.Previewers.Helpers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using ManagedCommon;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
Expand Down
3 changes: 1 addition & 2 deletions src/modules/peek/Peek.UI/Extensions/IShellItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

using System;
using System.IO;
using System.Runtime.CompilerServices;
using Peek.Common.Helpers;
using ManagedCommon;
using Peek.Common.Models;

namespace Peek.UI.Extensions
Expand Down
4 changes: 2 additions & 2 deletions src/modules/peek/Peek.UI/Helpers/DefaultAppHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using System.Runtime.InteropServices;
using System.Text;
using Peek.Common.Helpers;
using ManagedCommon;
using Peek.Common.Models;
using Peek.UI.Native;

Expand All @@ -30,7 +30,7 @@ public static string TryGetDefaultAppName(string extension)
ret = NativeMethods.AssocQueryString(NativeMethods.AssocF.Verify, NativeMethods.AssocStr.FriendlyAppName, extension, null, sb, ref length);
if (ret != HResult.Ok)
{
Logger.LogError($"Error when getting accessString for {extension} file: {Marshal.GetExceptionForHR((int)ret)!.Message}" );
Logger.LogError($"Error when getting accessString for {extension} file: {Marshal.GetExceptionForHR((int)ret)!.Message}");
return appName;
}

Expand Down
13 changes: 13 additions & 0 deletions src/modules/peek/Peek.UI/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using ManagedCommon;
using Microsoft.UI.Xaml;
using Peek.Common.Helpers;
using Peek.Common.Models;
Expand All @@ -15,6 +16,7 @@ namespace Peek.UI
{
public partial class MainWindowViewModel : ObservableObject
{
private static readonly string _defaultWindowTitle = ResourceLoaderInstance.ResourceLoader.GetString("AppTitle/Title");
private const int NavigationThrottleDelayMs = 100;

[ObservableProperty]
Expand All @@ -23,6 +25,16 @@ public partial class MainWindowViewModel : ObservableObject
[ObservableProperty]
private IFileSystemItem? _currentItem;

partial void OnCurrentItemChanged(IFileSystemItem? value)
{
WindowTitle = value != null
? ReadableStringHelper.FormatResourceString("WindowTitle", value.Name)
: _defaultWindowTitle;
}

[ObservableProperty]
private string _windowTitle;

[ObservableProperty]
private NeighboringItems? _items;

Expand All @@ -36,6 +48,7 @@ public partial class MainWindowViewModel : ObservableObject
public MainWindowViewModel(NeighboringItemsQuery query)
{
NeighboringItemsQuery = query;
WindowTitle = _defaultWindowTitle;

NavigationThrottleTimer.Tick += NavigationThrottleTimer_Tick;
NavigationThrottleTimer.Interval = TimeSpan.FromMilliseconds(NavigationThrottleDelayMs);
Expand Down
1 change: 1 addition & 0 deletions src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="using:Peek.UI.Views"
xmlns:winuiex="using:WinUIEx"
Title="{x:Bind ViewModel.WindowTitle, Mode=OneWay}"
MinWidth="450"
MinHeight="400"
mc:Ignorable="d">
Expand Down
1 change: 1 addition & 0 deletions src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public MainWindow()
ViewModel = Application.Current.GetService<MainWindowViewModel>();

TitleBarControl.SetTitleBarToWindow(this);
AppWindow.SetIcon("Assets/Peek/Icon.ico");

AppWindow.Closing += AppWindow_Closing;
}
Expand Down
6 changes: 0 additions & 6 deletions src/modules/peek/Peek.UI/PeekXAML/Views/TitleBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using Windows.Graphics;
using Windows.Storage;
using Windows.System;
using WinUIEx;

namespace Peek.UI.Views
{
Expand Down Expand Up @@ -123,11 +122,6 @@ public void SetTitleBarToWindow(MainWindow mainWindow)
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
ThemeHelpers.SetImmersiveDarkMode(hWnd, ThemeHelpers.GetAppTheme() == AppTheme.Dark);
Visibility = Visibility.Collapsed;

// Set window icon
WindowId windowId = Win32Interop.GetWindowIdFromWindow(hWnd);
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
appWindow.SetIcon("Assets/Peek/Icon.ico");
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/modules/peek/Peek.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,8 @@
<value> ({1:N0} byte)</value>
<comment>Displays unit byte. Don't localize the "{1:N0}" part.</comment>
</data>
<data name="WindowTitle" xml:space="preserve">
<value>{0} - Peek</value>
<comment>Title of the Peek window. {0} is the name of the currently previewed item."Peek" is the name of the utility.</comment>
</data>
</root>

0 comments on commit f30438b

Please sign in to comment.