mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[General]Display in titlebar/tray if running as admin (#28425)
* display in titlebar if running as admin * show run as admin in tray tooltip
This commit is contained in:
committed by
GitHub
parent
63975600f1
commit
ebd051ff61
@@ -6,7 +6,6 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:views="using:PowerToys.FileLocksmithUI.Views"
|
xmlns:views="using:PowerToys.FileLocksmithUI.Views"
|
||||||
xmlns:winuiex="using:WinUIEx"
|
xmlns:winuiex="using:WinUIEx"
|
||||||
x:Uid="AppTitle"
|
|
||||||
Width="680"
|
Width="680"
|
||||||
MinWidth="480"
|
MinWidth="480"
|
||||||
MinHeight="320"
|
MinHeight="320"
|
||||||
@@ -39,7 +38,6 @@
|
|||||||
Height="16"/>
|
Height="16"/>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
x:Name="AppTitleTextBlock"
|
x:Name="AppTitleTextBlock"
|
||||||
x:Uid="AppTitleText"
|
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Style="{StaticResource CaptionTextBlockStyle}" />
|
Style="{StaticResource CaptionTextBlockStyle}" />
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using Microsoft.UI.Windowing;
|
using Microsoft.UI.Windowing;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
|
using PowerToys.FileLocksmithUI.Helpers;
|
||||||
using WinUIEx;
|
using WinUIEx;
|
||||||
|
|
||||||
namespace FileLocksmithUI
|
namespace FileLocksmithUI
|
||||||
@@ -21,6 +21,11 @@ namespace FileLocksmithUI
|
|||||||
SetTitleBar(AppTitleBar);
|
SetTitleBar(AppTitleBar);
|
||||||
Activated += MainWindow_Activated;
|
Activated += MainWindow_Activated;
|
||||||
AppWindow.SetIcon("Assets/FileLocksmith/Icon.ico");
|
AppWindow.SetIcon("Assets/FileLocksmith/Icon.ico");
|
||||||
|
|
||||||
|
var loader = ResourceLoaderInstance.ResourceLoader;
|
||||||
|
var title = isElevated ? loader.GetString("AppAdminTitle") : loader.GetString("AppTitle");
|
||||||
|
Title = title;
|
||||||
|
AppTitleTextBlock.Text = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
|
private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// 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 Microsoft.Windows.ApplicationModel.Resources;
|
||||||
|
|
||||||
|
namespace PowerToys.FileLocksmithUI.Helpers
|
||||||
|
{
|
||||||
|
internal static class ResourceLoaderInstance
|
||||||
|
{
|
||||||
|
internal static ResourceLoader ResourceLoader { get; private set; }
|
||||||
|
|
||||||
|
static ResourceLoaderInstance()
|
||||||
|
{
|
||||||
|
ResourceLoader = new Microsoft.Windows.ApplicationModel.Resources.ResourceLoader("PowerToys.FileLocksmithUI.pri");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -117,11 +117,9 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<data name="AppTitle.Title" xml:space="preserve">
|
<data name="AppTitle" xml:space="preserve">
|
||||||
<value>File Locksmith</value>
|
|
||||||
</data>
|
|
||||||
<data name="AppTitleText.Text" xml:space="preserve">
|
|
||||||
<value>File Locksmith</value>
|
<value>File Locksmith</value>
|
||||||
|
<comment>Title of the window when running as user.</comment>
|
||||||
</data>
|
</data>
|
||||||
<data name="EmptyListDescription.Text" xml:space="preserve">
|
<data name="EmptyListDescription.Text" xml:space="preserve">
|
||||||
<value>No results</value>
|
<value>No results</value>
|
||||||
@@ -162,4 +160,8 @@
|
|||||||
<data name="User.Header" xml:space="preserve">
|
<data name="User.Header" xml:space="preserve">
|
||||||
<value>User</value>
|
<value>User</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="AppAdminTitle" xml:space="preserve">
|
||||||
|
<value>Administrator: File Locksmith</value>
|
||||||
|
<comment>Title of the window when running as administrator.</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -37,8 +37,7 @@
|
|||||||
x:Name="AppTitleTextBlock"
|
x:Name="AppTitleTextBlock"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
Style="{StaticResource CaptionTextBlockStyle}"
|
Style="{StaticResource CaptionTextBlockStyle}"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center" />
|
||||||
Text="Hosts File Editor" />
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<views:MainPage Grid.Row="1" />
|
<views:MainPage Grid.Row="1" />
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using Hosts.Helpers;
|
using Hosts.Helpers;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
@@ -19,7 +18,11 @@ namespace Hosts
|
|||||||
ExtendsContentIntoTitleBar = true;
|
ExtendsContentIntoTitleBar = true;
|
||||||
SetTitleBar(titleBar);
|
SetTitleBar(titleBar);
|
||||||
AppWindow.SetIcon("Assets/Hosts/Hosts.ico");
|
AppWindow.SetIcon("Assets/Hosts/Hosts.ico");
|
||||||
Title = ResourceLoaderInstance.ResourceLoader.GetString("WindowTitle");
|
|
||||||
|
var loader = ResourceLoaderInstance.ResourceLoader;
|
||||||
|
var title = App.GetService<IElevationHelper>().IsElevated ? loader.GetString("WindowAdminTitle") : loader.GetString("WindowTitle");
|
||||||
|
Title = title;
|
||||||
|
AppTitleTextBlock.Text = title;
|
||||||
|
|
||||||
BringToForeground();
|
BringToForeground();
|
||||||
|
|
||||||
|
|||||||
@@ -307,8 +307,12 @@
|
|||||||
<data name="WarningDialog_Title" xml:space="preserve">
|
<data name="WarningDialog_Title" xml:space="preserve">
|
||||||
<value>Warning</value>
|
<value>Warning</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="WindowAdminTitle" xml:space="preserve">
|
||||||
|
<value>Administrator: Hosts File Editor</value>
|
||||||
|
<comment>Title of the window when running as administrator. "Hosts File Editor" is the name of the utility. "Hosts" refers to the system hosts file, do not loc</comment>
|
||||||
|
</data>
|
||||||
<data name="WindowTitle" xml:space="preserve">
|
<data name="WindowTitle" xml:space="preserve">
|
||||||
<value>Hosts File Editor</value>
|
<value>Hosts File Editor</value>
|
||||||
<comment>"Hosts File Editor" is the name of the utility. "Hosts" refers to the system hosts file, do not loc</comment>
|
<comment>Title of the window when running as user. "Hosts File Editor" is the name of the utility. "Hosts" refers to the system hosts file, do not loc</comment>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -126,4 +126,7 @@
|
|||||||
<value>A new PowerToys version has been installed. Please restart the computer when possible, to fully reload File Explorer extensions.</value>
|
<value>A new PowerToys version has been installed. Please restart the computer when possible, to fully reload File Explorer extensions.</value>
|
||||||
<comment>File Explorer refers to the Windows File Explorer application.</comment>
|
<comment>File Explorer refers to the Windows File Explorer application.</comment>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
<data name="TRAY_ICON_ADMIN_TOOLTIP" xml:space="preserve">
|
||||||
|
<value>Administrator</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
@@ -100,7 +100,7 @@ int runner(bool isProcessElevated, bool openSettings, std::string settingsWindow
|
|||||||
//init_global_error_handlers();
|
//init_global_error_handlers();
|
||||||
#endif
|
#endif
|
||||||
Trace::RegisterProvider();
|
Trace::RegisterProvider();
|
||||||
start_tray_icon();
|
start_tray_icon(isProcessElevated);
|
||||||
CentralizedKeyboardHook::Start();
|
CentralizedKeyboardHook::Start();
|
||||||
|
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
|||||||
@@ -118,6 +118,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Manifest Include="PowerToys.exe.manifest" />
|
<Manifest Include="PowerToys.exe.manifest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Resources.resx" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<Import Project="..\..\deps\spdlog.props" />
|
<Import Project="..\..\deps\spdlog.props" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|||||||
@@ -112,4 +112,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="Generated Files/runner.rc" />
|
<ResourceCompile Include="Generated Files/runner.rc" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Resources.resx">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -268,7 +268,7 @@ LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam
|
|||||||
return DefWindowProc(window, message, wparam, lparam);
|
return DefWindowProc(window, message, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_tray_icon()
|
void start_tray_icon(bool isProcessElevated)
|
||||||
{
|
{
|
||||||
auto h_instance = reinterpret_cast<HINSTANCE>(&__ImageBase);
|
auto h_instance = reinterpret_cast<HINSTANCE>(&__ImageBase);
|
||||||
auto icon = LoadIcon(h_instance, MAKEINTRESOURCE(APPICON));
|
auto icon = LoadIcon(h_instance, MAKEINTRESOURCE(APPICON));
|
||||||
@@ -304,8 +304,16 @@ void start_tray_icon()
|
|||||||
tray_icon_data.hWnd = hwnd;
|
tray_icon_data.hWnd = hwnd;
|
||||||
tray_icon_data.uID = id_tray_icon;
|
tray_icon_data.uID = id_tray_icon;
|
||||||
tray_icon_data.uCallbackMessage = wm_icon_notify;
|
tray_icon_data.uCallbackMessage = wm_icon_notify;
|
||||||
std::wstring about_msg_pt_version = L"PowerToys " + get_product_version();
|
|
||||||
wcscpy_s(tray_icon_data.szTip, sizeof(tray_icon_data.szTip) / sizeof(WCHAR), about_msg_pt_version.c_str());
|
std::wstringstream pt_version_tooltip_stream;
|
||||||
|
if (isProcessElevated)
|
||||||
|
{
|
||||||
|
pt_version_tooltip_stream << GET_RESOURCE_STRING(IDS_TRAY_ICON_ADMIN_TOOLTIP) << L": ";
|
||||||
|
}
|
||||||
|
|
||||||
|
pt_version_tooltip_stream << L"PowerToys " << get_product_version() << '\0';
|
||||||
|
std::wstring pt_version_tooltip = pt_version_tooltip_stream.str();
|
||||||
|
wcscpy_s(tray_icon_data.szTip, sizeof(tray_icon_data.szTip) / sizeof(WCHAR), pt_version_tooltip.c_str());
|
||||||
tray_icon_data.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
|
tray_icon_data.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
|
||||||
ChangeWindowMessageFilterEx(hwnd, WM_COMMAND, MSGFLT_ALLOW, nullptr);
|
ChangeWindowMessageFilterEx(hwnd, WM_COMMAND, MSGFLT_ALLOW, nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// Start the Tray Icon
|
// Start the Tray Icon
|
||||||
void start_tray_icon();
|
void start_tray_icon(bool isProcessElevated);
|
||||||
// Stop the Tray Icon
|
// Stop the Tray Icon
|
||||||
void stop_tray_icon();
|
void stop_tray_icon();
|
||||||
// Open the Settings Window
|
// Open the Settings Window
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ namespace Microsoft.PowerToys.Settings.UI
|
|||||||
|
|
||||||
NativeMethods.SetWindowPlacement(hWnd, ref placement);
|
NativeMethods.SetWindowPlacement(hWnd, ref placement);
|
||||||
|
|
||||||
var loader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
var loader = ResourceLoaderInstance.ResourceLoader;
|
||||||
Title = loader.GetString("SettingsWindow_Title");
|
Title = App.IsElevated ? loader.GetString("SettingsWindow_AdminTitle") : loader.GetString("SettingsWindow_Title");
|
||||||
|
|
||||||
// send IPC Message
|
// send IPC Message
|
||||||
ShellPage.SetDefaultSndMessageCallback(msg =>
|
ShellPage.SetDefaultSndMessageCallback(msg =>
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
Source="/Assets/Settings/icon.ico" />
|
Source="/Assets/Settings/icon.ico" />
|
||||||
<TextBlock
|
<TextBlock
|
||||||
x:Name="AppTitleBarText"
|
x:Name="AppTitleBarText"
|
||||||
x:Uid="SettingsWindow_TitleTxt"
|
|
||||||
Margin="12,0,0,0"
|
Margin="12,0,0,0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Style="{StaticResource CaptionTextBlockStyle}"
|
Style="{StaticResource CaptionTextBlockStyle}"
|
||||||
|
|||||||
@@ -373,6 +373,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
// https://docs.microsoft.com/windows/apps/develop/title-bar?tabs=winui3#full-customization
|
// https://docs.microsoft.com/windows/apps/develop/title-bar?tabs=winui3#full-customization
|
||||||
u.ExtendsContentIntoTitleBar = true;
|
u.ExtendsContentIntoTitleBar = true;
|
||||||
u.SetTitleBar(AppTitleBar);
|
u.SetTitleBar(AppTitleBar);
|
||||||
|
var loader = ResourceLoaderInstance.ResourceLoader;
|
||||||
|
AppTitleBarText.Text = App.IsElevated ? loader.GetString("SettingsWindow_AdminTitle") : loader.GetString("SettingsWindow_Title");
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
DebugMessage.Visibility = Visibility.Visible;
|
DebugMessage.Visibility = Visibility.Visible;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2152,6 +2152,7 @@ From there, simply click on one of the supported files in the File Explorer and
|
|||||||
</data>
|
</data>
|
||||||
<data name="SettingsWindow_Title" xml:space="preserve">
|
<data name="SettingsWindow_Title" xml:space="preserve">
|
||||||
<value>PowerToys Settings</value>
|
<value>PowerToys Settings</value>
|
||||||
|
<comment>Title of the settings window when running as user</comment>
|
||||||
</data>
|
</data>
|
||||||
<data name="Awake.ModuleTitle" xml:space="preserve">
|
<data name="Awake.ModuleTitle" xml:space="preserve">
|
||||||
<value>Awake</value>
|
<value>Awake</value>
|
||||||
@@ -3612,9 +3613,6 @@ Activate by holding the key for the character you want to add an accent to, then
|
|||||||
<value>Maximum width (px)</value>
|
<value>Maximum width (px)</value>
|
||||||
<comment>px = pixels</comment>
|
<comment>px = pixels</comment>
|
||||||
</data>
|
</data>
|
||||||
<data name="SettingsWindow_TitleTxt.Text" xml:space="preserve">
|
|
||||||
<value>PowerToys Settings</value>
|
|
||||||
</data>
|
|
||||||
<data name="Oobe_Peek.Description" xml:space="preserve">
|
<data name="Oobe_Peek.Description" xml:space="preserve">
|
||||||
<value>A lightning fast file preview feature for Windows.</value>
|
<value>A lightning fast file preview feature for Windows.</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -3674,4 +3672,8 @@ Activate by holding the key for the character you want to add an accent to, then
|
|||||||
<data name="MouseUtils_FindMyMouse_ActivationShortcut.Header" xml:space="preserve">
|
<data name="MouseUtils_FindMyMouse_ActivationShortcut.Header" xml:space="preserve">
|
||||||
<value>Activation shortcut</value>
|
<value>Activation shortcut</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="SettingsWindow_AdminTitle" xml:space="preserve">
|
||||||
|
<value>Administrator: PowerToys Settings</value>
|
||||||
|
<comment>Title of the settings window when running as administrator</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
Reference in New Issue
Block a user