mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
[Settings]Theme override fix and cleanup (#32362)
* theme override fix and cleanup * test fix
This commit is contained in:
committed by
GitHub
parent
fba5f6f002
commit
b14aa8276d
58
src/settings-ui/Settings.UI/Helpers/WindowHelper.cs
Normal file
58
src/settings-ui/Settings.UI/Helpers/WindowHelper.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
// 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.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||
{
|
||||
internal sealed class WindowHelper
|
||||
{
|
||||
private static string _placementPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\PowerToys\settings-placement.json");
|
||||
|
||||
public static WINDOWPLACEMENT DeserializePlacementOrDefault(IntPtr handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(_placementPath);
|
||||
var placement = JsonSerializer.Deserialize<WINDOWPLACEMENT>(json);
|
||||
|
||||
placement.Length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
|
||||
placement.Flags = 0;
|
||||
placement.ShowCmd = (placement.ShowCmd == NativeMethods.SW_SHOWMAXIMIZED) ? NativeMethods.SW_SHOWMAXIMIZED : NativeMethods.SW_SHOWNORMAL;
|
||||
return placement;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
_ = NativeMethods.GetWindowPlacement(handle, out var defaultPlacement);
|
||||
return defaultPlacement;
|
||||
}
|
||||
|
||||
public static void SerializePlacement(IntPtr handle)
|
||||
{
|
||||
_ = NativeMethods.GetWindowPlacement(handle, out var placement);
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(placement);
|
||||
File.WriteAllText(_placementPath, json);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetTheme(Window window, ElementTheme theme)
|
||||
{
|
||||
if (window.Content is FrameworkElement rootElement)
|
||||
{
|
||||
rootElement.RequestedTheme = theme;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user