mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
set window icon/title and use centralized logger (#30091)
This commit is contained in:
committed by
GitHub
parent
9e03386eb3
commit
f30438b959
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Peek.UI.Helpers
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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]
|
||||
@@ -23,6 +25,16 @@ namespace Peek.UI
|
||||
[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;
|
||||
|
||||
@@ -36,6 +48,7 @@ namespace Peek.UI
|
||||
public MainWindowViewModel(NeighboringItemsQuery query)
|
||||
{
|
||||
NeighboringItemsQuery = query;
|
||||
WindowTitle = _defaultWindowTitle;
|
||||
|
||||
NavigationThrottleTimer.Tick += NavigationThrottleTimer_Tick;
|
||||
NavigationThrottleTimer.Interval = TimeSpan.FromMilliseconds(NavigationThrottleDelayMs);
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace Peek.UI
|
||||
ViewModel = Application.Current.GetService<MainWindowViewModel>();
|
||||
|
||||
TitleBarControl.SetTitleBarToWindow(this);
|
||||
AppWindow.SetIcon("Assets/Peek/Icon.ico");
|
||||
|
||||
AppWindow.Closing += AppWindow_Closing;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ using Peek.UI.Telemetry.Events;
|
||||
using Windows.Graphics;
|
||||
using Windows.Storage;
|
||||
using Windows.System;
|
||||
using WinUIEx;
|
||||
|
||||
namespace Peek.UI.Views
|
||||
{
|
||||
@@ -123,11 +122,6 @@ namespace Peek.UI.Views
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user