mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-12 18:29:24 +08:00
[Registry Preview] * Two settings folders reduces to one. (#26842)
* [Registry Preview] * Two settings folders reduces to one. * Two settings files reduced to one. * Folder creation if not exist added. * Add size/position properties to fix saving from Settings app * Separate settings.json and app-placement.json --------- Co-authored-by: Stefan Markovic <stefan@janeasystems.com>
This commit is contained in:
parent
8dcdcbaa37
commit
1b9094ae2b
@ -29,10 +29,10 @@ namespace RegistryPreview
|
||||
/// </summary>
|
||||
private void AppWindow_Closing(Microsoft.UI.Windowing.AppWindow sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs args)
|
||||
{
|
||||
jsonSettings.SetNamedValue("appWindow.Position.X", JsonValue.CreateNumberValue(appWindow.Position.X));
|
||||
jsonSettings.SetNamedValue("appWindow.Position.Y", JsonValue.CreateNumberValue(appWindow.Position.Y));
|
||||
jsonSettings.SetNamedValue("appWindow.Size.Width", JsonValue.CreateNumberValue(appWindow.Size.Width));
|
||||
jsonSettings.SetNamedValue("appWindow.Size.Height", JsonValue.CreateNumberValue(appWindow.Size.Height));
|
||||
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>
|
||||
@ -55,8 +55,8 @@ namespace RegistryPreview
|
||||
resourceLoader.GetString("YesNoCancelDialogCloseButtonText"));
|
||||
}
|
||||
|
||||
// Save app settings
|
||||
SaveSettingsFile(settingsFolder, settingsFile);
|
||||
// Save window placement
|
||||
SaveWindowPlacementFile(settingsFolder, windowPlacementFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -9,6 +9,7 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.UI.Input;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
@ -842,7 +843,7 @@ namespace RegistryPreview
|
||||
ChangeCursor(gridPreview, false);
|
||||
}
|
||||
|
||||
private void OpenSettingsFile(string path, string filename)
|
||||
private void OpenWindowPlacementFile(string path, string filename)
|
||||
{
|
||||
string fileContents = string.Empty;
|
||||
string storageFile = Path.Combine(path, filename);
|
||||
@ -860,23 +861,27 @@ namespace RegistryPreview
|
||||
fileContents = "{ }";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.Run(() => SaveWindowPlacementFile(path, filename)).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
jsonSettings = Windows.Data.Json.JsonObject.Parse(fileContents);
|
||||
jsonWindowPlacement = Windows.Data.Json.JsonObject.Parse(fileContents);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// set up default JSON blob
|
||||
fileContents = "{ }";
|
||||
jsonSettings = Windows.Data.Json.JsonObject.Parse(fileContents);
|
||||
jsonWindowPlacement = Windows.Data.Json.JsonObject.Parse(fileContents);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save the settings JSON blob out to a local file
|
||||
/// Save the window placement JSON blob out to a local file
|
||||
/// </summary>
|
||||
private async void SaveSettingsFile(string path, string filename)
|
||||
private async void SaveWindowPlacementFile(string path, string filename)
|
||||
{
|
||||
StorageFolder storageFolder = null;
|
||||
StorageFile storageFile = null;
|
||||
@ -905,7 +910,7 @@ namespace RegistryPreview
|
||||
|
||||
try
|
||||
{
|
||||
fileContents = jsonSettings.Stringify();
|
||||
fileContents = jsonWindowPlacement.Stringify();
|
||||
await Windows.Storage.FileIO.WriteTextAsync(storageFile, fileContents);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -30,9 +30,9 @@ namespace RegistryPreview
|
||||
private bool visualTreeReady;
|
||||
private Dictionary<string, TreeViewNode> mapRegistryKeys;
|
||||
private List<RegistryValue> listRegistryValues;
|
||||
private JsonObject jsonSettings;
|
||||
private JsonObject jsonWindowPlacement;
|
||||
private string settingsFolder = string.Empty;
|
||||
private string settingsFile = string.Empty;
|
||||
private string windowPlacementFile = "app-placement.json";
|
||||
|
||||
internal MainWindow()
|
||||
{
|
||||
@ -43,8 +43,7 @@ namespace RegistryPreview
|
||||
|
||||
// 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;
|
||||
settingsFile = APPNAME + "_settings.json";
|
||||
OpenSettingsFile(settingsFolder, settingsFile);
|
||||
OpenWindowPlacementFile(settingsFolder, windowPlacementFile);
|
||||
|
||||
// Update the Win32 looking window with the correct icon (and grab the appWindow handle for later)
|
||||
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
@ -58,14 +57,14 @@ namespace RegistryPreview
|
||||
SetTitleBar(titleBar);
|
||||
|
||||
// if have settings, update the location of the window
|
||||
if (jsonSettings != null)
|
||||
if (jsonWindowPlacement != null)
|
||||
{
|
||||
// resize the window
|
||||
if (jsonSettings.ContainsKey("appWindow.Size.Width") && jsonSettings.ContainsKey("appWindow.Size.Height"))
|
||||
if (jsonWindowPlacement.ContainsKey("appWindow.Size.Width") && jsonWindowPlacement.ContainsKey("appWindow.Size.Height"))
|
||||
{
|
||||
SizeInt32 size;
|
||||
size.Width = (int)jsonSettings.GetNamedNumber("appWindow.Size.Width");
|
||||
size.Height = (int)jsonSettings.GetNamedNumber("appWindow.Size.Height");
|
||||
size.Width = (int)jsonWindowPlacement.GetNamedNumber("appWindow.Size.Width");
|
||||
size.Height = (int)jsonWindowPlacement.GetNamedNumber("appWindow.Size.Height");
|
||||
|
||||
// check to make sure the size values are reasonable before attempting to restore the last saved size
|
||||
if (size.Width >= 320 && size.Height >= 240)
|
||||
@ -75,11 +74,11 @@ namespace RegistryPreview
|
||||
}
|
||||
|
||||
// reposition the window
|
||||
if (jsonSettings.ContainsKey("appWindow.Position.X") && jsonSettings.ContainsKey("appWindow.Position.Y"))
|
||||
if (jsonWindowPlacement.ContainsKey("appWindow.Position.X") && jsonWindowPlacement.ContainsKey("appWindow.Position.Y"))
|
||||
{
|
||||
PointInt32 point;
|
||||
point.X = (int)jsonSettings.GetNamedNumber("appWindow.Position.X");
|
||||
point.Y = (int)jsonSettings.GetNamedNumber("appWindow.Position.Y");
|
||||
point.X = (int)jsonWindowPlacement.GetNamedNumber("appWindow.Position.X");
|
||||
point.Y = (int)jsonWindowPlacement.GetNamedNumber("appWindow.Position.Y");
|
||||
|
||||
// check to make sure the move values are reasonable before attempting to restore the last saved location
|
||||
if (point.X >= 0 && point.Y >= 0)
|
||||
|
Loading…
Reference in New Issue
Block a user