mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 21:41:51 +02:00
[General]Reduce installer size by flattening application paths (#27451)
* Flatten everything and succeed build * Figure out Settings assets * Remove UseCommonOutputDirectory tag * Proper settings app path * [VCM] Fix assets location * Fix some runtime paths * [RegistryPreview]Use MRTCore specific pri file * [Hosts]Use MRTCore specific pri file * [Settings]Use MRTCore specific pri file * [Peek]Use MRTCore specific pri file * [FileLocksmith]Use MRTCore specific pri file * [ScreenRuler]Use MRTCore specific pri file * [PowerRename]Use MRTCore specific pri file * [Peek]Move assets to own folder * [FileLocksmith] Use own Assets path * [Hosts]Use own assets folder * [PowerRename]Use own assets dir * [MeasureTool] Use its own assets folder * [ImageResizer]Use its own assets path * Fix spellcheck * Fix tab instead of space in project files * Normalize target frameworks and platforms * Remove WINRT_NO_MAKE_DETECTION flag. No longer needed? * Fix AOT and Hosts locations * Fix Dll version differences on dependency * Add Common.UI.csproj as refernce to fix dll versions * Update ControlzEx to normalize dll versions * Update System.Management version to 7.0.2 * Add GPOWrapper to Registry Preview to fix dll versions * [PTRun]Reference Microsoft.Extensions.Hosting to fix dll versions * Fix remaining output paths / dll version conflicts * [KeyboardManager]Executables still on their own directories * Fix Monaco paths * WinAppSDK apps get to play outside again * Enable VCM settings again * Fix KBM Editor path again * [Monaco]Set to own Assets dir * Fix installer preamble; Fix publish. remove unneeded publishes * Remove Hardlink functions * Installer builds again (still needs work to work) * Readd Monaco to spellcheck excludes * Fix spellcheck and call publish.cmd again * [Installer] Remove components that don't need own dirs * [Installer] Refactor Power Launcher * [Installer] Refactor Color Picker * [Installer] Refactor Monaco assets * [Installer]Generate File script no longer needs to remove files * [Installer]Refactor FileLocksmith * [Installer] Refactor Hosts * [Installer]Refactor Image Resizer * [Installer]Refactor MouseUtils * [Installer]Refactor MWB * [Installer]Refactor MeasureTool * [Installer]Refactor Peek * [Installer]Refactor PowerRename and registry fixes * [Installer]Refactor RegistryPreview * [Installer]Refactor ShortcutGuide * [Installer]Refactor Settings * [Installer]Clean up some unused stuff * [Installer]Clean up stuff for user install * [Installer]Fix WinUi3Apps wxs * [Installer]Fix misplaced folders * [Installer]Move x86 VCM dll to right path * Fix monaco language list location * [Installer]Fix VCM directory reference * [CI]Fix signing * [Installer] Fix resources folder for release CI * [ci]Looks like we still ship NLog on PowerToys Run * [Settings]Add dependency to avoid dll collision with Experimentation * [RegistryPreview]Move XAML files to own path * [RegistryPreview]Fix app icon * [Hosts]Move XAML files to their own path * [FileLocksmith]Move XAML files to their own path * [Peek]Move XAML files to own path * [ScreenRuler]Move XAML files to its own path * [Settings]Move XAML to its own path * [ColorPicker]Move Resources to Assets * [ShortcutGuide]Move svgs to own Assets path * [Awake]Move images to assets path * [Runner]Remove debug checks for PowerToys Run assets * [PTRun]Move images to its own assets path * [ImageResizer]Icon for context menu on own assets path * [PowerRename]Move ico to its own path * Remove unneeded intermediary directories * Remove further int dirs * Move tests to its own output path * Fix spellcheck * spellcheck: remove warnings * [CppAnalyzers]Ignore rule in a tool * [CI]Check if all deps.json files reference same versions * fix spellcheck * [ci]Fix task identation * [ci]Add script to guard against asset conflicts * [ci]Add more deps.json audit steps in the release build * Add xbf to spellcheck expects * Fix typo in asset conflict check scripts * Fix some more dependency conflicts * Downgrade CsWinRT to have the same dll version as sdk * [ci]Do a recursive check for every deps.json * Fix spellcheck error inside comment * [ci]Fix asset script error * [ci]Name deps.json verify tasks a bit better * [ci]Improve deps json verify script output * [ci]Update WinRT version to the same running in CI * Also upgrade CsWinRT in NOTICE.MD * [PowerRename]Move XAML files to own path * [Common]Fix Settings executable path * [ci]Verify there's no xbf files in app directories * [installer]Fix firewall path * [Monaco]Move new files to their proper assets path * [Monaco]Fix paths for new files after merge * [Feedback]Removed unneeded build conditions * [Feedback]Clear vcxproj direct reference to frameworks * [Feedback]RunPlugins name to hold PTRun plugins * [Feedback]Remove unneeded foreach * [Feedback]Shortcut Guide svgs with ** in project file * [Feedback]Fix spellcheck
This commit is contained in:
287
src/modules/peek/Peek.UI/PeekXAML/Views/TitleBar.xaml.cs
Normal file
287
src/modules/peek/Peek.UI/PeekXAML/Views/TitleBar.xaml.cs
Normal file
@@ -0,0 +1,287 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Peek.Common.Helpers;
|
||||
using Peek.Common.Models;
|
||||
using Peek.UI.Extensions;
|
||||
using Peek.UI.Helpers;
|
||||
using Peek.UI.Telemetry.Events;
|
||||
using Windows.Graphics;
|
||||
using Windows.Storage;
|
||||
using Windows.System;
|
||||
using WinUIEx;
|
||||
|
||||
namespace Peek.UI.Views
|
||||
{
|
||||
[INotifyPropertyChanged]
|
||||
public sealed partial class TitleBar : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty ItemProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(Item),
|
||||
typeof(IFileSystemItem),
|
||||
typeof(TitleBar),
|
||||
new PropertyMetadata(null, (d, e) => ((TitleBar)d).OnFilePropertyChanged()));
|
||||
|
||||
public static readonly DependencyProperty FileIndexProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(FileIndex),
|
||||
typeof(int),
|
||||
typeof(TitleBar),
|
||||
new PropertyMetadata(-1, (d, e) => ((TitleBar)d).OnFileIndexPropertyChanged()));
|
||||
|
||||
public static readonly DependencyProperty IsMultiSelectionProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(IsMultiSelection),
|
||||
typeof(bool),
|
||||
typeof(TitleBar),
|
||||
new PropertyMetadata(false));
|
||||
|
||||
public static readonly DependencyProperty NumberOfFilesProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(NumberOfFiles),
|
||||
typeof(int),
|
||||
typeof(TitleBar),
|
||||
new PropertyMetadata(null, null));
|
||||
|
||||
[ObservableProperty]
|
||||
private string openWithAppText = ResourceLoaderInstance.ResourceLoader.GetString("LaunchAppButton_OpenWith_Text");
|
||||
|
||||
[ObservableProperty]
|
||||
private string openWithAppToolTip = ResourceLoaderInstance.ResourceLoader.GetString("LaunchAppButton_OpenWith_ToolTip");
|
||||
|
||||
[ObservableProperty]
|
||||
private string? fileCountText;
|
||||
|
||||
[ObservableProperty]
|
||||
private string defaultAppName = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool pinned = false;
|
||||
|
||||
public TitleBar()
|
||||
{
|
||||
InitializeComponent();
|
||||
TitleBarRootContainer.SizeChanged += TitleBarRootContainer_SizeChanged;
|
||||
}
|
||||
|
||||
public IFileSystemItem Item
|
||||
{
|
||||
get => (IFileSystemItem)GetValue(ItemProperty);
|
||||
set => SetValue(ItemProperty, value);
|
||||
}
|
||||
|
||||
public int FileIndex
|
||||
{
|
||||
get => (int)GetValue(FileIndexProperty);
|
||||
set => SetValue(FileIndexProperty, value);
|
||||
}
|
||||
|
||||
public bool IsMultiSelection
|
||||
{
|
||||
get => (bool)GetValue(IsMultiSelectionProperty);
|
||||
set => SetValue(IsMultiSelectionProperty, value);
|
||||
}
|
||||
|
||||
public int NumberOfFiles
|
||||
{
|
||||
get => (int)GetValue(NumberOfFilesProperty);
|
||||
set => SetValue(NumberOfFilesProperty, value);
|
||||
}
|
||||
|
||||
private Window? MainWindow { get; set; }
|
||||
|
||||
public void SetTitleBarToWindow(MainWindow mainWindow)
|
||||
{
|
||||
MainWindow = mainWindow;
|
||||
|
||||
if (AppWindowTitleBar.IsCustomizationSupported())
|
||||
{
|
||||
UpdateTitleBarCustomization(mainWindow);
|
||||
}
|
||||
else
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility IsLaunchDefaultAppButtonVisible(string appName)
|
||||
{
|
||||
return string.IsNullOrEmpty(appName) ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async void LaunchDefaultAppButtonAsync()
|
||||
{
|
||||
if (Item is not FileItem fileItem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StorageFile? storageFile = await fileItem.GetStorageFileAsync();
|
||||
LauncherOptions options = new();
|
||||
|
||||
PowerToysTelemetry.Log.WriteEvent(new OpenWithEvent() { App = DefaultAppName ?? string.Empty });
|
||||
|
||||
// StorageFile objects can't represent files that are ".lnk", ".url", or ".wsh" file types.
|
||||
// https://learn.microsoft.com/en-us/uwp/api/windows.storage.storagefile?view=winrt-22621
|
||||
if (storageFile == null)
|
||||
{
|
||||
options.DisplayApplicationPicker = true;
|
||||
await Launcher.LaunchUriAsync(new Uri(Item.Path), options);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(DefaultAppName))
|
||||
{
|
||||
// If there's no default app found, open the App picker
|
||||
options.DisplayApplicationPicker = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try to launch the default app for current file format
|
||||
bool result = await Launcher.LaunchFileAsync(storageFile, options);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
// If we couldn't successfully open the default app, open the App picker as a fallback
|
||||
options.DisplayApplicationPicker = true;
|
||||
await Launcher.LaunchFileAsync(storageFile, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string PinGlyph(bool pinned)
|
||||
{
|
||||
return pinned ? "\xE841" : "\xE77A";
|
||||
}
|
||||
|
||||
public string PinToolTip(bool pinned)
|
||||
{
|
||||
return pinned ? ResourceLoaderInstance.ResourceLoader.GetString("UnpinButton_ToolTip") : ResourceLoaderInstance.ResourceLoader.GetString("PinButton_ToolTip");
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Pin()
|
||||
{
|
||||
Pinned = !Pinned;
|
||||
}
|
||||
|
||||
private void TitleBarRootContainer_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
UpdateDragRegion();
|
||||
}
|
||||
|
||||
private void UpdateDragRegion()
|
||||
{
|
||||
if (MainWindow == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var appWindow = MainWindow.AppWindow;
|
||||
if (AppWindowTitleBar.IsCustomizationSupported() && appWindow != null && appWindow.TitleBar.ExtendsContentIntoTitleBar)
|
||||
{
|
||||
var scale = MainWindow.GetMonitorScale();
|
||||
|
||||
SystemRightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset / scale);
|
||||
SystemLeftPaddingColumn.Width = new GridLength(appWindow.TitleBar.LeftInset / scale);
|
||||
|
||||
var dragRectsList = new List<RectInt32>();
|
||||
|
||||
RectInt32 dragRectangleLeft;
|
||||
dragRectangleLeft.X = (int)(SystemLeftPaddingColumn.ActualWidth * scale);
|
||||
dragRectangleLeft.Y = 0;
|
||||
dragRectangleLeft.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
|
||||
dragRectangleLeft.Width = (int)(DraggableColumn.ActualWidth * scale);
|
||||
|
||||
RectInt32 dragRectangleRight;
|
||||
dragRectangleRight.X = (int)((SystemLeftPaddingColumn.ActualWidth + DraggableColumn.ActualWidth + LaunchAppButtonColumn.ActualWidth) * scale);
|
||||
dragRectangleRight.Y = 0;
|
||||
dragRectangleRight.Height = (int)(TitleBarRootContainer.ActualHeight * scale);
|
||||
dragRectangleRight.Width = (int)(AppRightPaddingColumn.ActualWidth * scale);
|
||||
|
||||
dragRectsList.Add(dragRectangleLeft);
|
||||
dragRectsList.Add(dragRectangleRight);
|
||||
|
||||
appWindow.TitleBar.SetDragRectangles(dragRectsList.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTitleBarCustomization(MainWindow mainWindow)
|
||||
{
|
||||
if (AppWindowTitleBar.IsCustomizationSupported())
|
||||
{
|
||||
AppWindow appWindow = mainWindow.AppWindow;
|
||||
appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
|
||||
appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
|
||||
appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
|
||||
if (ThemeHelpers.GetAppTheme() == AppTheme.Light)
|
||||
{
|
||||
appWindow.TitleBar.ButtonForegroundColor = Colors.DarkSlateGray;
|
||||
}
|
||||
else
|
||||
{
|
||||
appWindow.TitleBar.ButtonForegroundColor = Colors.White;
|
||||
}
|
||||
|
||||
mainWindow.SetTitleBar(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFilePropertyChanged()
|
||||
{
|
||||
if (Item == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateFileCountText();
|
||||
UpdateDefaultAppToLaunch();
|
||||
}
|
||||
|
||||
private void OnFileIndexPropertyChanged()
|
||||
{
|
||||
UpdateFileCountText();
|
||||
}
|
||||
|
||||
private void UpdateFileCountText()
|
||||
{
|
||||
// Update file count
|
||||
if (NumberOfFiles > 1)
|
||||
{
|
||||
string fileCountTextFormat = ResourceLoaderInstance.ResourceLoader.GetString("AppTitle_FileCounts_Text");
|
||||
FileCountText = string.Format(CultureInfo.InvariantCulture, fileCountTextFormat, FileIndex + 1, NumberOfFiles);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDefaultAppToLaunch()
|
||||
{
|
||||
// Update the name of default app to launch
|
||||
DefaultAppName = DefaultAppHelper.TryGetDefaultAppName(Item.Extension);
|
||||
|
||||
string openWithAppTextFormat = ResourceLoaderInstance.ResourceLoader.GetString("LaunchAppButton_OpenWithApp_Text");
|
||||
OpenWithAppText = string.Format(CultureInfo.InvariantCulture, openWithAppTextFormat, DefaultAppName);
|
||||
|
||||
string openWithAppToolTipFormat = ResourceLoaderInstance.ResourceLoader.GetString("LaunchAppButton_OpenWithApp_ToolTip");
|
||||
OpenWithAppToolTip = string.Format(CultureInfo.InvariantCulture, openWithAppToolTipFormat, DefaultAppName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user