[EnvVar][Hosts][RegPrev]Decouple and refactor to make it "packable" as nuget package (#32604)
* WIP Hosts - remove deps * Add consumer app * Move App and MainWindow to Consumer app. Make Hosts dll * Try consume it * Fix errors * Make it work with custom build targets * Dependency injection Refactor Explicit page creation Wire missing dependencies * Fix installer * Remove unneeded stuff * Fix build again * Extract UI and logic from MainWindow to RegistryPreviewMainPage * Convert to lib Change namespace to RegistryPreviewUILib Remove PT deps * Add exe app and move App.xaml and MainWindow.xaml * Consume the lib * Update Hosts package creation * Fix RegistryPreview package creation * Rename RegistryPreviewUI back to RegistryPreview * Back to consuming lib * Ship icons and assets in nuget packages * Rename to EnvironmentVariablesUILib and convert to lib * Add app and consume * Telemetry * GPO * nuget * Rename HostsPackageConsumer to Hosts and Hosts lib to HostsUILib * Assets cleanup * nuget struct * v0 * assets * [Hosts] Re-add AppList to Lib Assets, [RegPrev] Copy lib assets to out dir * Sign UI dlls * Revert WinUIEx bump * Cleanup * Align deps * version exception dll * Fix RegistryPreview crashes * XAML format * XAML format 2 * Pack .pri files in lib/ dir --------- Co-authored-by: Darshak Bhatti <dabhatti@microsoft.com>
@ -96,6 +96,7 @@
|
|||||||
"PowerToys.SvgThumbnailProviderCpp.dll",
|
"PowerToys.SvgThumbnailProviderCpp.dll",
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.HostsModuleInterface.dll",
|
"WinUI3Apps\\PowerToys.HostsModuleInterface.dll",
|
||||||
|
"WinUI3Apps\\PowerToys.HostsUILib.dll",
|
||||||
"WinUI3Apps\\PowerToys.Hosts.dll",
|
"WinUI3Apps\\PowerToys.Hosts.dll",
|
||||||
"WinUI3Apps\\PowerToys.Hosts.exe",
|
"WinUI3Apps\\PowerToys.Hosts.exe",
|
||||||
|
|
||||||
@ -113,6 +114,7 @@
|
|||||||
"WinUI3Apps\\Powertoys.Peek.dll",
|
"WinUI3Apps\\Powertoys.Peek.dll",
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.EnvironmentVariablesModuleInterface.dll",
|
"WinUI3Apps\\PowerToys.EnvironmentVariablesModuleInterface.dll",
|
||||||
|
"WinUI3Apps\\PowerToys.EnvironmentVariablesUILib.dll",
|
||||||
"WinUI3Apps\\PowerToys.EnvironmentVariables.dll",
|
"WinUI3Apps\\PowerToys.EnvironmentVariables.dll",
|
||||||
"WinUI3Apps\\PowerToys.EnvironmentVariables.exe",
|
"WinUI3Apps\\PowerToys.EnvironmentVariables.exe",
|
||||||
|
|
||||||
@ -186,6 +188,7 @@
|
|||||||
"WinUI3Apps\\PowerRenameContextMenuPackage.msix",
|
"WinUI3Apps\\PowerRenameContextMenuPackage.msix",
|
||||||
|
|
||||||
"WinUI3Apps\\PowerToys.RegistryPreviewExt.dll",
|
"WinUI3Apps\\PowerToys.RegistryPreviewExt.dll",
|
||||||
|
"WinUI3Apps\\PowerToys.RegistryPreviewUILib.dll",
|
||||||
"WinUI3Apps\\PowerToys.RegistryPreview.dll",
|
"WinUI3Apps\\PowerToys.RegistryPreview.dll",
|
||||||
"WinUI3Apps\\PowerToys.RegistryPreview.exe",
|
"WinUI3Apps\\PowerToys.RegistryPreview.exe",
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ $versionExceptions = @(
|
|||||||
"Microsoft.Xaml.Interactivity.dll",
|
"Microsoft.Xaml.Interactivity.dll",
|
||||||
"hyjiacan.py4n.dll",
|
"hyjiacan.py4n.dll",
|
||||||
"Microsoft.WindowsAppRuntime.Release.Net.dll",
|
"Microsoft.WindowsAppRuntime.Release.Net.dll",
|
||||||
"Microsoft.Windows.Widgets.Projection.dll") -join '|';
|
"Microsoft.Windows.Widgets.Projection.dll",
|
||||||
|
"WinRT.Host.Shim.dll") -join '|';
|
||||||
$nullVersionExceptions = @(
|
$nullVersionExceptions = @(
|
||||||
"codicon.ttf",
|
"codicon.ttf",
|
||||||
"e_sqlite3.dll",
|
"e_sqlite3.dll",
|
||||||
|
@ -448,7 +448,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MeasureToolUI", "src\module
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerAccentKeyboardService", "src\modules\poweraccent\PowerAccentKeyboardService\PowerAccentKeyboardService.vcxproj", "{C97D9A5D-206C-454E-997E-009E227D7F02}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerAccentKeyboardService", "src\modules\poweraccent\PowerAccentKeyboardService\PowerAccentKeyboardService.vcxproj", "{C97D9A5D-206C-454E-997E-009E227D7F02}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts", "src\modules\Hosts\Hosts\Hosts.csproj", "{31D1C81D-765F-4446-AA62-E743F6325049}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostsUILib", "src\modules\Hosts\HostsUILib\HostsUILib.csproj", "{31D1C81D-765F-4446-AA62-E743F6325049}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosts", "Hosts", "{F05E590D-AD46-42BE-9C25-6A63ADD2E3EA}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Hosts", "Hosts", "{F05E590D-AD46-42BE-9C25-6A63ADD2E3EA}"
|
||||||
EndProject
|
EndProject
|
||||||
@ -518,7 +518,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PastePlainModuleInterface",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AllExperiments", "src\common\AllExperiments\AllExperiments.csproj", "{9CE59ED5-7087-4353-88EB-788038A73CEC}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AllExperiments", "src\common\AllExperiments\AllExperiments.csproj", "{9CE59ED5-7087-4353-88EB-788038A73CEC}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RegistryPreviewUI", "src\modules\registrypreview\RegistryPreviewUI\RegistryPreviewUI.csproj", "{FD86C06A-FB54-4D5E-9831-1CDADF60D45F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RegistryPreviewUILib", "src\modules\registrypreview\RegistryPreviewUILib\RegistryPreviewUILib.csproj", "{FD86C06A-FB54-4D5E-9831-1CDADF60D45F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RegistryPreviewExt", "src\modules\registrypreview\RegistryPreviewExt\RegistryPreviewExt.vcxproj", "{697C6AF9-0A48-49A9-866C-67DA12384015}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RegistryPreviewExt", "src\modules\registrypreview\RegistryPreviewExt\RegistryPreviewExt.vcxproj", "{697C6AF9-0A48-49A9-866C-67DA12384015}"
|
||||||
EndProject
|
EndProject
|
||||||
@ -546,7 +546,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests-FancyZonesEditor"
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EnvironmentVariables", "EnvironmentVariables", "{538ED0BB-B863-4B20-98CC-BCDF7FA0B68A}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EnvironmentVariables", "EnvironmentVariables", "{538ED0BB-B863-4B20-98CC-BCDF7FA0B68A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnvironmentVariables", "src\modules\EnvironmentVariables\EnvironmentVariables\EnvironmentVariables.csproj", "{51465DA1-C18B-4B99-93E1-ECF8E0FA0CBA}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnvironmentVariablesUILib", "src\modules\EnvironmentVariables\EnvironmentVariablesUILib\EnvironmentVariablesUILib.csproj", "{51465DA1-C18B-4B99-93E1-ECF8E0FA0CBA}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EnvironmentVariablesModuleInterface", "src\modules\EnvironmentVariables\EnvironmentVariablesModuleInterface\EnvironmentVariablesModuleInterface.vcxproj", "{B9420661-B0E4-4241-ABD4-4A27A1F64250}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EnvironmentVariablesModuleInterface", "src\modules\EnvironmentVariables\EnvironmentVariablesModuleInterface\EnvironmentVariablesModuleInterface.vcxproj", "{B9420661-B0E4-4241-ABD4-4A27A1F64250}"
|
||||||
EndProject
|
EndProject
|
||||||
@ -568,6 +568,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileLocksmithContextMenu",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileLocksmithLib", "src\modules\FileLocksmith\FileLocksmithLib\FileLocksmithLib.vcxproj", "{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileLocksmithLib", "src\modules\FileLocksmith\FileLocksmithLib\FileLocksmithLib.vcxproj", "{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hosts", "src\modules\Hosts\Hosts\Hosts.csproj", "{02DD46D3-F761-47D9-8894-2D6DA0124650}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RegistryPreview", "src\modules\registrypreview\RegistryPreview\RegistryPreview.csproj", "{8E23E173-7127-4A5F-9F93-3049F2B68047}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnvironmentVariables", "src\modules\EnvironmentVariables\EnvironmentVariables\EnvironmentVariables.csproj", "{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}"
|
||||||
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests-FancyZones", "src\modules\fancyzones\UITests-FancyZones\UITests-FancyZones.csproj", "{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests-FancyZones", "src\modules\fancyzones\UITests-FancyZones\UITests-FancyZones.csproj", "{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests-FancyZonesEditor", "src\modules\fancyzones\UITests-FancyZonesEditor\UITests-FancyZonesEditor.csproj", "{3A9A791E-94A9-49F8-8401-C11CE288D5FB}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests-FancyZonesEditor", "src\modules\fancyzones\UITests-FancyZonesEditor\UITests-FancyZonesEditor.csproj", "{3A9A791E-94A9-49F8-8401-C11CE288D5FB}"
|
||||||
@ -2507,6 +2513,42 @@ Global
|
|||||||
{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F}.Release|x64.Build.0 = Release|x64
|
{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F}.Release|x64.Build.0 = Release|x64
|
||||||
{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F}.Release|x86.ActiveCfg = Release|x64
|
{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F}.Release|x86.ActiveCfg = Release|x64
|
||||||
{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F}.Release|x86.Build.0 = Release|x64
|
{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F}.Release|x86.Build.0 = Release|x64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Debug|x86.ActiveCfg = Debug|x64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Debug|x86.Build.0 = Debug|x64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Release|ARM64.Build.0 = Release|ARM64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Release|x64.Build.0 = Release|x64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Release|x86.ActiveCfg = Release|x64
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650}.Release|x86.Build.0 = Release|x64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Debug|x86.ActiveCfg = Debug|x64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Debug|x86.Build.0 = Debug|x64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Release|ARM64.Build.0 = Release|ARM64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Release|x64.Build.0 = Release|x64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Release|x86.ActiveCfg = Release|x64
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047}.Release|x86.Build.0 = Release|x64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Debug|x86.ActiveCfg = Debug|x64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Debug|x86.Build.0 = Debug|x64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Release|ARM64.Build.0 = Release|ARM64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Release|x64.Build.0 = Release|x64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Release|x86.ActiveCfg = Release|x64
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8}.Release|x86.Build.0 = Release|x64
|
||||||
{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||||
{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}.Debug|ARM64.Build.0 = Debug|ARM64
|
{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||||
{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}.Debug|x64.ActiveCfg = Debug|x64
|
{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
@ -2764,6 +2806,9 @@ Global
|
|||||||
{0014D652-901F-4456-8D65-06FC5F997FB0} = {4C0D0746-BE5B-49EE-BD5D-A7811628AE8B}
|
{0014D652-901F-4456-8D65-06FC5F997FB0} = {4C0D0746-BE5B-49EE-BD5D-A7811628AE8B}
|
||||||
{799A50D8-DE89-4ED1-8FF8-AD5A9ED8C0CA} = {AB82E5DD-C32D-4F28-9746-2C780846188E}
|
{799A50D8-DE89-4ED1-8FF8-AD5A9ED8C0CA} = {AB82E5DD-C32D-4F28-9746-2C780846188E}
|
||||||
{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F} = {AB82E5DD-C32D-4F28-9746-2C780846188E}
|
{9D52FD25-EF90-4F9A-A015-91EFC5DAF54F} = {AB82E5DD-C32D-4F28-9746-2C780846188E}
|
||||||
|
{02DD46D3-F761-47D9-8894-2D6DA0124650} = {F05E590D-AD46-42BE-9C25-6A63ADD2E3EA}
|
||||||
|
{8E23E173-7127-4A5F-9F93-3049F2B68047} = {929C1324-22E8-4412-A9A8-80E85F3985A5}
|
||||||
|
{DFF88D16-D36F-40A4-A955-CDCAA76EF7B8} = {538ED0BB-B863-4B20-98CC-BCDF7FA0B68A}
|
||||||
{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD}
|
{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD}
|
||||||
{3A9A791E-94A9-49F8-8401-C11CE288D5FB} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD}
|
{3A9A791E-94A9-49F8-8401-C11CE288D5FB} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD}
|
||||||
{C0974915-8A1D-4BF0-977B-9587D3807AB7} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD}
|
{C0974915-8A1D-4BF0-977B-9587D3807AB7} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<clear />
|
<clear />
|
||||||
|
@ -262,7 +262,7 @@ inline registry::ChangeSet getRegistryPreviewChangeSet(const std::wstring instal
|
|||||||
changes.push_back({ scope, L"Software\\Classes\\regfile\\shell\\preview\\command", std::nullopt, command });
|
changes.push_back({ scope, L"Software\\Classes\\regfile\\shell\\preview\\command", std::nullopt, command });
|
||||||
|
|
||||||
std::wstring icon_path = installationDir;
|
std::wstring icon_path = installationDir;
|
||||||
icon_path.append(L"\\WinUI3Apps\\Assets\\RegistryPreview\\app.ico");
|
icon_path.append(L"\\WinUI3Apps\\Assets\\RegistryPreview\\RegistryPreview.ico");
|
||||||
changes.push_back({ scope, L"Software\\Classes\\regfile\\shell\\preview", L"icon", icon_path });
|
changes.push_back({ scope, L"Software\\Classes\\regfile\\shell\\preview", L"icon", icon_path });
|
||||||
|
|
||||||
return { changes };
|
return { changes };
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<Import Project="..\..\..\Version.props" />
|
<Import Project="..\..\..\Version.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net8.0-windows10.0.20348.0</TargetFramework>
|
<TargetFramework>net8.0-windows10.0.20348.0</TargetFramework>
|
||||||
@ -8,6 +7,7 @@
|
|||||||
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
|
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
|
||||||
<RootNamespace>EnvironmentVariables</RootNamespace>
|
<RootNamespace>EnvironmentVariables</RootNamespace>
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
|
<Platforms>x86;x64;ARM64</Platforms>
|
||||||
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
|
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
|
||||||
<UseWinUI>true</UseWinUI>
|
<UseWinUI>true</UseWinUI>
|
||||||
<EnableMsixTooling>true</EnableMsixTooling>
|
<EnableMsixTooling>true</EnableMsixTooling>
|
||||||
@ -16,21 +16,36 @@
|
|||||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||||
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
|
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
|
||||||
|
<SelfContained>true</SelfContained>
|
||||||
|
<DefineConstants>DISABLE_XAML_GENERATED_MAIN,TRACE</DefineConstants>
|
||||||
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps</OutputPath>
|
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps</OutputPath>
|
||||||
<AssemblyName>PowerToys.EnvironmentVariables</AssemblyName>
|
<AssemblyName>PowerToys.EnvironmentVariables</AssemblyName>
|
||||||
<DefineConstants>DISABLE_XAML_GENERATED_MAIN,TRACE</DefineConstants>
|
<ApplicationIcon>Assets\EnvironmentVariables\EnvironmentVariables.ico</ApplicationIcon>
|
||||||
<ApplicationIcon>Assets/EnvironmentVariables/EnvironmentVariables.ico</ApplicationIcon>
|
|
||||||
<SelfContained>true</SelfContained>
|
|
||||||
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
||||||
<ProjectPriFileName>PowerToys.EnvironmentVariables.pri</ProjectPriFileName>
|
<ProjectPriFileName>PowerToys.EnvironmentVariables.pri</ProjectPriFileName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Styles\**" />
|
<Page Remove="EnvironmentVariablesXAML\App.xaml" />
|
||||||
<EmbeddedResource Remove="Styles\**" />
|
|
||||||
<None Remove="Styles\**" />
|
|
||||||
<Page Remove="Styles\**" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ApplicationDefinition Include="EnvironmentVariablesXAML\App.xaml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="EnvironmentVariablesXAML\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="CopyPRIFileToOutputDir" AfterTargets="Build">
|
||||||
|
<Message Text="Executing CopyPRIFileToOutputDir task" Importance="High" />
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PRIFile Include="$(OutDir)**\PowerToys.EnvironmentVariablesUILib.pri" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Copy SourceFiles="@(PRIFile)" DestinationFolder="$(OutDir)" />
|
||||||
|
|
||||||
|
<Message Text="Copied CopyPRIFileToOutputDir files" Importance="High" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
<!-- SelfContained=true requires RuntimeIdentifier to be set -->
|
<!-- SelfContained=true requires RuntimeIdentifier to be set -->
|
||||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||||
@ -48,24 +63,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="EnvironmentVariablesXAML\Views\MainPage.xaml" />
|
<!-- HACK: Common.UI is referenced, even if it is not used, to force dll versions to be the same as in other projects that use it. It's still unclear why this is the case, but this is need for flattening the install directory. -->
|
||||||
</ItemGroup>
|
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||||
<ItemGroup>
|
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
|
||||||
<Page Remove="EnvironmentVariablesXAML\App.xaml" />
|
<ProjectReference Include="..\EnvironmentVariablesUILib\EnvironmentVariablesUILib.csproj" />
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ApplicationDefinition Include="EnvironmentVariablesXAML\App.xaml" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="Assets\EnvironmentVariables\SplashScreen.scale-200.png" />
|
|
||||||
<Content Include="Assets\EnvironmentVariables\LockScreenLogo.scale-200.png" />
|
|
||||||
<Content Include="Assets\EnvironmentVariables\Square150x150Logo.scale-200.png" />
|
|
||||||
<Content Include="Assets\EnvironmentVariables\Square44x44Logo.scale-200.png" />
|
|
||||||
<Content Include="Assets\EnvironmentVariables\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
|
||||||
<Content Include="Assets\EnvironmentVariables\StoreLogo.png" />
|
|
||||||
<Content Include="Assets\EnvironmentVariables\Wide310x150Logo.scale-200.png" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -73,23 +75,10 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
||||||
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
||||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" />
|
|
||||||
<PackageReference Include="CommunityToolkit.Mvvm" />
|
|
||||||
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" />
|
|
||||||
<PackageReference Include="CommunityToolkit.WinUI.Controls.Segmented" />
|
|
||||||
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" />
|
|
||||||
<PackageReference Include="CommunityToolkit.WinUI.Converters" />
|
|
||||||
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" />
|
|
||||||
<PackageReference Include="WinUIEx" />
|
<PackageReference Include="WinUIEx" />
|
||||||
<Manifest Include="$(ApplicationManifest)" />
|
<Manifest Include="$(ApplicationManifest)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<!-- HACK: Common.UI is referenced, even if it is not used, to force dll versions to be the same as in other projects that use it. It's still unclear why this is the case, but this is need for flattening the install directory. -->
|
|
||||||
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
|
|
||||||
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
|
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
|
||||||
Tools extension to be activated for this project even if the Windows App SDK Nuget
|
Tools extension to be activated for this project even if the Windows App SDK Nuget
|
||||||
@ -98,12 +87,13 @@
|
|||||||
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||||
<ProjectCapability Include="Msix" />
|
<ProjectCapability Include="Msix" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Page Update="EnvironmentVariablesXAML\Views\MainPage.xaml">
|
<!--
|
||||||
<Generator>MSBuild:Compile</Generator>
|
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
|
||||||
</Page>
|
Explorer "Package and Publish" context menu entry to be enabled for this project even if
|
||||||
</ItemGroup>
|
the Windows App SDK Nuget package has not yet been restored.
|
||||||
<ItemGroup>
|
-->
|
||||||
<PRIResource Remove="Styles\**" />
|
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||||
</ItemGroup>
|
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
|
||||||
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<Application
|
<Application
|
||||||
x:Class="EnvironmentVariables.App"
|
x:Class="EnvironmentVariables.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
@ -7,161 +7,9 @@
|
|||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<ResourceDictionary Source="/EnvironmentVariablesXAML/Styles/TextBlock.xaml" />
|
|
||||||
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
||||||
<!-- Other merged dictionaries here -->
|
<!-- Other merged dictionaries here -->
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
<ResourceDictionary.ThemeDictionaries>
|
|
||||||
<ResourceDictionary x:Key="Default">
|
|
||||||
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SubtleFillColorTertiary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SubtleFillColorTertiary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="TextFillColorPrimary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="TextFillColorPrimary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="TextFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="TextFillColorDisabled" />
|
|
||||||
</ResourceDictionary>
|
|
||||||
|
|
||||||
<ResourceDictionary x:Key="Light">
|
|
||||||
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SubtleFillColorTertiary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SubtleFillColorTertiary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="TextFillColorPrimary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="TextFillColorPrimary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="TextFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="TextFillColorDisabled" />
|
|
||||||
</ResourceDictionary>
|
|
||||||
|
|
||||||
<ResourceDictionary x:Key="HighContrast">
|
|
||||||
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SystemColorWindowColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SystemColorHighlightTextColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SystemColorWindowColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SystemControlBackgroundBaseLowBrush" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SystemColorWindowColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SystemColorHighlightColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SystemColorHighlightColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SystemColorGrayTextColor" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="SystemColorButtonTextColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="SystemControlHighlightBaseHighBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="SystemControlHighlightBaseHighBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
|
|
||||||
</ResourceDictionary>
|
|
||||||
|
|
||||||
</ResourceDictionary.ThemeDictionaries>
|
|
||||||
|
|
||||||
<Style x:Key="SubtleButtonStyle" TargetType="Button">
|
|
||||||
<Setter Property="Background" Value="{ThemeResource SubtleButtonBackground}" />
|
|
||||||
<Setter Property="BackgroundSizing" Value="InnerBorderEdge" />
|
|
||||||
<Setter Property="Foreground" Value="{ThemeResource SubtleButtonForeground}" />
|
|
||||||
<Setter Property="BorderBrush" Value="{ThemeResource SubtleButtonBorderBrush}" />
|
|
||||||
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}" />
|
|
||||||
<Setter Property="Padding" Value="{StaticResource ButtonPadding}" />
|
|
||||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
|
||||||
<Setter Property="VerticalAlignment" Value="Center" />
|
|
||||||
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
|
|
||||||
<Setter Property="FontWeight" Value="Normal" />
|
|
||||||
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
|
|
||||||
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
|
|
||||||
<Setter Property="FocusVisualMargin" Value="-3" />
|
|
||||||
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="Button">
|
|
||||||
<ContentPresenter
|
|
||||||
x:Name="ContentPresenter"
|
|
||||||
Padding="{TemplateBinding Padding}"
|
|
||||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
|
||||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
|
||||||
AnimatedIcon.State="Normal"
|
|
||||||
AutomationProperties.AccessibilityView="Raw"
|
|
||||||
Background="{TemplateBinding Background}"
|
|
||||||
BackgroundSizing="{TemplateBinding BackgroundSizing}"
|
|
||||||
BorderBrush="{TemplateBinding BorderBrush}"
|
|
||||||
BorderThickness="{TemplateBinding BorderThickness}"
|
|
||||||
Content="{TemplateBinding Content}"
|
|
||||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
|
||||||
ContentTransitions="{TemplateBinding ContentTransitions}"
|
|
||||||
CornerRadius="{TemplateBinding CornerRadius}"
|
|
||||||
Foreground="{TemplateBinding Foreground}">
|
|
||||||
<ContentPresenter.BackgroundTransition>
|
|
||||||
<BrushTransition Duration="0:0:0.083" />
|
|
||||||
</ContentPresenter.BackgroundTransition>
|
|
||||||
<VisualStateManager.VisualStateGroups>
|
|
||||||
<VisualStateGroup x:Name="CommonStates">
|
|
||||||
<VisualState x:Name="Normal" />
|
|
||||||
<VisualState x:Name="PointerOver">
|
|
||||||
<Storyboard>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundPointerOver}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushPointerOver}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundPointerOver}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
</Storyboard>
|
|
||||||
<VisualState.Setters>
|
|
||||||
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="PointerOver" />
|
|
||||||
</VisualState.Setters>
|
|
||||||
</VisualState>
|
|
||||||
<VisualState x:Name="Pressed">
|
|
||||||
<Storyboard>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundPressed}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushPressed}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundPressed}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
</Storyboard>
|
|
||||||
<VisualState.Setters>
|
|
||||||
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="Pressed" />
|
|
||||||
</VisualState.Setters>
|
|
||||||
</VisualState>
|
|
||||||
<VisualState x:Name="Disabled">
|
|
||||||
<Storyboard>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundDisabled}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushDisabled}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundDisabled}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
</Storyboard>
|
|
||||||
<VisualState.Setters>
|
|
||||||
<!-- DisabledVisual Should be handled by the control, not the animated icon. -->
|
|
||||||
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="Normal" />
|
|
||||||
</VisualState.Setters>
|
|
||||||
</VisualState>
|
|
||||||
</VisualStateGroup>
|
|
||||||
</VisualStateManager.VisualStateGroups>
|
|
||||||
</ContentPresenter>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
||||||
|
@ -4,8 +4,11 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariables.Telemetry;
|
||||||
using EnvironmentVariables.ViewModels;
|
using EnvironmentVariablesUILib;
|
||||||
|
using EnvironmentVariablesUILib.Helpers;
|
||||||
|
using EnvironmentVariablesUILib.Telemetry;
|
||||||
|
using EnvironmentVariablesUILib.ViewModels;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
@ -47,8 +50,11 @@ namespace EnvironmentVariables
|
|||||||
services.AddSingleton<IFileSystem, FileSystem>();
|
services.AddSingleton<IFileSystem, FileSystem>();
|
||||||
services.AddSingleton<IElevationHelper, ElevationHelper>();
|
services.AddSingleton<IElevationHelper, ElevationHelper>();
|
||||||
services.AddSingleton<IEnvironmentVariablesService, EnvironmentVariablesService>();
|
services.AddSingleton<IEnvironmentVariablesService, EnvironmentVariablesService>();
|
||||||
|
services.AddSingleton<ILogger, LoggerWrapper>();
|
||||||
|
services.AddSingleton<ITelemetry, TelemetryWrapper>();
|
||||||
|
|
||||||
services.AddSingleton<MainViewModel>();
|
services.AddSingleton<MainViewModel>();
|
||||||
|
services.AddSingleton<EnvironmentVariablesMainPage>();
|
||||||
}).Build();
|
}).Build();
|
||||||
|
|
||||||
UnhandledException += App_UnhandledException;
|
UnhandledException += App_UnhandledException;
|
||||||
@ -85,8 +91,7 @@ namespace EnvironmentVariables
|
|||||||
Logger.LogInfo($"EnvironmentVariables started detached from PowerToys Runner.");
|
Logger.LogInfo($"EnvironmentVariables started detached from PowerToys Runner.");
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerToysTelemetry.Log.WriteEvent(new EnvironmentVariables.Telemetry.EnvironmentVariablesOpenedEvent());
|
PowerToysTelemetry.Log.WriteEvent(new Telemetry.EnvironmentVariablesOpenedEvent());
|
||||||
|
|
||||||
window = new MainWindow();
|
window = new MainWindow();
|
||||||
window.Activate();
|
window.Activate();
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="using:EnvironmentVariables"
|
xmlns:local="using:EnvironmentVariables"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:views="using:EnvironmentVariables.Views"
|
|
||||||
xmlns:winuiex="using:WinUIEx"
|
xmlns:winuiex="using:WinUIEx"
|
||||||
x:Uid="Window"
|
x:Uid="Window"
|
||||||
MinWidth="700"
|
MinWidth="700"
|
||||||
@ -15,7 +14,7 @@
|
|||||||
<Window.SystemBackdrop>
|
<Window.SystemBackdrop>
|
||||||
<MicaBackdrop />
|
<MicaBackdrop />
|
||||||
</Window.SystemBackdrop>
|
</Window.SystemBackdrop>
|
||||||
<Grid>
|
<Grid x:Name="MainGrid" Loaded="Grid_Loaded">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
@ -42,6 +41,5 @@
|
|||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Style="{StaticResource CaptionTextBlockStyle}" />
|
Style="{StaticResource CaptionTextBlockStyle}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
<views:MainPage Grid.Row="1" />
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</winuiex:WindowEx>
|
</winuiex:WindowEx>
|
||||||
|
@ -4,11 +4,14 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariables.Win32;
|
||||||
using EnvironmentVariables.Helpers.Win32;
|
using EnvironmentVariablesUILib;
|
||||||
using EnvironmentVariables.ViewModels;
|
using EnvironmentVariablesUILib.Helpers;
|
||||||
|
using EnvironmentVariablesUILib.ViewModels;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Microsoft.UI.Dispatching;
|
using Microsoft.UI.Dispatching;
|
||||||
|
using Microsoft.UI.Xaml;
|
||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using WinUIEx;
|
using WinUIEx;
|
||||||
|
|
||||||
namespace EnvironmentVariables
|
namespace EnvironmentVariables
|
||||||
@ -18,6 +21,8 @@ namespace EnvironmentVariables
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class MainWindow : WindowEx
|
public sealed partial class MainWindow : WindowEx
|
||||||
{
|
{
|
||||||
|
private EnvironmentVariablesMainPage MainPage { get; }
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
@ -35,6 +40,14 @@ namespace EnvironmentVariables
|
|||||||
RegisterWindow(handle);
|
RegisterWindow(handle);
|
||||||
|
|
||||||
WindowHelpers.BringToForeground(handle);
|
WindowHelpers.BringToForeground(handle);
|
||||||
|
|
||||||
|
MainPage = App.GetService<EnvironmentVariablesMainPage>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Grid_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
MainGrid.Children.Add(MainPage);
|
||||||
|
Grid.SetRow(MainPage, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
private static readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||||
@ -61,7 +74,7 @@ namespace EnvironmentVariables
|
|||||||
if (wParam != (IntPtr)0x12345)
|
if (wParam != (IntPtr)0x12345)
|
||||||
{
|
{
|
||||||
var viewModel = App.GetService<MainViewModel>();
|
var viewModel = App.GetService<MainViewModel>();
|
||||||
viewModel.EnvironmentState = Models.EnvironmentState.EnvironmentMessageReceived;
|
viewModel.EnvironmentState = EnvironmentVariablesUILib.Models.EnvironmentState.EnvironmentMessageReceived;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
|
||||||
|
|
||||||
<x:Double x:Key="SecondaryTextFontSize">12</x:Double>
|
|
||||||
<Style x:Key="SecondaryTextStyle" TargetType="TextBlock">
|
|
||||||
<Setter Property="FontSize" Value="{StaticResource SecondaryTextFontSize}" />
|
|
||||||
<Setter Property="Foreground" Value="{ThemeResource TextFillColorSecondaryBrush}" />
|
|
||||||
</Style>
|
|
||||||
</ResourceDictionary>
|
|
@ -0,0 +1,43 @@
|
|||||||
|
// 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 EnvironmentVariablesUILib.Helpers;
|
||||||
|
using ManagedCommon;
|
||||||
|
|
||||||
|
namespace EnvironmentVariables
|
||||||
|
{
|
||||||
|
internal sealed class LoggerWrapper : ILogger
|
||||||
|
{
|
||||||
|
public void LogDebug(string message)
|
||||||
|
{
|
||||||
|
Logger.LogDebug(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogError(string message)
|
||||||
|
{
|
||||||
|
Logger.LogError(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogError(string message, Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(message, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogInfo(string message)
|
||||||
|
{
|
||||||
|
Logger.LogInfo(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogTrace()
|
||||||
|
{
|
||||||
|
Logger.LogTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogWarning(string message)
|
||||||
|
{
|
||||||
|
Logger.LogWarning(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Helpers.Win32
|
namespace EnvironmentVariables.Win32
|
||||||
{
|
{
|
||||||
public static class NativeMethods
|
public static class NativeMethods
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Diagnostics.Tracing;
|
using System.Diagnostics.Tracing;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
using Microsoft.PowerToys.Telemetry;
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using Microsoft.PowerToys.Telemetry.Events;
|
using Microsoft.PowerToys.Telemetry.Events;
|
||||||
|
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
// 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 EnvironmentVariablesUILib.Models;
|
||||||
|
using EnvironmentVariablesUILib.Telemetry;
|
||||||
|
using Microsoft.PowerToys.Telemetry;
|
||||||
|
|
||||||
|
namespace EnvironmentVariables.Telemetry
|
||||||
|
{
|
||||||
|
internal sealed class TelemetryWrapper : ITelemetry
|
||||||
|
{
|
||||||
|
public void LogEnvironmentVariablesProfileEnabledEvent(bool enabled)
|
||||||
|
{
|
||||||
|
var telemetryEnabled = new EnvironmentVariablesProfileEnabledEvent()
|
||||||
|
{
|
||||||
|
Enabled = enabled,
|
||||||
|
};
|
||||||
|
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(telemetryEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogEnvironmentVariablesVariableChangedEvent(VariablesSetType type)
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new Telemetry.EnvironmentVariablesVariableChangedEvent(type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,12 +4,9 @@
|
|||||||
|
|
||||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
<application>
|
<application>
|
||||||
<!--The ID below informs the system that this application is compatible with OS features first introduced in Windows 8.
|
<!-- The ID below informs the system that this application is compatible with OS features first introduced in Windows 10.
|
||||||
For more info see https://docs.microsoft.com/windows/win32/sysinfo/targeting-your-application-at-windows-8-1
|
It is necessary to support features in unpackaged applications, for example the custom titlebar implementation.
|
||||||
|
For more info see https://docs.microsoft.com/windows/apps/windows-app-sdk/use-windows-app-sdk-run-time#declare-os-compatibility-in-your-application-manifest -->
|
||||||
It is also necessary to support features in unpackaged applications, for example the custom title bar implementation.-->
|
|
||||||
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
|
|
||||||
<!-- Windows 10 -->
|
|
||||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||||
</application>
|
</application>
|
||||||
</compatibility>
|
</compatibility>
|
||||||
|
After Width: | Height: | Size: 460 KiB |
Before Width: | Height: | Size: 432 B After Width: | Height: | Size: 432 B |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 432 B After Width: | Height: | Size: 432 B |
@ -3,10 +3,10 @@
|
|||||||
// 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 System;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
using Microsoft.UI.Xaml.Data;
|
using Microsoft.UI.Xaml.Data;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Converters;
|
namespace EnvironmentVariablesUILib.Converters;
|
||||||
|
|
||||||
public class EnvironmentStateToBoolConverter : IValueConverter
|
public class EnvironmentStateToBoolConverter : IValueConverter
|
||||||
{
|
{
|
@ -3,11 +3,11 @@
|
|||||||
// 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 System;
|
||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariablesUILib.Helpers;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
using Microsoft.UI.Xaml.Data;
|
using Microsoft.UI.Xaml.Data;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Converters;
|
namespace EnvironmentVariablesUILib.Converters;
|
||||||
|
|
||||||
public class EnvironmentStateToMessageConverter : IValueConverter
|
public class EnvironmentStateToMessageConverter : IValueConverter
|
||||||
{
|
{
|
@ -3,11 +3,11 @@
|
|||||||
// 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 System;
|
||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariablesUILib.Helpers;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
using Microsoft.UI.Xaml.Data;
|
using Microsoft.UI.Xaml.Data;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Converters;
|
namespace EnvironmentVariablesUILib.Converters;
|
||||||
|
|
||||||
public class EnvironmentStateToTitleConverter : IValueConverter
|
public class EnvironmentStateToTitleConverter : IValueConverter
|
||||||
{
|
{
|
@ -3,11 +3,11 @@
|
|||||||
// 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 System;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Data;
|
using Microsoft.UI.Xaml.Data;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Converters;
|
namespace EnvironmentVariablesUILib.Converters;
|
||||||
|
|
||||||
public class EnvironmentStateToVisibilityConverter : IValueConverter
|
public class EnvironmentStateToVisibilityConverter : IValueConverter
|
||||||
{
|
{
|
@ -3,10 +3,10 @@
|
|||||||
// 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 System;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
using Microsoft.UI.Xaml.Data;
|
using Microsoft.UI.Xaml.Data;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Converters;
|
namespace EnvironmentVariablesUILib.Converters;
|
||||||
|
|
||||||
public class VariableTypeToGlyphConverter : IValueConverter
|
public class VariableTypeToGlyphConverter : IValueConverter
|
||||||
{
|
{
|
@ -1,13 +1,13 @@
|
|||||||
<Page
|
<Page
|
||||||
x:Class="EnvironmentVariables.Views.MainPage"
|
x:Class="EnvironmentVariablesUILib.EnvironmentVariablesMainPage"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:converters="using:EnvironmentVariables.Converters"
|
xmlns:converters="using:EnvironmentVariablesUILib.Converters"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:i="using:Microsoft.Xaml.Interactivity"
|
xmlns:i="using:Microsoft.Xaml.Interactivity"
|
||||||
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
|
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:models="using:EnvironmentVariables.Models"
|
xmlns:models="using:EnvironmentVariablesUILib.Models"
|
||||||
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
|
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
|
||||||
xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
|
xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
|
||||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||||
@ -21,6 +21,163 @@
|
|||||||
<ResourceDictionary Source="ms-appx:///CommunityToolkit.WinUI.Controls.SettingsControls/SettingsExpander/SettingsExpander.xaml" />
|
<ResourceDictionary Source="ms-appx:///CommunityToolkit.WinUI.Controls.SettingsControls/SettingsExpander/SettingsExpander.xaml" />
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
|
<ResourceDictionary.ThemeDictionaries>
|
||||||
|
<ResourceDictionary x:Key="Default">
|
||||||
|
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SubtleFillColorTertiary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SubtleFillColorTertiary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="TextFillColorPrimary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="TextFillColorPrimary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="TextFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="TextFillColorDisabled" />
|
||||||
|
</ResourceDictionary>
|
||||||
|
|
||||||
|
<ResourceDictionary x:Key="Light">
|
||||||
|
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SubtleFillColorTertiary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SubtleFillColorTertiary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="TextFillColorPrimary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="TextFillColorPrimary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="TextFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="TextFillColorDisabled" />
|
||||||
|
</ResourceDictionary>
|
||||||
|
|
||||||
|
<ResourceDictionary x:Key="HighContrast">
|
||||||
|
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SystemColorWindowColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SystemColorHighlightTextColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SystemColorWindowColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SystemControlBackgroundBaseLowBrush" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SystemColorWindowColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SystemColorHighlightColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SystemColorHighlightColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SystemColorGrayTextColor" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="SystemColorButtonTextColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="SystemControlHighlightBaseHighBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="SystemControlHighlightBaseHighBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
|
||||||
|
</ResourceDictionary>
|
||||||
|
|
||||||
|
</ResourceDictionary.ThemeDictionaries>
|
||||||
|
|
||||||
|
<Style x:Key="SubtleButtonStyle" TargetType="Button">
|
||||||
|
<Setter Property="Background" Value="{ThemeResource SubtleButtonBackground}" />
|
||||||
|
<Setter Property="BackgroundSizing" Value="InnerBorderEdge" />
|
||||||
|
<Setter Property="Foreground" Value="{ThemeResource SubtleButtonForeground}" />
|
||||||
|
<Setter Property="BorderBrush" Value="{ThemeResource SubtleButtonBorderBrush}" />
|
||||||
|
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}" />
|
||||||
|
<Setter Property="Padding" Value="{StaticResource ButtonPadding}" />
|
||||||
|
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||||
|
<Setter Property="VerticalAlignment" Value="Center" />
|
||||||
|
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
|
||||||
|
<Setter Property="FontWeight" Value="Normal" />
|
||||||
|
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
|
||||||
|
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
|
||||||
|
<Setter Property="FocusVisualMargin" Value="-3" />
|
||||||
|
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<ContentPresenter
|
||||||
|
x:Name="ContentPresenter"
|
||||||
|
Padding="{TemplateBinding Padding}"
|
||||||
|
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||||
|
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
|
AnimatedIcon.State="Normal"
|
||||||
|
AutomationProperties.AccessibilityView="Raw"
|
||||||
|
Background="{TemplateBinding Background}"
|
||||||
|
BackgroundSizing="{TemplateBinding BackgroundSizing}"
|
||||||
|
BorderBrush="{TemplateBinding BorderBrush}"
|
||||||
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
|
Content="{TemplateBinding Content}"
|
||||||
|
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||||
|
ContentTransitions="{TemplateBinding ContentTransitions}"
|
||||||
|
CornerRadius="{TemplateBinding CornerRadius}"
|
||||||
|
Foreground="{TemplateBinding Foreground}">
|
||||||
|
<ContentPresenter.BackgroundTransition>
|
||||||
|
<BrushTransition Duration="0:0:0.083" />
|
||||||
|
</ContentPresenter.BackgroundTransition>
|
||||||
|
<VisualStateManager.VisualStateGroups>
|
||||||
|
<VisualStateGroup x:Name="CommonStates">
|
||||||
|
<VisualState x:Name="Normal" />
|
||||||
|
<VisualState x:Name="PointerOver">
|
||||||
|
<Storyboard>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundPointerOver}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushPointerOver}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundPointerOver}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
</Storyboard>
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="PointerOver" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
<VisualState x:Name="Pressed">
|
||||||
|
<Storyboard>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundPressed}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushPressed}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundPressed}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
</Storyboard>
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="Pressed" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
<VisualState x:Name="Disabled">
|
||||||
|
<Storyboard>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundDisabled}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushDisabled}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundDisabled}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
</Storyboard>
|
||||||
|
<VisualState.Setters>
|
||||||
|
<!-- DisabledVisual Should be handled by the control, not the animated icon. -->
|
||||||
|
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="Normal" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
</VisualStateGroup>
|
||||||
|
</VisualStateManager.VisualStateGroups>
|
||||||
|
</ContentPresenter>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<x:Double x:Key="SecondaryTextFontSize">12</x:Double>
|
||||||
|
<Style x:Key="SecondaryTextStyle" TargetType="TextBlock">
|
||||||
|
<Setter Property="FontSize" Value="{StaticResource SecondaryTextFontSize}" />
|
||||||
|
<Setter Property="Foreground" Value="{ThemeResource TextFillColorSecondaryBrush}" />
|
||||||
|
</Style>
|
||||||
|
|
||||||
<DataTemplate x:Key="VariableTemplate" x:DataType="models:Variable">
|
<DataTemplate x:Key="VariableTemplate" x:DataType="models:Variable">
|
||||||
<tkcontrols:SettingsCard
|
<tkcontrols:SettingsCard
|
||||||
CommandParameter="{x:Bind (models:Variable)}"
|
CommandParameter="{x:Bind (models:Variable)}"
|
||||||
@ -106,11 +263,6 @@
|
|||||||
<tkconverters:BoolNegationConverter x:Key="BoolNegationConverter" />
|
<tkconverters:BoolNegationConverter x:Key="BoolNegationConverter" />
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
<i:Interaction.Behaviors>
|
|
||||||
<ic:EventTriggerBehavior EventName="Loaded">
|
|
||||||
<ic:InvokeCommandAction Command="{x:Bind ViewModel.LoadEnvironmentVariablesCommand}" />
|
|
||||||
</ic:EventTriggerBehavior>
|
|
||||||
</i:Interaction.Behaviors>
|
|
||||||
|
|
||||||
|
|
||||||
<Grid Margin="16" RowSpacing="8">
|
<Grid Margin="16" RowSpacing="8">
|
@ -3,19 +3,17 @@
|
|||||||
// 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 System;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
using EnvironmentVariables.ViewModels;
|
using EnvironmentVariablesUILib.ViewModels;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Windows.Foundation.Collections;
|
|
||||||
|
|
||||||
namespace EnvironmentVariables.Views
|
namespace EnvironmentVariablesUILib
|
||||||
{
|
{
|
||||||
public sealed partial class MainPage : Page
|
public sealed partial class EnvironmentVariablesMainPage : Page
|
||||||
{
|
{
|
||||||
private sealed class RelayCommandParameter
|
private sealed class RelayCommandParameter
|
||||||
{
|
{
|
||||||
@ -46,11 +44,13 @@ namespace EnvironmentVariables.Views
|
|||||||
|
|
||||||
public ICommand AddDefaultVariableCommand => new RelayCommand<DefaultVariablesSet>(AddDefaultVariable);
|
public ICommand AddDefaultVariableCommand => new RelayCommand<DefaultVariablesSet>(AddDefaultVariable);
|
||||||
|
|
||||||
public MainPage()
|
public EnvironmentVariablesMainPage(MainViewModel viewModel)
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
ViewModel = App.GetService<MainViewModel>();
|
ViewModel = viewModel;
|
||||||
DataContext = ViewModel;
|
DataContext = ViewModel;
|
||||||
|
|
||||||
|
ViewModel.LoadEnvironmentVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ShowEditDialogAsync(Variable variable, VariablesSet parentSet)
|
private async Task ShowEditDialogAsync(Variable variable, VariablesSet parentSet)
|
@ -0,0 +1,68 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<Import Condition="exists('..\..\..\Version.props')" Project="..\..\..\Version.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows10.0.20348</TargetFramework>
|
||||||
|
<RootNamespace>EnvironmentVariablesUILib</RootNamespace>
|
||||||
|
<UseWinUI>true</UseWinUI>
|
||||||
|
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
|
||||||
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
|
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||||
|
<AssemblyName>PowerToys.EnvironmentVariablesUILib</AssemblyName>
|
||||||
|
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
||||||
|
<ProjectPriFileName>PowerToys.EnvironmentVariablesUILib.pri</ProjectPriFileName>
|
||||||
|
<GenerateLibraryLayout>true</GenerateLibraryLayout>
|
||||||
|
<IsPackable>true</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="$(OutDir)\PowerToys.EnvironmentVariablesUILib.pri" Pack="True" PackageCopyToOutput="true" PackagePath="lib/$(TargetFramework)" />
|
||||||
|
<None Include="$(OutDir)\PowerToys.EnvironmentVariablesUILib.pri" Pack="True" PackageCopyToOutput="True" PackagePath="contentFiles\any\$(TargetFramework)" />
|
||||||
|
<XBFFile Include="$(OutDir)**\*.xbf" />
|
||||||
|
<None Include="@(XBFFile)" Pack="True" PackageCopyToOutput="True" PackagePath="contentFiles\any\$(TargetFramework)" />
|
||||||
|
<None Include="$(OutDir)\PowerToys.EnvironmentVariablesUILib.pdb" Pack="True" PackageCopyToOutput="true" PackagePath="lib/$(TargetFramework)" />
|
||||||
|
|
||||||
|
<None Include="Assets\**\*.png" Pack="true" PackageCopyToOutput="true" PackagePath="contentFiles\any\$(TargetFramework)\Assets"/>
|
||||||
|
<None Include="Assets\**\*.ico" Pack="true" PackageCopyToOutput="true" PackagePath="contentFiles\any\$(TargetFramework)\Assets"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Remove="Assets\**\*.png" Pack="false" />
|
||||||
|
<Content Remove="Assets\**\*.ico" Pack="false" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Windows.CsWinRT" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
||||||
|
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
||||||
|
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
||||||
|
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" />
|
||||||
|
<PackageReference Include="CommunityToolkit.Mvvm" />
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" />
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.Controls.Segmented" />
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" />
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.Converters" />
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" />
|
||||||
|
<PackageReference Include="System.IO.Abstractions" />
|
||||||
|
<PackageReference Include="WinUIEx" />
|
||||||
|
<Manifest Include="$(ApplicationManifest)" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Helpers
|
namespace EnvironmentVariablesUILib.Helpers
|
||||||
{
|
{
|
||||||
public class ElevationHelper : IElevationHelper
|
public class ElevationHelper : IElevationHelper
|
||||||
{
|
{
|
||||||
@ -16,5 +16,7 @@ namespace EnvironmentVariables.Helpers
|
|||||||
{
|
{
|
||||||
_isElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
_isElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IElevationHelper ElevationHelperInstance { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,12 +5,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using EnvironmentVariables.Helpers.Win32;
|
using EnvironmentVariablesUILib.Helpers.Win32;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
using ManagedCommon;
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Helpers
|
namespace EnvironmentVariablesUILib.Helpers
|
||||||
{
|
{
|
||||||
internal sealed class EnvironmentVariablesHelper
|
internal sealed class EnvironmentVariablesHelper
|
||||||
{
|
{
|
||||||
@ -73,7 +72,7 @@ namespace EnvironmentVariables.Helpers
|
|||||||
const int MaxUserEnvVariableLength = 255; // User-wide env vars stored in the registry have names limited to 255 chars
|
const int MaxUserEnvVariableLength = 255; // User-wide env vars stored in the registry have names limited to 255 chars
|
||||||
if (!fromMachine && variable.Length >= MaxUserEnvVariableLength)
|
if (!fromMachine && variable.Length >= MaxUserEnvVariableLength)
|
||||||
{
|
{
|
||||||
Logger.LogError("Can't apply variable - name too long.");
|
LoggerInstance.Logger.LogError("Can't apply variable - name too long.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -8,11 +8,11 @@ using System.IO;
|
|||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Helpers
|
namespace EnvironmentVariablesUILib.Helpers
|
||||||
{
|
{
|
||||||
internal sealed class EnvironmentVariablesService : IEnvironmentVariablesService
|
public sealed class EnvironmentVariablesService : IEnvironmentVariablesService
|
||||||
{
|
{
|
||||||
private const string ProfilesJsonFileSubPath = "Microsoft\\PowerToys\\EnvironmentVariables\\";
|
private const string ProfilesJsonFileSubPath = "Microsoft\\PowerToys\\EnvironmentVariables\\";
|
||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
namespace EnvironmentVariables.Helpers
|
namespace EnvironmentVariablesUILib.Helpers
|
||||||
{
|
{
|
||||||
public interface IElevationHelper
|
public interface IElevationHelper
|
||||||
{
|
{
|
@ -5,9 +5,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Models;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Helpers
|
namespace EnvironmentVariablesUILib.Helpers
|
||||||
{
|
{
|
||||||
public interface IEnvironmentVariablesService : IDisposable
|
public interface IEnvironmentVariablesService : IDisposable
|
||||||
{
|
{
|
@ -0,0 +1,23 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace EnvironmentVariablesUILib.Helpers
|
||||||
|
{
|
||||||
|
public interface ILogger
|
||||||
|
{
|
||||||
|
public void LogError(string message);
|
||||||
|
|
||||||
|
public void LogError(string message, Exception ex);
|
||||||
|
|
||||||
|
public void LogWarning(string message);
|
||||||
|
|
||||||
|
public void LogInfo(string message);
|
||||||
|
|
||||||
|
public void LogDebug(string message);
|
||||||
|
|
||||||
|
public void LogTrace();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
// 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.
|
||||||
|
namespace EnvironmentVariablesUILib.Helpers
|
||||||
|
{
|
||||||
|
public static class LoggerInstance
|
||||||
|
{
|
||||||
|
public static ILogger Logger { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
// 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.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace EnvironmentVariablesUILib.Helpers.Win32
|
||||||
|
{
|
||||||
|
public static class NativeMethods
|
||||||
|
{
|
||||||
|
internal const int HWND_BROADCAST = 0xffff;
|
||||||
|
|
||||||
|
internal delegate IntPtr WinProc(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||||
|
internal static extern int SendNotifyMessage(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
[DllImport("User32.dll")]
|
||||||
|
internal static extern int GetDpiForWindow(IntPtr hwnd);
|
||||||
|
|
||||||
|
[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
|
||||||
|
internal static extern int SetWindowLong32(IntPtr hWnd, WindowLongIndexFlags nIndex, WinProc newProc);
|
||||||
|
|
||||||
|
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
|
||||||
|
internal static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, WindowLongIndexFlags nIndex, WinProc newProc);
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
internal static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
internal enum WindowLongIndexFlags : int
|
||||||
|
{
|
||||||
|
GWL_WNDPROC = -4,
|
||||||
|
}
|
||||||
|
|
||||||
|
internal enum WindowMessage : int
|
||||||
|
{
|
||||||
|
WM_SETTINGSCHANGED = 0x001A,
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static IntPtr SetWindowLongPtr(IntPtr hWnd, WindowLongIndexFlags nIndex, WinProc newProc)
|
||||||
|
{
|
||||||
|
if (IntPtr.Size == 8)
|
||||||
|
{
|
||||||
|
return SetWindowLongPtr64(hWnd, nIndex, newProc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new IntPtr(SetWindowLong32(hWnd, nIndex, newProc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,15 +3,15 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
using Microsoft.Windows.ApplicationModel.Resources;
|
using Microsoft.Windows.ApplicationModel.Resources;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Helpers
|
namespace EnvironmentVariablesUILib.Helpers
|
||||||
{
|
{
|
||||||
internal static class ResourceLoaderInstance
|
public static class ResourceLoaderInstance
|
||||||
{
|
{
|
||||||
internal static ResourceLoader ResourceLoader { get; private set; }
|
public static ResourceLoader ResourceLoader { get; private set; }
|
||||||
|
|
||||||
static ResourceLoaderInstance()
|
static ResourceLoaderInstance()
|
||||||
{
|
{
|
||||||
ResourceLoader = new ResourceLoader("PowerToys.EnvironmentVariables.pri");
|
ResourceLoader = new ResourceLoader("PowerToys.EnvironmentVariablesUILib.pri", "PowerToys.EnvironmentVariablesUILib/Resources");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Models
|
namespace EnvironmentVariablesUILib.Models
|
||||||
{
|
{
|
||||||
public class DefaultVariablesSet : VariablesSet
|
public class DefaultVariablesSet : VariablesSet
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
namespace EnvironmentVariables.Models
|
namespace EnvironmentVariablesUILib.Models
|
||||||
{
|
{
|
||||||
public enum EnvironmentState
|
public enum EnvironmentState
|
||||||
{
|
{
|
@ -6,10 +6,9 @@ using System;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariablesUILib.Helpers;
|
||||||
using ManagedCommon;
|
|
||||||
|
|
||||||
namespace EnvironmentVariables.Models
|
namespace EnvironmentVariablesUILib.Models
|
||||||
{
|
{
|
||||||
public partial class ProfileVariablesSet : VariablesSet
|
public partial class ProfileVariablesSet : VariablesSet
|
||||||
{
|
{
|
||||||
@ -48,13 +47,13 @@ namespace EnvironmentVariables.Models
|
|||||||
// Backup the variable
|
// Backup the variable
|
||||||
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variableToOverride))
|
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variableToOverride))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to set backup variable.");
|
LoggerInstance.Logger.LogError("Failed to set backup variable.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variable))
|
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variable))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to set profile variable.");
|
LoggerInstance.Logger.LogError("Failed to set profile variable.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +79,7 @@ namespace EnvironmentVariables.Models
|
|||||||
// Unset the variable
|
// Unset the variable
|
||||||
if (!EnvironmentVariablesHelper.UnsetVariableWithoutNotify(variable))
|
if (!EnvironmentVariablesHelper.UnsetVariableWithoutNotify(variable))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to unset variable.");
|
LoggerInstance.Logger.LogError("Failed to unset variable.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var originalName = variable.Name;
|
var originalName = variable.Name;
|
||||||
@ -95,12 +94,12 @@ namespace EnvironmentVariables.Models
|
|||||||
|
|
||||||
if (!EnvironmentVariablesHelper.UnsetVariableWithoutNotify(backupVariable))
|
if (!EnvironmentVariablesHelper.UnsetVariableWithoutNotify(backupVariable))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to unset backup variable.");
|
LoggerInstance.Logger.LogError("Failed to unset backup variable.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variableToRestore))
|
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variableToRestore))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to restore backup variable.");
|
LoggerInstance.Logger.LogError("Failed to restore backup variable.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,10 +10,9 @@ using System.Linq;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariablesUILib.Helpers;
|
||||||
using ManagedCommon;
|
|
||||||
|
|
||||||
namespace EnvironmentVariables.Models
|
namespace EnvironmentVariablesUILib.Models
|
||||||
{
|
{
|
||||||
public partial class Variable : ObservableObject, IJsonOnDeserialized
|
public partial class Variable : ObservableObject, IJsonOnDeserialized
|
||||||
{
|
{
|
||||||
@ -38,7 +37,7 @@ namespace EnvironmentVariables.Models
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return (ParentType != VariablesSetType.System || App.GetService<IElevationHelper>().IsElevated) && !IsAppliedFromProfile;
|
return (ParentType != VariablesSetType.System || ElevationHelper.ElevationHelperInstance.IsElevated) && !IsAppliedFromProfile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +121,7 @@ namespace EnvironmentVariables.Models
|
|||||||
{
|
{
|
||||||
if (!EnvironmentVariablesHelper.UnsetVariable(clone))
|
if (!EnvironmentVariablesHelper.UnsetVariable(clone))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to unset original variable.");
|
LoggerInstance.Logger.LogError("Failed to unset original variable.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentProfile != null)
|
if (parentProfile != null)
|
||||||
@ -137,12 +136,12 @@ namespace EnvironmentVariables.Models
|
|||||||
|
|
||||||
if (!EnvironmentVariablesHelper.UnsetVariableWithoutNotify(backupVariable))
|
if (!EnvironmentVariablesHelper.UnsetVariableWithoutNotify(backupVariable))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to unset backup variable.");
|
LoggerInstance.Logger.LogError("Failed to unset backup variable.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variableToRestore))
|
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variableToRestore))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to restore backup variable.");
|
LoggerInstance.Logger.LogError("Failed to restore backup variable.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,14 +162,14 @@ namespace EnvironmentVariables.Models
|
|||||||
// Backup the variable
|
// Backup the variable
|
||||||
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variableToOverride))
|
if (!EnvironmentVariablesHelper.SetVariableWithoutNotify(variableToOverride))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to set backup variable.");
|
LoggerInstance.Logger.LogError("Failed to set backup variable.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EnvironmentVariablesHelper.SetVariable(this))
|
if (!EnvironmentVariablesHelper.SetVariable(this))
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to set new variable.");
|
LoggerInstance.Logger.LogError("Failed to set new variable.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -197,7 +196,7 @@ namespace EnvironmentVariables.Models
|
|||||||
const int MaxUserEnvVariableLength = 255; // User-wide env vars stored in the registry have names limited to 255 chars
|
const int MaxUserEnvVariableLength = 255; // User-wide env vars stored in the registry have names limited to 255 chars
|
||||||
if (ParentType != VariablesSetType.System && Name.Length >= MaxUserEnvVariableLength)
|
if (ParentType != VariablesSetType.System && Name.Length >= MaxUserEnvVariableLength)
|
||||||
{
|
{
|
||||||
Logger.LogError("Variable name too long.");
|
LoggerInstance.Logger.LogError("Variable name too long.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -7,9 +7,9 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using EnvironmentVariables.ViewModels;
|
using EnvironmentVariablesUILib.ViewModels;
|
||||||
|
|
||||||
namespace EnvironmentVariables.Models
|
namespace EnvironmentVariablesUILib.Models
|
||||||
{
|
{
|
||||||
public partial class VariablesSet : ObservableObject
|
public partial class VariablesSet : ObservableObject
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
namespace EnvironmentVariables.Models
|
namespace EnvironmentVariablesUILib.Models
|
||||||
{
|
{
|
||||||
public enum VariablesSetType
|
public enum VariablesSetType
|
||||||
{
|
{
|
@ -0,0 +1,15 @@
|
|||||||
|
// 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 EnvironmentVariablesUILib.Models;
|
||||||
|
|
||||||
|
namespace EnvironmentVariablesUILib.Telemetry
|
||||||
|
{
|
||||||
|
public interface ITelemetry
|
||||||
|
{
|
||||||
|
abstract void LogEnvironmentVariablesProfileEnabledEvent(bool enabled);
|
||||||
|
|
||||||
|
abstract void LogEnvironmentVariablesVariableChangedEvent(VariablesSetType type);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
// 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 EnvironmentVariablesUILib.Telemetry;
|
||||||
|
|
||||||
|
namespace EnvironmentVariablesUILib.Helpers
|
||||||
|
{
|
||||||
|
public static class TelemetryInstance
|
||||||
|
{
|
||||||
|
public static ITelemetry Telemetry { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -10,14 +10,12 @@ using System.Globalization;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using EnvironmentVariablesUILib.Helpers;
|
||||||
using EnvironmentVariables.Helpers;
|
using EnvironmentVariablesUILib.Models;
|
||||||
using EnvironmentVariables.Models;
|
using EnvironmentVariablesUILib.Telemetry;
|
||||||
using ManagedCommon;
|
|
||||||
using Microsoft.PowerToys.Telemetry;
|
|
||||||
using Microsoft.UI.Dispatching;
|
using Microsoft.UI.Dispatching;
|
||||||
|
|
||||||
namespace EnvironmentVariables.ViewModels
|
namespace EnvironmentVariablesUILib.ViewModels
|
||||||
{
|
{
|
||||||
public partial class MainViewModel : ObservableObject
|
public partial class MainViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
@ -48,10 +46,15 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
|
|
||||||
public ProfileVariablesSet AppliedProfile { get; set; }
|
public ProfileVariablesSet AppliedProfile { get; set; }
|
||||||
|
|
||||||
public MainViewModel(IEnvironmentVariablesService environmentVariablesService)
|
public MainViewModel(IElevationHelper elevationHelper, IEnvironmentVariablesService environmentVariablesService, ILogger logger, ITelemetry telemetry)
|
||||||
{
|
{
|
||||||
_environmentVariablesService = environmentVariablesService;
|
_environmentVariablesService = environmentVariablesService;
|
||||||
var isElevated = App.GetService<IElevationHelper>().IsElevated;
|
|
||||||
|
ElevationHelper.ElevationHelperInstance = elevationHelper;
|
||||||
|
LoggerInstance.Logger = logger;
|
||||||
|
TelemetryInstance.Telemetry = telemetry;
|
||||||
|
|
||||||
|
var isElevated = ElevationHelper.ElevationHelperInstance.IsElevated;
|
||||||
IsElevated = isElevated;
|
IsElevated = isElevated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +88,6 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
|
||||||
public void LoadEnvironmentVariables()
|
public void LoadEnvironmentVariables()
|
||||||
{
|
{
|
||||||
LoadDefaultVariables();
|
LoadDefaultVariables();
|
||||||
@ -129,7 +131,7 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Show some error
|
// Show some error
|
||||||
Logger.LogError("Failed to load profiles.json file", ex);
|
LoggerInstance.Logger.LogError("Failed to load profiles.json file", ex);
|
||||||
|
|
||||||
Profiles = new ObservableCollection<ProfileVariablesSet>();
|
Profiles = new ObservableCollection<ProfileVariablesSet>();
|
||||||
}
|
}
|
||||||
@ -228,8 +230,7 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
PowerToysTelemetry.Log.WriteEvent(new Telemetry.EnvironmentVariablesVariableChangedEvent(original.ParentType));
|
TelemetryInstance.Telemetry.LogEnvironmentVariablesVariableChangedEvent(original.ParentType);
|
||||||
|
|
||||||
_ = Task.Run(SaveAsync);
|
_ = Task.Run(SaveAsync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,7 +277,7 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Show some error
|
// Show some error
|
||||||
Logger.LogError("Failed to save to profiles.json file", ex);
|
LoggerInstance.Logger.LogError("Failed to save to profiles.json file", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,23 +294,13 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
UnsetAppliedProfile();
|
UnsetAppliedProfile();
|
||||||
SetAppliedProfile(profile);
|
SetAppliedProfile(profile);
|
||||||
|
|
||||||
var telemetryEnabled = new Telemetry.EnvironmentVariablesProfileEnabledEvent()
|
TelemetryInstance.Telemetry.LogEnvironmentVariablesProfileEnabledEvent(true);
|
||||||
{
|
|
||||||
Enabled = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
PowerToysTelemetry.Log.WriteEvent(telemetryEnabled);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UnsetAppliedProfile();
|
UnsetAppliedProfile();
|
||||||
|
|
||||||
var telemetryEnabled = new Telemetry.EnvironmentVariablesProfileEnabledEvent()
|
TelemetryInstance.Telemetry.LogEnvironmentVariablesProfileEnabledEvent(false);
|
||||||
{
|
|
||||||
Enabled = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
PowerToysTelemetry.Log.WriteEvent(telemetryEnabled);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<assemblyIdentity version="1.0.0.0" name="EnvironmentVariables.app"/>
|
||||||
|
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<!--The ID below informs the system that this application is compatible with OS features first introduced in Windows 8.
|
||||||
|
For more info see https://docs.microsoft.com/windows/win32/sysinfo/targeting-your-application-at-windows-8-1
|
||||||
|
|
||||||
|
It is also necessary to support features in unpackaged applications, for example the custom title bar implementation.-->
|
||||||
|
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
|
||||||
|
<!-- Windows 10 -->
|
||||||
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
|
||||||
|
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<windowsSettings>
|
||||||
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||||
|
</windowsSettings>
|
||||||
|
</application>
|
||||||
|
</assembly>
|
@ -2,7 +2,7 @@
|
|||||||
// 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 Hosts.Models;
|
using HostsUILib.Models;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
namespace Hosts.Tests
|
namespace Hosts.Tests
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Hosts\Hosts.csproj" />
|
<ProjectReference Include="..\HostsUILib\HostsUILib.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -5,14 +5,13 @@
|
|||||||
using System.IO.Abstractions.TestingHelpers;
|
using System.IO.Abstractions.TestingHelpers;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Hosts.Exceptions;
|
|
||||||
using Hosts.Helpers;
|
|
||||||
using Hosts.Models;
|
|
||||||
using Hosts.Settings;
|
|
||||||
using Hosts.Tests.Mocks;
|
using Hosts.Tests.Mocks;
|
||||||
|
using HostsUILib.Exceptions;
|
||||||
|
using HostsUILib.Helpers;
|
||||||
|
using HostsUILib.Models;
|
||||||
|
using HostsUILib.Settings;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Settings.UI.Library.Enumerations;
|
|
||||||
|
|
||||||
namespace Hosts.Tests
|
namespace Hosts.Tests
|
||||||
{
|
{
|
||||||
|
28
src/modules/Hosts/Hosts/Helpers/Host.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// 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 Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
namespace Hosts.Helpers
|
||||||
|
{
|
||||||
|
public static class Host
|
||||||
|
{
|
||||||
|
public static IHost HostInstance
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T GetService<T>()
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
if (HostInstance!.Services.GetService(typeof(T)) is not T service)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"{typeof(T)} needs to be registered in ConfigureServices within App.xaml.cs.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
src/modules/Hosts/Hosts/Helpers/LoggerWrapper.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// 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 HostsUILib.Helpers;
|
||||||
|
using ManagedCommon;
|
||||||
|
|
||||||
|
namespace Hosts
|
||||||
|
{
|
||||||
|
internal sealed class LoggerWrapper : ILogger
|
||||||
|
{
|
||||||
|
public void LogDebug(string message)
|
||||||
|
{
|
||||||
|
Logger.LogDebug(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogError(string message)
|
||||||
|
{
|
||||||
|
Logger.LogError(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogError(string message, Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(message, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogInfo(string message)
|
||||||
|
{
|
||||||
|
Logger.LogInfo(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogTrace()
|
||||||
|
{
|
||||||
|
Logger.LogTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogWarning(string message)
|
||||||
|
{
|
||||||
|
Logger.LogWarning(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,15 +16,34 @@
|
|||||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||||
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
|
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
|
||||||
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps</OutputPath>
|
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps</OutputPath>
|
||||||
<RootNamespace>Hosts</RootNamespace>
|
|
||||||
<AssemblyName>PowerToys.Hosts</AssemblyName>
|
<AssemblyName>PowerToys.Hosts</AssemblyName>
|
||||||
<DefineConstants>DISABLE_XAML_GENERATED_MAIN,TRACE</DefineConstants>
|
<DefineConstants>DISABLE_XAML_GENERATED_MAIN,TRACE</DefineConstants>
|
||||||
<ApplicationIcon>Assets/Hosts/Hosts.ico</ApplicationIcon>
|
|
||||||
<SelfContained>true</SelfContained>
|
<SelfContained>true</SelfContained>
|
||||||
|
<ApplicationIcon>Assets/Hosts/Hosts.ico</ApplicationIcon>
|
||||||
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
||||||
<ProjectPriFileName>PowerToys.Hosts.pri</ProjectPriFileName>
|
<ProjectPriFileName>PowerToys.Hosts.pri</ProjectPriFileName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="Assets\Hosts\AppList.scale-100.png" />
|
||||||
|
<None Remove="Assets\Hosts\AppList.scale-125.png" />
|
||||||
|
<None Remove="Assets\Hosts\AppList.scale-150.png" />
|
||||||
|
<None Remove="Assets\Hosts\AppList.scale-200.png" />
|
||||||
|
<None Remove="Assets\Hosts\AppList.scale-400.png" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="CopyPRIFileToOutputDir" AfterTargets="Build">
|
||||||
|
<Message Text="Executing CopyPRIFileToOutputDir task" Importance="High" />
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PRIFile Include="$(OutDir)**\PowerToys.Hosts.pri" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Copy SourceFiles="@(PRIFile)" DestinationFolder="$(OutDir)" />
|
||||||
|
|
||||||
|
<Message Text="Copied CopyPRIFileToOutputDir files" Importance="High" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Page Remove="HostsXAML\App.xaml" />
|
<Page Remove="HostsXAML\App.xaml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -32,6 +51,10 @@
|
|||||||
<ApplicationDefinition Include="HostsXAML\App.xaml" />
|
<ApplicationDefinition Include="HostsXAML\App.xaml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Assets\Hosts\Hosts.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- SelfContained=true requires RuntimeIdentifier to be set -->
|
<!-- SelfContained=true requires RuntimeIdentifier to be set -->
|
||||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
@ -46,38 +69,38 @@
|
|||||||
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
|
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
|
||||||
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
|
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="Assets\Hosts\AppList.scale-100.png" />
|
|
||||||
<None Remove="Assets\Hosts\AppList.scale-125.png" />
|
|
||||||
<None Remove="Assets\Hosts\AppList.scale-150.png" />
|
|
||||||
<None Remove="Assets\Hosts\AppList.scale-200.png" />
|
|
||||||
<None Remove="Assets\Hosts\AppList.scale-400.png" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Windows.CsWinRT" />
|
|
||||||
<PackageReference Include="CommunityToolkit.Mvvm" />
|
|
||||||
<PackageReference Include="CommunityToolkit.WinUI.Converters" />
|
|
||||||
<PackageReference Include="CommunityToolkit.WinUI.Extensions" />
|
|
||||||
<PackageReference Include="CommunityToolkit.WinUI.Collections" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" />
|
||||||
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
||||||
|
<PackageReference Include="Microsoft.Windows.CsWinRT" />
|
||||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" />
|
|
||||||
<PackageReference Include="System.IO.Abstractions" />
|
|
||||||
<PackageReference Include="WinUIEx" />
|
<PackageReference Include="WinUIEx" />
|
||||||
<Manifest Include="$(ApplicationManifest)" />
|
<Manifest Include="$(ApplicationManifest)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnablePreviewMsixTooling)'=='true'">
|
<!--
|
||||||
|
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
|
||||||
|
Tools extension to be activated for this project even if the Windows App SDK Nuget
|
||||||
|
package has not yet been restored.
|
||||||
|
-->
|
||||||
|
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||||
<ProjectCapability Include="Msix" />
|
<ProjectCapability Include="Msix" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
|
|
||||||
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
|
|
||||||
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
|
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
|
||||||
|
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||||
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
|
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
|
||||||
|
<ProjectReference Include="..\HostsUILib\HostsUILib.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<!--
|
||||||
|
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
|
||||||
|
Explorer "Package and Publish" context menu entry to be enabled for this project even if
|
||||||
|
the Windows App SDK Nuget package has not yet been restored.
|
||||||
|
-->
|
||||||
|
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||||
|
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
|
||||||
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<Application
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<Application
|
||||||
x:Class="Hosts.App"
|
x:Class="Hosts.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
@ -9,158 +10,7 @@
|
|||||||
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
||||||
<!-- Other merged dictionaries here -->
|
<!-- Other merged dictionaries here -->
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
<!-- Other app resources here -->
|
||||||
|
|
||||||
<ResourceDictionary.ThemeDictionaries>
|
|
||||||
<ResourceDictionary x:Key="Default">
|
|
||||||
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SubtleFillColorTertiary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SubtleFillColorTertiary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="TextFillColorPrimary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="TextFillColorPrimary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="TextFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="TextFillColorDisabled" />
|
|
||||||
</ResourceDictionary>
|
|
||||||
|
|
||||||
<ResourceDictionary x:Key="Light">
|
|
||||||
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SubtleFillColorTertiary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SubtleFillColorTertiary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SubtleFillColorTransparent" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="TextFillColorPrimary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="TextFillColorPrimary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="TextFillColorSecondary" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="TextFillColorDisabled" />
|
|
||||||
</ResourceDictionary>
|
|
||||||
|
|
||||||
<ResourceDictionary x:Key="HighContrast">
|
|
||||||
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SystemColorWindowColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SystemColorHighlightTextColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SystemColorWindowColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SystemControlBackgroundBaseLowBrush" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SystemColorWindowColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SystemColorHighlightColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SystemColorHighlightColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SystemColorGrayTextColor" />
|
|
||||||
|
|
||||||
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="SystemColorButtonTextColorBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="SystemControlHighlightBaseHighBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="SystemControlHighlightBaseHighBrush" />
|
|
||||||
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
|
|
||||||
</ResourceDictionary>
|
|
||||||
|
|
||||||
</ResourceDictionary.ThemeDictionaries>
|
|
||||||
|
|
||||||
<Style x:Key="SubtleButtonStyle" TargetType="Button">
|
|
||||||
<Setter Property="Background" Value="{ThemeResource SubtleButtonBackground}" />
|
|
||||||
<Setter Property="BackgroundSizing" Value="InnerBorderEdge" />
|
|
||||||
<Setter Property="Foreground" Value="{ThemeResource SubtleButtonForeground}" />
|
|
||||||
<Setter Property="BorderBrush" Value="{ThemeResource SubtleButtonBorderBrush}" />
|
|
||||||
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}" />
|
|
||||||
<Setter Property="Padding" Value="{StaticResource ButtonPadding}" />
|
|
||||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
|
||||||
<Setter Property="VerticalAlignment" Value="Center" />
|
|
||||||
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
|
|
||||||
<Setter Property="FontWeight" Value="Normal" />
|
|
||||||
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
|
|
||||||
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
|
|
||||||
<Setter Property="FocusVisualMargin" Value="-3" />
|
|
||||||
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
|
|
||||||
<Setter Property="Template">
|
|
||||||
<Setter.Value>
|
|
||||||
<ControlTemplate TargetType="Button">
|
|
||||||
<ContentPresenter
|
|
||||||
x:Name="ContentPresenter"
|
|
||||||
Padding="{TemplateBinding Padding}"
|
|
||||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
|
||||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
|
||||||
AnimatedIcon.State="Normal"
|
|
||||||
AutomationProperties.AccessibilityView="Raw"
|
|
||||||
Background="{TemplateBinding Background}"
|
|
||||||
BackgroundSizing="{TemplateBinding BackgroundSizing}"
|
|
||||||
BorderBrush="{TemplateBinding BorderBrush}"
|
|
||||||
BorderThickness="{TemplateBinding BorderThickness}"
|
|
||||||
Content="{TemplateBinding Content}"
|
|
||||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
|
||||||
ContentTransitions="{TemplateBinding ContentTransitions}"
|
|
||||||
CornerRadius="{TemplateBinding CornerRadius}"
|
|
||||||
Foreground="{TemplateBinding Foreground}">
|
|
||||||
<ContentPresenter.BackgroundTransition>
|
|
||||||
<BrushTransition Duration="0:0:0.083" />
|
|
||||||
</ContentPresenter.BackgroundTransition>
|
|
||||||
<VisualStateManager.VisualStateGroups>
|
|
||||||
<VisualStateGroup x:Name="CommonStates">
|
|
||||||
<VisualState x:Name="Normal" />
|
|
||||||
<VisualState x:Name="PointerOver">
|
|
||||||
<Storyboard>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundPointerOver}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushPointerOver}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundPointerOver}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
</Storyboard>
|
|
||||||
<VisualState.Setters>
|
|
||||||
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="PointerOver" />
|
|
||||||
</VisualState.Setters>
|
|
||||||
</VisualState>
|
|
||||||
<VisualState x:Name="Pressed">
|
|
||||||
<Storyboard>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundPressed}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushPressed}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundPressed}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
</Storyboard>
|
|
||||||
<VisualState.Setters>
|
|
||||||
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="Pressed" />
|
|
||||||
</VisualState.Setters>
|
|
||||||
</VisualState>
|
|
||||||
<VisualState x:Name="Disabled">
|
|
||||||
<Storyboard>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundDisabled}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushDisabled}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
|
||||||
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundDisabled}" />
|
|
||||||
</ObjectAnimationUsingKeyFrames>
|
|
||||||
</Storyboard>
|
|
||||||
<VisualState.Setters>
|
|
||||||
<!-- DisabledVisual Should be handled by the control, not the animated icon. -->
|
|
||||||
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="Normal" />
|
|
||||||
</VisualState.Setters>
|
|
||||||
</VisualState>
|
|
||||||
</VisualStateGroup>
|
|
||||||
</VisualStateManager.VisualStateGroups>
|
|
||||||
</ContentPresenter>
|
|
||||||
</ControlTemplate>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
||||||
|
@ -1,48 +1,43 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// 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 System;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Hosts.Helpers;
|
using Common.UI;
|
||||||
using Hosts.Settings;
|
using HostsUILib.Helpers;
|
||||||
using Hosts.ViewModels;
|
using HostsUILib.Settings;
|
||||||
using Hosts.Views;
|
using HostsUILib.ViewModels;
|
||||||
|
using HostsUILib.Views;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.PowerToys.Telemetry;
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using Microsoft.UI.Dispatching;
|
using Microsoft.UI.Dispatching;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
|
using static HostsUILib.Settings.IUserSettings;
|
||||||
|
using Host = Hosts.Helpers.Host;
|
||||||
|
|
||||||
|
// To learn more about WinUI, the WinUI project structure,
|
||||||
|
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||||
namespace Hosts
|
namespace Hosts
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides application-specific behavior to supplement the default Application class.
|
||||||
|
/// </summary>
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
private Window _window;
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="App"/> class.
|
||||||
public IHost Host
|
/// Initializes the singleton application object. This is the first line of authored code
|
||||||
{
|
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||||
get;
|
/// </summary>
|
||||||
}
|
|
||||||
|
|
||||||
public static T GetService<T>()
|
|
||||||
where T : class
|
|
||||||
{
|
|
||||||
if ((App.Current as App)!.Host.Services.GetService(typeof(T)) is not T service)
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"{typeof(T)} needs to be registered in ConfigureServices within App.xaml.cs.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
|
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Host = Microsoft.Extensions.Hosting.Host.
|
Host.HostInstance = Microsoft.Extensions.Hosting.Host.
|
||||||
CreateDefaultBuilder().
|
CreateDefaultBuilder().
|
||||||
UseContentRoot(AppContext.BaseDirectory).
|
UseContentRoot(AppContext.BaseDirectory).
|
||||||
ConfigureServices((context, services) =>
|
ConfigureServices((context, services) =>
|
||||||
@ -50,28 +45,33 @@ namespace Hosts
|
|||||||
// Core Services
|
// Core Services
|
||||||
services.AddSingleton<IFileSystem, FileSystem>();
|
services.AddSingleton<IFileSystem, FileSystem>();
|
||||||
services.AddSingleton<IHostsService, HostsService>();
|
services.AddSingleton<IHostsService, HostsService>();
|
||||||
services.AddSingleton<IUserSettings, UserSettings>();
|
services.AddSingleton<IUserSettings, Hosts.Settings.UserSettings>();
|
||||||
services.AddSingleton<IElevationHelper, ElevationHelper>();
|
services.AddSingleton<IElevationHelper, ElevationHelper>();
|
||||||
|
|
||||||
// Views and ViewModels
|
// Views and ViewModels
|
||||||
services.AddTransient<MainPage>();
|
services.AddSingleton<ILogger, LoggerWrapper>();
|
||||||
services.AddTransient<MainViewModel>();
|
services.AddSingleton<IElevationHelper, ElevationHelper>();
|
||||||
|
services.AddSingleton<OpenSettingsFunction>(() =>
|
||||||
|
{
|
||||||
|
SettingsDeepLink.OpenSettings(SettingsDeepLink.SettingsWindow.Hosts, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
services.AddSingleton<MainViewModel, MainViewModel>();
|
||||||
|
services.AddSingleton<HostsMainPage, HostsMainPage>();
|
||||||
}).
|
}).
|
||||||
Build();
|
Build();
|
||||||
|
|
||||||
UnhandledException += App_UnhandledException;
|
|
||||||
|
|
||||||
var cleanupBackupThread = new Thread(() =>
|
var cleanupBackupThread = new Thread(() =>
|
||||||
{
|
{
|
||||||
// Delete old backups only if running elevated
|
// Delete old backups only if running elevated
|
||||||
if (!GetService<IElevationHelper>().IsElevated)
|
if (!Host.GetService<IElevationHelper>().IsElevated)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GetService<IHostsService>().CleanupBackup();
|
Host.GetService<IHostsService>().CleanupBackup();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -81,8 +81,14 @@ namespace Hosts
|
|||||||
|
|
||||||
cleanupBackupThread.IsBackground = true;
|
cleanupBackupThread.IsBackground = true;
|
||||||
cleanupBackupThread.Start();
|
cleanupBackupThread.Start();
|
||||||
|
|
||||||
|
UnhandledException += App_UnhandledException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked when the application is launched.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="args">Details about the launch request and process.</param>
|
||||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||||
{
|
{
|
||||||
var cmdArgs = Environment.GetCommandLineArgs();
|
var cmdArgs = Environment.GetCommandLineArgs();
|
||||||
@ -105,15 +111,17 @@ namespace Hosts
|
|||||||
Logger.LogInfo($"Hosts started detached from PowerToys Runner.");
|
Logger.LogInfo($"Hosts started detached from PowerToys Runner.");
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerToysTelemetry.Log.WriteEvent(new Hosts.Telemetry.HostsFileEditorOpenedEvent());
|
PowerToysTelemetry.Log.WriteEvent(new Telemetry.HostsFileEditorOpenedEvent());
|
||||||
|
|
||||||
_window = new MainWindow();
|
window = new MainWindow();
|
||||||
_window.Activate();
|
window.Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
|
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
|
||||||
{
|
{
|
||||||
Logger.LogError("Unhandled exception", e.Exception);
|
Logger.LogError("Unhandled exception", e.Exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Window window;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
<winuiex:WindowEx
|
<winuiex:WindowEx
|
||||||
x:Class="Hosts.MainWindow"
|
x:Class="Hosts.MainWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="using:Hosts"
|
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:views="using:Hosts.Views"
|
xmlns:views="using:Hosts.Views"
|
||||||
xmlns:winuiex="using:WinUIEx"
|
xmlns:winuiex="using:WinUIEx"
|
||||||
@ -15,7 +14,7 @@
|
|||||||
<Window.SystemBackdrop>
|
<Window.SystemBackdrop>
|
||||||
<MicaBackdrop />
|
<MicaBackdrop />
|
||||||
</Window.SystemBackdrop>
|
</Window.SystemBackdrop>
|
||||||
<Grid>
|
<Grid x:Name="MainGrid" Loaded="Grid_Loaded">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
@ -42,7 +41,5 @@
|
|||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Style="{StaticResource CaptionTextBlockStyle}" />
|
Style="{StaticResource CaptionTextBlockStyle}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<views:MainPage Grid.Row="1" />
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</winuiex:WindowEx>
|
</winuiex:WindowEx>
|
||||||
|
@ -1,17 +1,28 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// 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 Hosts.Helpers;
|
using Hosts.Helpers;
|
||||||
|
using HostsUILib.Helpers;
|
||||||
|
using HostsUILib.Views;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
|
using Microsoft.Windows.ApplicationModel.Resources;
|
||||||
using WinUIEx;
|
using WinUIEx;
|
||||||
|
|
||||||
|
// To learn more about WinUI, the WinUI project structure,
|
||||||
|
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||||
namespace Hosts
|
namespace Hosts
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An empty window that can be used on its own or navigated to within a Frame.
|
||||||
|
/// </summary>
|
||||||
public sealed partial class MainWindow : WindowEx
|
public sealed partial class MainWindow : WindowEx
|
||||||
{
|
{
|
||||||
|
private HostsMainPage MainPage { get; }
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -20,15 +31,18 @@ namespace Hosts
|
|||||||
SetTitleBar(titleBar);
|
SetTitleBar(titleBar);
|
||||||
AppWindow.SetIcon("Assets/Hosts/Hosts.ico");
|
AppWindow.SetIcon("Assets/Hosts/Hosts.ico");
|
||||||
|
|
||||||
var loader = ResourceLoaderInstance.ResourceLoader;
|
var loader = new ResourceLoader("PowerToys.HostsUILib.pri", "PowerToys.HostsUILib/Resources");
|
||||||
var title = App.GetService<IElevationHelper>().IsElevated ? loader.GetString("WindowAdminTitle") : loader.GetString("WindowTitle");
|
|
||||||
|
var title = Host.GetService<IElevationHelper>().IsElevated ? loader.GetString("WindowAdminTitle") : loader.GetString("WindowTitle");
|
||||||
Title = title;
|
Title = title;
|
||||||
AppTitleTextBlock.Text = title;
|
AppTitleTextBlock.Text = title;
|
||||||
|
|
||||||
var handle = this.GetWindowHandle();
|
var handle = this.GetWindowHandle();
|
||||||
WindowHelpers.BringToForeground(handle);
|
|
||||||
|
|
||||||
|
WindowHelpers.BringToForeground(handle);
|
||||||
Activated += MainWindow_Activated;
|
Activated += MainWindow_Activated;
|
||||||
|
|
||||||
|
MainPage = Host.GetService<HostsMainPage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
|
private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
|
||||||
@ -42,5 +56,11 @@ namespace Hosts
|
|||||||
AppTitleTextBlock.Foreground = (SolidColorBrush)App.Current.Resources["WindowCaptionForeground"];
|
AppTitleTextBlock.Foreground = (SolidColorBrush)App.Current.Resources["WindowCaptionForeground"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Grid_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
MainGrid.Children.Add(MainPage);
|
||||||
|
Grid.SetRow(MainPage, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ namespace Hosts
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Logger.InitializeLogger("\\Hosts\\Logs");
|
Logger.InitializeLogger("\\Hosts\\Logs");
|
||||||
|
|
||||||
WinRT.ComWrappersSupport.InitializeComWrappers();
|
WinRT.ComWrappersSupport.InitializeComWrappers();
|
||||||
|
|
||||||
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredHostsFileEditorEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
|
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredHostsFileEditorEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
|
||||||
|
@ -5,10 +5,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using HostsUILib.Helpers;
|
||||||
|
using HostsUILib.Settings;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||||
using Settings.UI.Library.Enumerations;
|
|
||||||
|
|
||||||
namespace Hosts.Settings
|
namespace Hosts.Settings
|
||||||
{
|
{
|
||||||
@ -38,8 +39,10 @@ namespace Hosts.Settings
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Moved from Settings.UI.Library
|
||||||
public HostsAdditionalLinesPosition AdditionalLinesPosition { get; private set; }
|
public HostsAdditionalLinesPosition AdditionalLinesPosition { get; private set; }
|
||||||
|
|
||||||
|
// Moved from Settings.UI.Library
|
||||||
public HostsEncoding Encoding { get; set; }
|
public HostsEncoding Encoding { get; set; }
|
||||||
|
|
||||||
public UserSettings()
|
public UserSettings()
|
||||||
@ -72,6 +75,7 @@ namespace Hosts.Settings
|
|||||||
|
|
||||||
if (!_settingsUtils.SettingsExists(HostsModuleName))
|
if (!_settingsUtils.SettingsExists(HostsModuleName))
|
||||||
{
|
{
|
||||||
|
// Logger needs to be abstracted
|
||||||
Logger.LogInfo("Hosts settings.json was missing, creating a new one");
|
Logger.LogInfo("Hosts settings.json was missing, creating a new one");
|
||||||
var defaultSettings = new HostsSettings();
|
var defaultSettings = new HostsSettings();
|
||||||
defaultSettings.Save(_settingsUtils);
|
defaultSettings.Save(_settingsUtils);
|
||||||
@ -81,8 +85,8 @@ namespace Hosts.Settings
|
|||||||
if (settings != null)
|
if (settings != null)
|
||||||
{
|
{
|
||||||
ShowStartupWarning = settings.Properties.ShowStartupWarning;
|
ShowStartupWarning = settings.Properties.ShowStartupWarning;
|
||||||
AdditionalLinesPosition = settings.Properties.AdditionalLinesPosition;
|
AdditionalLinesPosition = (HostsAdditionalLinesPosition)settings.Properties.AdditionalLinesPosition;
|
||||||
Encoding = settings.Properties.Encoding;
|
Encoding = (HostsEncoding)settings.Properties.Encoding;
|
||||||
LoopbackDuplicates = settings.Properties.LoopbackDuplicates;
|
LoopbackDuplicates = settings.Properties.LoopbackDuplicates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assembly manifestVersion="1.0"
|
||||||
|
xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
<assemblyIdentity version="1.0.0.0" name="Hosts.app"/>
|
<assemblyIdentity version="1.0.0.0" name="Hosts.app"/>
|
||||||
|
|
||||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
After Width: | Height: | Size: 567 B |
After Width: | Height: | Size: 768 B |
After Width: | Height: | Size: 1001 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 4.2 KiB |
BIN
src/modules/Hosts/HostsUILib/Assets/HostsUILib/Hosts.ico
Normal file
After Width: | Height: | Size: 174 KiB |
@ -2,7 +2,7 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
namespace Hosts
|
namespace HostsUILib
|
||||||
{
|
{
|
||||||
public static class Consts
|
public static class Consts
|
||||||
{
|
{
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Hosts.Exceptions
|
namespace HostsUILib.Exceptions
|
||||||
{
|
{
|
||||||
public class NotRunningElevatedException : Exception
|
public class NotRunningElevatedException : Exception
|
||||||
{
|
{
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Hosts.Exceptions
|
namespace HostsUILib.Exceptions
|
||||||
{
|
{
|
||||||
public class ReadOnlyHostsException : Exception
|
public class ReadOnlyHostsException : Exception
|
||||||
{
|
{
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
|
||||||
namespace Hosts.Helpers
|
namespace HostsUILib.Helpers
|
||||||
{
|
{
|
||||||
public class ElevationHelper : IElevationHelper
|
public class ElevationHelper : IElevationHelper
|
||||||
{
|
{
|
@ -5,7 +5,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
namespace Hosts.Helpers
|
namespace HostsUILib.Helpers
|
||||||
{
|
{
|
||||||
// https://stackoverflow.com/a/22569086
|
// https://stackoverflow.com/a/22569086
|
||||||
public static class ExpressionExtensions
|
public static class ExpressionExtensions
|
@ -13,14 +13,12 @@ using System.Net.NetworkInformation;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Hosts.Exceptions;
|
using HostsUILib.Exceptions;
|
||||||
using Hosts.Models;
|
using HostsUILib.Models;
|
||||||
using Hosts.Settings;
|
using HostsUILib.Settings;
|
||||||
using ManagedCommon;
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using Settings.UI.Library.Enumerations;
|
|
||||||
|
|
||||||
namespace Hosts.Helpers
|
namespace HostsUILib.Helpers
|
||||||
{
|
{
|
||||||
public class HostsService : IHostsService, IDisposable
|
public class HostsService : IHostsService, IDisposable
|
||||||
{
|
{
|
||||||
@ -277,7 +275,7 @@ namespace Hosts.Helpers
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to open default editor", ex);
|
LoggerInstance.Logger.LogError("Failed to open default editor", ex);
|
||||||
notepadFallback = true;
|
notepadFallback = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +287,7 @@ namespace Hosts.Helpers
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to open notepad", ex);
|
LoggerInstance.Logger.LogError("Failed to open notepad", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
namespace Hosts.Helpers
|
namespace HostsUILib.Helpers
|
||||||
{
|
{
|
||||||
public interface IElevationHelper
|
public interface IElevationHelper
|
||||||
{
|
{
|
@ -5,9 +5,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Hosts.Models;
|
using HostsUILib.Models;
|
||||||
|
|
||||||
namespace Hosts.Helpers
|
namespace HostsUILib.Helpers
|
||||||
{
|
{
|
||||||
public interface IHostsService : IDisposable
|
public interface IHostsService : IDisposable
|
||||||
{
|
{
|
23
src/modules/Hosts/HostsUILib/Helpers/ILogger.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace HostsUILib.Helpers
|
||||||
|
{
|
||||||
|
public interface ILogger
|
||||||
|
{
|
||||||
|
public void LogError(string message);
|
||||||
|
|
||||||
|
public void LogError(string message, Exception ex);
|
||||||
|
|
||||||
|
public void LogWarning(string message);
|
||||||
|
|
||||||
|
public void LogInfo(string message);
|
||||||
|
|
||||||
|
public void LogDebug(string message);
|
||||||
|
|
||||||
|
public void LogTrace();
|
||||||
|
}
|
||||||
|
}
|
10
src/modules/Hosts/HostsUILib/Helpers/LoggerInstance.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// 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.
|
||||||
|
namespace HostsUILib.Helpers
|
||||||
|
{
|
||||||
|
public static class LoggerInstance
|
||||||
|
{
|
||||||
|
public static ILogger Logger { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
using Microsoft.Windows.ApplicationModel.Resources;
|
using Microsoft.Windows.ApplicationModel.Resources;
|
||||||
|
|
||||||
namespace RegistryPreview
|
namespace HostsUILib.Helpers
|
||||||
{
|
{
|
||||||
internal static class ResourceLoaderInstance
|
internal static class ResourceLoaderInstance
|
||||||
{
|
{
|
||||||
@ -11,7 +11,7 @@ namespace RegistryPreview
|
|||||||
|
|
||||||
static ResourceLoaderInstance()
|
static ResourceLoaderInstance()
|
||||||
{
|
{
|
||||||
ResourceLoader = new Microsoft.Windows.ApplicationModel.Resources.ResourceLoader("PowerToys.RegistryPreview.pri");
|
ResourceLoader = new Microsoft.Windows.ApplicationModel.Resources.ResourceLoader("PowerToys.HostsUILib.pri", "PowerToys.HostsUILib/Resources");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
namespace Hosts.Helpers
|
namespace HostsUILib.Helpers
|
||||||
{
|
{
|
||||||
public static class StringHelper
|
public static class StringHelper
|
||||||
{
|
{
|
@ -5,7 +5,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Hosts.Helpers
|
namespace HostsUILib.Helpers
|
||||||
{
|
{
|
||||||
public static class ValidationHelper
|
public static class ValidationHelper
|
||||||
{
|
{
|
@ -5,7 +5,7 @@
|
|||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
|
|
||||||
namespace Hosts.Helpers
|
namespace HostsUILib.Helpers
|
||||||
{
|
{
|
||||||
// Taken from https://github.com/microsoft/microsoft-ui-xaml/blob/main/test/MUXControlsTestApp/Utilities/VisualTreeUtils.cs
|
// Taken from https://github.com/microsoft/microsoft-ui-xaml/blob/main/test/MUXControlsTestApp/Utilities/VisualTreeUtils.cs
|
||||||
// Original copyright header:
|
// Original copyright header:
|
@ -1,14 +1,14 @@
|
|||||||
<Page
|
<Page
|
||||||
x:Class="Hosts.Views.MainPage"
|
x:Class="HostsUILib.Views.HostsMainPage"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:helpers="using:Hosts.Helpers"
|
xmlns:helpers="using:HostsUILib.Helpers"
|
||||||
xmlns:i="using:Microsoft.Xaml.Interactivity"
|
xmlns:i="using:Microsoft.Xaml.Interactivity"
|
||||||
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
|
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
|
||||||
xmlns:local="using:Hosts.Views"
|
xmlns:local="using:Hosts.Views"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:models="using:Hosts.Models"
|
xmlns:models="using:HostsUILib.Models"
|
||||||
xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
|
xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
|
||||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||||
x:Name="Page"
|
x:Name="Page"
|
||||||
@ -21,6 +21,166 @@
|
|||||||
</i:Interaction.Behaviors>
|
</i:Interaction.Behaviors>
|
||||||
|
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
|
|
||||||
|
<ResourceDictionary>
|
||||||
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
||||||
|
<!-- Other merged dictionaries here -->
|
||||||
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
|
|
||||||
|
<ResourceDictionary.ThemeDictionaries>
|
||||||
|
<ResourceDictionary x:Key="Default">
|
||||||
|
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SubtleFillColorTertiary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SubtleFillColorTertiary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="TextFillColorPrimary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="TextFillColorPrimary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="TextFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="TextFillColorDisabled" />
|
||||||
|
</ResourceDictionary>
|
||||||
|
|
||||||
|
<ResourceDictionary x:Key="Light">
|
||||||
|
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SubtleFillColorTertiary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SubtleFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SubtleFillColorTertiary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SubtleFillColorTransparent" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="TextFillColorPrimary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="TextFillColorPrimary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="TextFillColorSecondary" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="TextFillColorDisabled" />
|
||||||
|
</ResourceDictionary>
|
||||||
|
|
||||||
|
<ResourceDictionary x:Key="HighContrast">
|
||||||
|
<StaticResource x:Key="SubtleButtonBackground" ResourceKey="SystemColorWindowColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPointerOver" ResourceKey="SystemColorHighlightTextColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundPressed" ResourceKey="SystemColorWindowColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBackgroundDisabled" ResourceKey="SystemControlBackgroundBaseLowBrush" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrush" ResourceKey="SystemColorWindowColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPointerOver" ResourceKey="SystemColorHighlightColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushPressed" ResourceKey="SystemColorHighlightColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonBorderBrushDisabled" ResourceKey="SystemColorGrayTextColor" />
|
||||||
|
|
||||||
|
<StaticResource x:Key="SubtleButtonForeground" ResourceKey="SystemColorButtonTextColorBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPointerOver" ResourceKey="SystemControlHighlightBaseHighBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundPressed" ResourceKey="SystemControlHighlightBaseHighBrush" />
|
||||||
|
<StaticResource x:Key="SubtleButtonForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
|
||||||
|
</ResourceDictionary>
|
||||||
|
|
||||||
|
</ResourceDictionary.ThemeDictionaries>
|
||||||
|
|
||||||
|
<Style x:Key="SubtleButtonStyle" TargetType="Button">
|
||||||
|
<Setter Property="Background" Value="{ThemeResource SubtleButtonBackground}" />
|
||||||
|
<Setter Property="BackgroundSizing" Value="InnerBorderEdge" />
|
||||||
|
<Setter Property="Foreground" Value="{ThemeResource SubtleButtonForeground}" />
|
||||||
|
<Setter Property="BorderBrush" Value="{ThemeResource SubtleButtonBorderBrush}" />
|
||||||
|
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}" />
|
||||||
|
<Setter Property="Padding" Value="{StaticResource ButtonPadding}" />
|
||||||
|
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||||
|
<Setter Property="VerticalAlignment" Value="Center" />
|
||||||
|
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
|
||||||
|
<Setter Property="FontWeight" Value="Normal" />
|
||||||
|
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
|
||||||
|
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
|
||||||
|
<Setter Property="FocusVisualMargin" Value="-3" />
|
||||||
|
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="Button">
|
||||||
|
<ContentPresenter
|
||||||
|
x:Name="ContentPresenter"
|
||||||
|
Padding="{TemplateBinding Padding}"
|
||||||
|
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||||
|
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
|
AnimatedIcon.State="Normal"
|
||||||
|
AutomationProperties.AccessibilityView="Raw"
|
||||||
|
Background="{TemplateBinding Background}"
|
||||||
|
BackgroundSizing="{TemplateBinding BackgroundSizing}"
|
||||||
|
BorderBrush="{TemplateBinding BorderBrush}"
|
||||||
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
|
Content="{TemplateBinding Content}"
|
||||||
|
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||||
|
ContentTransitions="{TemplateBinding ContentTransitions}"
|
||||||
|
CornerRadius="{TemplateBinding CornerRadius}"
|
||||||
|
Foreground="{TemplateBinding Foreground}">
|
||||||
|
<ContentPresenter.BackgroundTransition>
|
||||||
|
<BrushTransition Duration="0:0:0.083" />
|
||||||
|
</ContentPresenter.BackgroundTransition>
|
||||||
|
<VisualStateManager.VisualStateGroups>
|
||||||
|
<VisualStateGroup x:Name="CommonStates">
|
||||||
|
<VisualState x:Name="Normal" />
|
||||||
|
<VisualState x:Name="PointerOver">
|
||||||
|
<Storyboard>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundPointerOver}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushPointerOver}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundPointerOver}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
</Storyboard>
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="PointerOver" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
<VisualState x:Name="Pressed">
|
||||||
|
<Storyboard>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundPressed}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushPressed}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundPressed}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
</Storyboard>
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="Pressed" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
<VisualState x:Name="Disabled">
|
||||||
|
<Storyboard>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBackgroundDisabled}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonBorderBrushDisabled}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
|
||||||
|
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SubtleButtonForegroundDisabled}" />
|
||||||
|
</ObjectAnimationUsingKeyFrames>
|
||||||
|
</Storyboard>
|
||||||
|
<VisualState.Setters>
|
||||||
|
<!-- DisabledVisual Should be handled by the control, not the animated icon. -->
|
||||||
|
<Setter Target="ContentPresenter.(AnimatedIcon.State)" Value="Normal" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
</VisualStateGroup>
|
||||||
|
</VisualStateManager.VisualStateGroups>
|
||||||
|
</ContentPresenter>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
|
||||||
<tkconverters:StringVisibilityConverter
|
<tkconverters:StringVisibilityConverter
|
||||||
x:Key="StringVisibilityConverter"
|
x:Key="StringVisibilityConverter"
|
||||||
EmptyValue="Collapsed"
|
EmptyValue="Collapsed"
|
||||||
@ -36,6 +196,7 @@
|
|||||||
FalseValue="Visible"
|
FalseValue="Visible"
|
||||||
GreaterThan="0"
|
GreaterThan="0"
|
||||||
TrueValue="Collapsed" />
|
TrueValue="Collapsed" />
|
||||||
|
</ResourceDictionary>
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
<Grid Margin="16" RowSpacing="8">
|
<Grid Margin="16" RowSpacing="8">
|
@ -6,18 +6,16 @@ using System;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Hosts.Helpers;
|
using HostsUILib.Helpers;
|
||||||
using Hosts.Models;
|
using HostsUILib.Models;
|
||||||
using Hosts.Settings;
|
using HostsUILib.ViewModels;
|
||||||
using Hosts.ViewModels;
|
|
||||||
using ManagedCommon;
|
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Input;
|
using Microsoft.UI.Xaml.Input;
|
||||||
|
|
||||||
namespace Hosts.Views
|
namespace HostsUILib.Views
|
||||||
{
|
{
|
||||||
public sealed partial class MainPage : Page
|
public partial class HostsMainPage : Page
|
||||||
{
|
{
|
||||||
public MainViewModel ViewModel { get; private set; }
|
public MainViewModel ViewModel { get; private set; }
|
||||||
|
|
||||||
@ -35,10 +33,11 @@ namespace Hosts.Views
|
|||||||
|
|
||||||
public ICommand ExitCommand => new RelayCommand(() => { Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread().TryEnqueue(Application.Current.Exit); });
|
public ICommand ExitCommand => new RelayCommand(() => { Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread().TryEnqueue(Application.Current.Exit); });
|
||||||
|
|
||||||
public MainPage()
|
public HostsMainPage(MainViewModel viewModel)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ViewModel = App.GetService<MainViewModel>();
|
ViewModel = viewModel;
|
||||||
|
|
||||||
DataContext = ViewModel;
|
DataContext = ViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +127,9 @@ namespace Hosts.Views
|
|||||||
|
|
||||||
private async void Page_Loaded(object sender, RoutedEventArgs e)
|
private async void Page_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var userSettings = App.GetService<IUserSettings>();
|
ViewModel.ReadHosts();
|
||||||
|
|
||||||
|
var userSettings = ViewModel.UserSettings;
|
||||||
if (userSettings.ShowStartupWarning)
|
if (userSettings.ShowStartupWarning)
|
||||||
{
|
{
|
||||||
var resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
var resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
||||||
@ -219,11 +220,14 @@ namespace Hosts.Views
|
|||||||
{
|
{
|
||||||
// Based on the template from dev/CommonStyles/ContentDialog_themeresources.xaml in https://github.com/microsoft/microsoft-ui-xaml
|
// Based on the template from dev/CommonStyles/ContentDialog_themeresources.xaml in https://github.com/microsoft/microsoft-ui-xaml
|
||||||
var border = VisualTreeUtils.FindVisualChildByName(sender as ContentDialog, "BackgroundElement") as Border;
|
var border = VisualTreeUtils.FindVisualChildByName(sender as ContentDialog, "BackgroundElement") as Border;
|
||||||
border.Margin = new Thickness(0, 32, 0, 0); // Should be the size reserved for the title bar as in MainWindow.xaml
|
if (border is not null)
|
||||||
|
{
|
||||||
|
border.Margin = new Thickness(0, 32, 0, 0); // Should be the size reserved for the title bar as in MainWindow.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.LogError("Couldn't set the margin for a content dialog. It will appear on top of the title bar.", ex);
|
LoggerInstance.Logger.LogError("Couldn't set the margin for a content dialog. It will appear on top of the title bar.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
69
src/modules/Hosts/HostsUILib/HostsUILib.csproj
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<Import Condition="exists('..\..\..\Version.props')" Project="..\..\..\Version.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows10.0.20348</TargetFramework>
|
||||||
|
<RootNamespace>HostsUILib</RootNamespace>
|
||||||
|
<UseWinUI>true</UseWinUI>
|
||||||
|
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
|
||||||
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
|
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||||
|
<AssemblyName>PowerToys.HostsUILib</AssemblyName>
|
||||||
|
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
||||||
|
<ProjectPriFileName>PowerToys.HostsUILib.pri</ProjectPriFileName>
|
||||||
|
|
||||||
|
<GenerateLibraryLayout>true</GenerateLibraryLayout>
|
||||||
|
<IsPackable>true</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="$(OutDir)\PowerToys.HostsUILib.pri" Pack="True" PackageCopyToOutput="true" PackagePath="lib/$(TargetFramework)" />
|
||||||
|
<None Include="$(OutDir)\PowerToys.HostsUILib.pri" Pack="True" PackageCopyToOutput="True" PackagePath="contentFiles\any\$(TargetFramework)" />
|
||||||
|
<XBFFile Include="$(OutDir)**\*.xbf" />
|
||||||
|
<None Include="@(XBFFile)" Pack="True" PackageCopyToOutput="True" PackagePath="contentFiles\any\$(TargetFramework)" />
|
||||||
|
<None Include="$(OutDir)\PowerToys.HostsUILib.pdb" Pack="True" PackageCopyToOutput="true" PackagePath="lib/$(TargetFramework)" />
|
||||||
|
|
||||||
|
<None Include="Assets\**\*.png" Pack="true" PackageCopyToOutput="true" PackagePath="contentFiles\any\$(TargetFramework)\Assets" />
|
||||||
|
<None Include="Assets\**\*.ico" Pack="true" PackageCopyToOutput="true" PackagePath="contentFiles\any\$(TargetFramework)\Assets" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Remove="Assets\**\*.png" Pack="false" />
|
||||||
|
<Content Remove="Assets\**\*.ico" Pack="false" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CommunityToolkit.Mvvm" />
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.Converters" />
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.Collections" />
|
||||||
|
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
||||||
|
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
||||||
|
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" />
|
||||||
|
<PackageReference Include="System.IO.Abstractions" />
|
||||||
|
<Manifest Include="$(ApplicationManifest)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnablePreviewMsixTooling)'=='true'">
|
||||||
|
<ProjectCapability Include="Msix" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -2,7 +2,7 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
namespace Hosts.Models
|
namespace HostsUILib.Models
|
||||||
{
|
{
|
||||||
public enum AddressType
|
public enum AddressType
|
||||||
{
|
{
|
@ -6,9 +6,9 @@ using System;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Hosts.Helpers;
|
using HostsUILib.Helpers;
|
||||||
|
|
||||||
namespace Hosts.Models
|
namespace HostsUILib.Models
|
||||||
{
|
{
|
||||||
public partial class Entry : ObservableObject
|
public partial class Entry : ObservableObject
|
||||||
{
|
{
|
@ -5,7 +5,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
namespace Hosts.Models
|
namespace HostsUILib.Models
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents the parsed hosts file
|
/// Represents the parsed hosts file
|
@ -0,0 +1,12 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace HostsUILib.Settings
|
||||||
|
{
|
||||||
|
public enum HostsAdditionalLinesPosition
|
||||||
|
{
|
||||||
|
Top = 0,
|
||||||
|
Bottom = 1,
|
||||||
|
}
|
||||||
|
}
|
12
src/modules/Hosts/HostsUILib/Settings/HostsEncoding.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace HostsUILib.Settings
|
||||||
|
{
|
||||||
|
public enum HostsEncoding
|
||||||
|
{
|
||||||
|
Utf8 = 0,
|
||||||
|
Utf8Bom = 1,
|
||||||
|
}
|
||||||
|
}
|
@ -3,9 +3,9 @@
|
|||||||
// 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 System;
|
||||||
using Settings.UI.Library.Enumerations;
|
using System.Net;
|
||||||
|
|
||||||
namespace Hosts.Settings
|
namespace HostsUILib.Settings
|
||||||
{
|
{
|
||||||
public interface IUserSettings
|
public interface IUserSettings
|
||||||
{
|
{
|
||||||
@ -18,5 +18,7 @@ namespace Hosts.Settings
|
|||||||
public HostsEncoding Encoding { get; }
|
public HostsEncoding Encoding { get; }
|
||||||
|
|
||||||
event EventHandler LoopbackDuplicatesChanged;
|
event EventHandler LoopbackDuplicatesChanged;
|
||||||
|
|
||||||
|
public delegate void OpenSettingsFunction();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,19 +10,18 @@ using System.Linq;
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Common.UI;
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using CommunityToolkit.WinUI;
|
using CommunityToolkit.WinUI;
|
||||||
using CommunityToolkit.WinUI.Collections;
|
using CommunityToolkit.WinUI.Collections;
|
||||||
using Hosts.Exceptions;
|
using HostsUILib.Exceptions;
|
||||||
using Hosts.Helpers;
|
using HostsUILib.Helpers;
|
||||||
using Hosts.Models;
|
using HostsUILib.Models;
|
||||||
using Hosts.Settings;
|
using HostsUILib.Settings;
|
||||||
using ManagedCommon;
|
|
||||||
using Microsoft.UI.Dispatching;
|
using Microsoft.UI.Dispatching;
|
||||||
|
using static HostsUILib.Settings.IUserSettings;
|
||||||
|
|
||||||
namespace Hosts.ViewModels
|
namespace HostsUILib.ViewModels
|
||||||
{
|
{
|
||||||
public partial class MainViewModel : ObservableObject, IDisposable
|
public partial class MainViewModel : ObservableObject, IDisposable
|
||||||
{
|
{
|
||||||
@ -90,13 +89,22 @@ namespace Hosts.ViewModels
|
|||||||
|
|
||||||
public int NextId => _entries?.Count > 0 ? _entries.Max(e => e.Id) + 1 : 0;
|
public int NextId => _entries?.Count > 0 ? _entries.Max(e => e.Id) + 1 : 0;
|
||||||
|
|
||||||
public MainViewModel(IHostsService hostService, IUserSettings userSettings)
|
public IUserSettings UserSettings => _userSettings;
|
||||||
|
|
||||||
|
public static MainViewModel Instance { get; set; }
|
||||||
|
|
||||||
|
private OpenSettingsFunction _openSettingsFunction;
|
||||||
|
|
||||||
|
public MainViewModel(IHostsService hostService, IUserSettings userSettings, ILogger logger, OpenSettingsFunction openSettingsFunction)
|
||||||
{
|
{
|
||||||
_hostsService = hostService;
|
_hostsService = hostService;
|
||||||
_userSettings = userSettings;
|
_userSettings = userSettings;
|
||||||
|
|
||||||
_hostsService.FileChanged += (s, e) => _dispatcherQueue.TryEnqueue(() => FileChanged = true);
|
_hostsService.FileChanged += (s, e) => _dispatcherQueue.TryEnqueue(() => FileChanged = true);
|
||||||
_userSettings.LoopbackDuplicatesChanged += (s, e) => ReadHosts();
|
_userSettings.LoopbackDuplicatesChanged += (s, e) => ReadHosts();
|
||||||
|
|
||||||
|
LoggerInstance.Logger = logger;
|
||||||
|
_openSettingsFunction = openSettingsFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(Entry entry)
|
public void Add(Entry entry)
|
||||||
@ -270,7 +278,7 @@ namespace Hosts.ViewModels
|
|||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public void OpenSettings()
|
public void OpenSettings()
|
||||||
{
|
{
|
||||||
SettingsDeepLink.OpenSettings(SettingsDeepLink.SettingsWindow.Hosts, true);
|
_openSettingsFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
@ -335,7 +343,7 @@ namespace Hosts.ViewModels
|
|||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
Logger.LogInfo("FindDuplicates cancelled");
|
LoggerInstance.Logger.LogInfo("FindDuplicates cancelled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -424,7 +432,7 @@ namespace Hosts.ViewModels
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.LogError("Failed to save hosts file", ex);
|
LoggerInstance.Logger.LogError("Failed to save hosts file", ex);
|
||||||
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
|
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
|
||||||
errorMessage = resourceLoader.GetString("FileSaveError_Generic");
|
errorMessage = resourceLoader.GetString("FileSaveError_Generic");
|
||||||
}
|
}
|
Before Width: | Height: | Size: 135 KiB After Width: | Height: | Size: 135 KiB |
@ -0,0 +1,33 @@
|
|||||||
|
// 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.UI.Xaml;
|
||||||
|
using Windows.Data.Json;
|
||||||
|
using WinUIEx;
|
||||||
|
|
||||||
|
namespace RegistryPreview
|
||||||
|
{
|
||||||
|
public sealed partial class MainWindow : WindowEx
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Event handler to grab the main window's size and position before it closes
|
||||||
|
/// </summary>
|
||||||
|
private void AppWindow_Closing(Microsoft.UI.Windowing.AppWindow sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs args)
|
||||||
|
{
|
||||||
|
jsonWindowPlacement.SetNamedValue("appWindow.Position.X", JsonValue.CreateNumberValue(appWindow.Position.X));
|
||||||
|
jsonWindowPlacement.SetNamedValue("appWindow.Position.Y", JsonValue.CreateNumberValue(appWindow.Position.Y));
|
||||||
|
jsonWindowPlacement.SetNamedValue("appWindow.Size.Width", JsonValue.CreateNumberValue(appWindow.Size.Width));
|
||||||
|
jsonWindowPlacement.SetNamedValue("appWindow.Size.Height", JsonValue.CreateNumberValue(appWindow.Size.Height));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that is will prevent the app from closing if the "save file" flag is active
|
||||||
|
/// </summary>
|
||||||
|
public void Window_Closed(object sender, WindowEventArgs args)
|
||||||
|
{
|
||||||
|
// Save window placement
|
||||||
|
SaveWindowPlacementFile(settingsFolder, windowPlacementFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
// 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.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Windows.Storage;
|
||||||
|
using WinUIEx;
|
||||||
|
|
||||||
|
namespace RegistryPreview
|
||||||
|
{
|
||||||
|
public sealed partial class MainWindow : WindowEx
|
||||||
|
{
|
||||||
|
private void OpenWindowPlacementFile(string path, string filename)
|
||||||
|
{
|
||||||
|
string fileContents = string.Empty;
|
||||||
|
string storageFile = Path.Combine(path, filename);
|
||||||
|
if (File.Exists(storageFile))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StreamReader reader = new StreamReader(storageFile);
|
||||||
|
fileContents = reader.ReadToEnd();
|
||||||
|
reader.Close();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// set up default JSON blob
|
||||||
|
fileContents = "{ }";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Task.Run(() => SaveWindowPlacementFile(path, filename)).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
jsonWindowPlacement = Windows.Data.Json.JsonObject.Parse(fileContents);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// set up default JSON blob
|
||||||
|
fileContents = "{ }";
|
||||||
|
jsonWindowPlacement = Windows.Data.Json.JsonObject.Parse(fileContents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Save the window placement JSON blob out to a local file
|
||||||
|
/// </summary>
|
||||||
|
private async void SaveWindowPlacementFile(string path, string filename)
|
||||||
|
{
|
||||||
|
StorageFolder storageFolder = null;
|
||||||
|
StorageFile storageFile = null;
|
||||||
|
string fileContents = string.Empty;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
storageFolder = await StorageFolder.GetFolderFromPathAsync(path);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(ex.Message);
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
storageFolder = await StorageFolder.GetFolderFromPathAsync(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
storageFile = await storageFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(ex.Message);
|
||||||
|
storageFile = await storageFolder.CreateFileAsync(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (jsonWindowPlacement != null)
|
||||||
|
{
|
||||||
|
fileContents = jsonWindowPlacement.Stringify();
|
||||||
|
await Windows.Storage.FileIO.WriteTextAsync(storageFile, fileContents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<Import Project="..\..\..\Version.props" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows10.0.20348.0</TargetFramework>
|
||||||
|
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>
|
||||||
|
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
|
||||||
|
<RootNamespace>RegistryPreview</RootNamespace>
|
||||||
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
|
<Platforms>x86;x64;ARM64</Platforms>
|
||||||
|
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
|
||||||
|
<UseWinUI>true</UseWinUI>
|
||||||
|
<EnableMsixTooling>true</EnableMsixTooling>
|
||||||
|
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
|
||||||
|
<WindowsPackageType>None</WindowsPackageType>
|
||||||
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
|
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||||
|
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
|
||||||
|
<SelfContained>true</SelfContained>
|
||||||
|
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps</OutputPath>
|
||||||
|
<AssemblyName>PowerToys.RegistryPreview</AssemblyName>
|
||||||
|
<ApplicationIcon>Assets\RegistryPreview\RegistryPreview.ico</ApplicationIcon>
|
||||||
|
<!-- MRT from windows app sdk will search for a pri file with the same name of the module before defaulting to resources.pri -->
|
||||||
|
<ProjectPriFileName>PowerToys.RegistryPreview.pri</ProjectPriFileName>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Page Remove="RegistryPreviewXAML\App.xaml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ApplicationDefinition Include="RegistryPreviewXAML\App.xaml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="RegistryPreviewXAML\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- SelfContained=true requires RuntimeIdentifier to be set -->
|
||||||
|
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||||
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Platform)'=='ARM64'">
|
||||||
|
<RuntimeIdentifier>win-arm64</RuntimeIdentifier>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" />
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" />
|
||||||
|
<PackageReference Include="CommunityToolkit.WinUI.Extensions" />
|
||||||
|
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
||||||
|
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
||||||
|
<PackageReference Include="WinUIEx" />
|
||||||
|
<Manifest Include="$(ApplicationManifest)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
|
||||||
|
Tools extension to be activated for this project even if the Windows App SDK Nuget
|
||||||
|
package has not yet been restored.
|
||||||
|
-->
|
||||||
|
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||||
|
<ProjectCapability Include="Msix" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- HACK: Common.UI is referenced, even if it is not used, to force dll versions to be the same as in other projects that use it. It's still unclear why this is the case, but this is need for flattening the install directory. -->
|
||||||
|
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||||
|
<ProjectReference Include="..\RegistryPreviewUILib\RegistryPreviewUILib.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="CopyPRIFileToOutputDir" AfterTargets="Build">
|
||||||
|
<Message Text="Executing CopyDLLs task" Importance="High" />
|
||||||
|
<ItemGroup>
|
||||||
|
<PRIFile Include="$(OutDir)**\PowerToys.RegistryPreviewUILib.pri" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Copy SourceFiles="@(PRIFile)" DestinationFolder="$(OutDir)" />
|
||||||
|
|
||||||
|
<Message Text="Copied build files" Importance="High" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
|
||||||
|
Explorer "Package and Publish" context menu entry to be enabled for this project even if
|
||||||
|
the Windows App SDK Nuget package has not yet been restored.
|
||||||
|
-->
|
||||||
|
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||||
|
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -1,4 +1,5 @@
|
|||||||
<Application
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<Application
|
||||||
x:Class="RegistryPreview.App"
|
x:Class="RegistryPreview.App"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
@ -3,14 +3,13 @@
|
|||||||
// 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 System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.Windows.AppLifecycle;
|
using Microsoft.Windows.AppLifecycle;
|
||||||
using Windows.ApplicationModel.Activation;
|
using Windows.ApplicationModel.Activation;
|
||||||
using LaunchActivatedEventArgs = Windows.ApplicationModel.Activation.LaunchActivatedEventArgs;
|
|
||||||
|
|
||||||
|
// To learn more about WinUI, the WinUI project structure,
|
||||||
|
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||||
namespace RegistryPreview
|
namespace RegistryPreview
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -20,6 +19,8 @@ namespace RegistryPreview
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="App"/> class.
|
/// Initializes a new instance of the <see cref="App"/> class.
|
||||||
|
/// Initializes the singleton application object. This is the first line of authored code
|
||||||
|
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
@ -27,8 +28,7 @@ namespace RegistryPreview
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when the application is launched normally by the end user. Other entry points
|
/// Invoked when the application is launched.
|
||||||
/// will be used such as when the application is launched to open a specific file.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="args">Details about the launch request and process.</param>
|
/// <param name="args">Details about the launch request and process.</param>
|
||||||
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
@ -0,0 +1,52 @@
|
|||||||
|
<winuiex:WindowEx
|
||||||
|
x:Class="RegistryPreview.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:tk7controls="using:CommunityToolkit.WinUI.UI.Controls"
|
||||||
|
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
|
||||||
|
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||||
|
xmlns:winuiex="using:WinUIEx"
|
||||||
|
MinWidth="480"
|
||||||
|
MinHeight="320"
|
||||||
|
Closed="Window_Closed"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
<Window.SystemBackdrop>
|
||||||
|
<MicaBackdrop />
|
||||||
|
</Window.SystemBackdrop>
|
||||||
|
|
||||||
|
<Grid x:Name="MainGrid" Loaded="Grid_Loaded">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid
|
||||||
|
x:Name="titleBar"
|
||||||
|
Grid.Row="0"
|
||||||
|
Height="32"
|
||||||
|
Margin="16,0"
|
||||||
|
ColumnSpacing="16"
|
||||||
|
IsHitTestVisible="True">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<!--<ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>-->
|
||||||
|
<ColumnDefinition x:Name="IconColumn" Width="Auto" />
|
||||||
|
<ColumnDefinition x:Name="TitleColumn" Width="Auto" />
|
||||||
|
<!--<ColumnDefinition x:Name="RightPaddingColumn" Width="0"/>-->
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Image
|
||||||
|
Grid.Column="0"
|
||||||
|
Width="16"
|
||||||
|
Height="16"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Source="../Assets/RegistryPreview/RegistryPreview.ico" />
|
||||||
|
<TextBlock
|
||||||
|
x:Name="titleBarText"
|
||||||
|
Grid.Column="1"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Style="{StaticResource CaptionTextBlockStyle}"
|
||||||
|
Text="{Binding ApplicationTitle}" />
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</winuiex:WindowEx>
|
@ -1,16 +1,14 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// 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 System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Microsoft.UI;
|
using Microsoft.UI;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
using Microsoft.Windows.ApplicationModel.Resources;
|
using RegistryPreviewUILib;
|
||||||
using Windows.Data.Json;
|
using Windows.Data.Json;
|
||||||
using Windows.Graphics;
|
using Windows.Graphics;
|
||||||
using WinUIEx;
|
using WinUIEx;
|
||||||
@ -20,39 +18,31 @@ namespace RegistryPreview
|
|||||||
public sealed partial class MainWindow : WindowEx
|
public sealed partial class MainWindow : WindowEx
|
||||||
{
|
{
|
||||||
// Const values
|
// Const values
|
||||||
private const string REGISTRYHEADER4 = "regedit4";
|
|
||||||
private const string REGISTRYHEADER5 = "windows registry editor version 5.00";
|
|
||||||
private const string APPNAME = "RegistryPreview";
|
private const string APPNAME = "RegistryPreview";
|
||||||
private const string KEYIMAGE = "ms-appx:///Assets/RegistryPreview/folder32.png";
|
|
||||||
private const string DELETEDKEYIMAGE = "ms-appx:///Assets/RegistryPreview/deleted-folder32.png";
|
|
||||||
private const string ERRORIMAGE = "ms-appx:///Assets/RegistryPreview/error32.png";
|
|
||||||
|
|
||||||
// private members
|
// private members
|
||||||
private Microsoft.UI.Windowing.AppWindow appWindow;
|
private Microsoft.UI.Windowing.AppWindow appWindow;
|
||||||
private ResourceLoader resourceLoader;
|
|
||||||
private bool visualTreeReady;
|
|
||||||
private Dictionary<string, TreeViewNode> mapRegistryKeys;
|
|
||||||
private List<RegistryValue> listRegistryValues;
|
|
||||||
private JsonObject jsonWindowPlacement;
|
private JsonObject jsonWindowPlacement;
|
||||||
private string settingsFolder = string.Empty;
|
private string settingsFolder = string.Empty;
|
||||||
private string windowPlacementFile = "app-placement.json";
|
private string windowPlacementFile = "app-placement.json";
|
||||||
|
|
||||||
|
private RegistryPreviewMainPage MainPage { get; }
|
||||||
|
|
||||||
internal MainWindow()
|
internal MainWindow()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
|
|
||||||
// Initialize the string table
|
|
||||||
resourceLoader = ResourceLoaderInstance.ResourceLoader;
|
|
||||||
|
|
||||||
// Open settings file; this moved to after the window tweak because it gives the window time to start up
|
// Open settings file; this moved to after the window tweak because it gives the window time to start up
|
||||||
settingsFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\PowerToys\" + APPNAME;
|
settingsFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\PowerToys\" + APPNAME;
|
||||||
OpenWindowPlacementFile(settingsFolder, windowPlacementFile);
|
OpenWindowPlacementFile(settingsFolder, windowPlacementFile);
|
||||||
|
|
||||||
// Update the Win32 looking window with the correct icon (and grab the appWindow handle for later)
|
// Update the Win32 looking window with the correct icon (and grab the appWindow handle for later)
|
||||||
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||||
WindowId windowId = Win32Interop.GetWindowIdFromWindow(windowHandle);
|
Microsoft.UI.WindowId windowId = Win32Interop.GetWindowIdFromWindow(windowHandle);
|
||||||
appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
|
appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
|
||||||
appWindow.SetIcon("Assets\\RegistryPreview\\app.ico");
|
appWindow.SetIcon("Assets\\RegistryPreview\\RegistryPreview.ico");
|
||||||
|
|
||||||
|
// TODO(stefan)
|
||||||
appWindow.Closing += AppWindow_Closing;
|
appWindow.Closing += AppWindow_Closing;
|
||||||
Activated += MainWindow_Activated;
|
Activated += MainWindow_Activated;
|
||||||
|
|
||||||
@ -92,12 +82,7 @@ namespace RegistryPreview
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Toolbar
|
MainPage = new RegistryPreviewMainPage(this, this.UpdateWindowTitle, App.AppFilename);
|
||||||
if ((App.AppFilename == null) || (File.Exists(App.AppFilename) != true))
|
|
||||||
{
|
|
||||||
UpdateToolBarAndUI(false);
|
|
||||||
UpdateWindowTitle(resourceLoader.GetString("FileNotFound"));
|
|
||||||
}
|
|
||||||
|
|
||||||
WindowHelpers.BringToForeground(windowHandle);
|
WindowHelpers.BringToForeground(windowHandle);
|
||||||
}
|
}
|
||||||
@ -107,12 +92,44 @@ namespace RegistryPreview
|
|||||||
if (args.WindowActivationState == WindowActivationState.Deactivated)
|
if (args.WindowActivationState == WindowActivationState.Deactivated)
|
||||||
{
|
{
|
||||||
titleBarText.Foreground =
|
titleBarText.Foreground =
|
||||||
(SolidColorBrush)App.Current.Resources["WindowCaptionForegroundDisabled"];
|
(SolidColorBrush)Application.Current.Resources["WindowCaptionForegroundDisabled"];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
titleBarText.Foreground =
|
titleBarText.Foreground =
|
||||||
(SolidColorBrush)App.Current.Resources["WindowCaptionForeground"];
|
(SolidColorBrush)Application.Current.Resources["WindowCaptionForeground"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Grid_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
MainGrid.Children.Add(MainPage);
|
||||||
|
Grid.SetRow(MainPage, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateWindowTitle(string title)
|
||||||
|
{
|
||||||
|
string filename = title;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(filename))
|
||||||
|
{
|
||||||
|
titleBarText.Text = APPNAME;
|
||||||
|
appWindow.Title = APPNAME;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string[] file = filename.Split('\\');
|
||||||
|
if (file.Length > 0)
|
||||||
|
{
|
||||||
|
titleBarText.Text = file[file.Length - 1] + " - " + APPNAME;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
titleBarText.Text = filename + " - " + APPNAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continue to update the window's title, after updating the custom title bar
|
||||||
|
appWindow.Title = titleBarText.Text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|