mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
Registry Preview: Cleanup of the resizing/moving logic on start up (#25064)
* Updating resizing logic Changed to the non-async version of reading a file. * Using and comment cleanups
This commit is contained in:
@@ -733,41 +733,24 @@ namespace RegistryPreview
|
||||
ChangeCursor(gridPreview, false);
|
||||
}
|
||||
|
||||
private async void OpenSettingsFile(string path, string filename)
|
||||
private void OpenSettingsFile(string path, string filename)
|
||||
{
|
||||
StorageFolder storageFolder = null;
|
||||
StorageFile storageFile = null;
|
||||
string fileContents = string.Empty;
|
||||
|
||||
try
|
||||
string storageFile = Path.Combine(path, filename);
|
||||
if (File.Exists(storageFile))
|
||||
{
|
||||
storageFolder = await StorageFolder.GetFolderFromPathAsync(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (storageFolder != null)
|
||||
try
|
||||
{
|
||||
storageFile = await storageFolder.GetFileAsync(filename);
|
||||
TextReader reader = new StreamReader(storageFile);
|
||||
fileContents = reader.ReadToEnd();
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (storageFile != null)
|
||||
catch
|
||||
{
|
||||
fileContents = await Windows.Storage.FileIO.ReadTextAsync(storageFile);
|
||||
// set up default JSON blob
|
||||
fileContents = "{ }";
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -40,9 +40,10 @@ namespace RegistryPreview
|
||||
// Initialize the string table
|
||||
resourceLoader = ResourceLoader.GetForViewIndependentUse();
|
||||
|
||||
// Removed this on 2/15/23 as it doesn't seem to be doing anything any more
|
||||
// Attempts to force the visual tree to load faster
|
||||
// this.Activate();
|
||||
// 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);
|
||||
|
||||
// Update the Win32 looking window with the correct icon (and grab the appWindow handle for later)
|
||||
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
@@ -51,36 +52,27 @@ namespace RegistryPreview
|
||||
appWindow.SetIcon("app.ico");
|
||||
appWindow.Closing += AppWindow_Closing;
|
||||
|
||||
// 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);
|
||||
// if have settings, update the location of the window
|
||||
if (jsonSettings != null)
|
||||
{
|
||||
// resize the window
|
||||
if (jsonSettings.ContainsKey("appWindow.Size.Width") && jsonSettings.ContainsKey("appWindow.Size.Height"))
|
||||
{
|
||||
SizeInt32 size;
|
||||
size.Width = (int)jsonSettings.GetNamedNumber("appWindow.Size.Width");
|
||||
size.Height = (int)jsonSettings.GetNamedNumber("appWindow.Size.Height");
|
||||
appWindow.Resize(size);
|
||||
}
|
||||
|
||||
// TODO: figure out a way to only call this once after MainWindow is initialized but before it shows itself
|
||||
// Calling it from here only successfully resizes/moves the window and it seems to be based off timing, which is horrible.
|
||||
// Calling it from GridPreview_Loaded() works 100% of the time, but the initial state of the window flashes before sizing/moving it
|
||||
//
|
||||
// // if have settings, update the location of the window
|
||||
// if (jsonSettings != null)
|
||||
// {
|
||||
// // resize the window
|
||||
// if (jsonSettings.ContainsKey("appWindow.Size.Width") && jsonSettings.ContainsKey("appWindow.Size.Height"))
|
||||
// {
|
||||
// SizeInt32 size;
|
||||
// size.Width = (int)jsonSettings.GetNamedNumber("appWindow.Size.Width");
|
||||
// size.Height = (int)jsonSettings.GetNamedNumber("appWindow.Size.Height");
|
||||
// appWindow.Resize(size);
|
||||
// }
|
||||
//
|
||||
// // reposition the window
|
||||
// if (jsonSettings.ContainsKey("appWindow.Position.X") && jsonSettings.ContainsKey("appWindow.Position.Y"))
|
||||
// {
|
||||
// PointInt32 point;
|
||||
// point.X = (int)jsonSettings.GetNamedNumber("appWindow.Position.X");
|
||||
// point.Y = (int)jsonSettings.GetNamedNumber("appWindow.Position.Y");
|
||||
// appWindow.Move(point);
|
||||
// }
|
||||
// }
|
||||
// reposition the window
|
||||
if (jsonSettings.ContainsKey("appWindow.Position.X") && jsonSettings.ContainsKey("appWindow.Position.Y"))
|
||||
{
|
||||
PointInt32 point;
|
||||
point.X = (int)jsonSettings.GetNamedNumber("appWindow.Position.X");
|
||||
point.Y = (int)jsonSettings.GetNamedNumber("appWindow.Position.Y");
|
||||
appWindow.Move(point);
|
||||
}
|
||||
}
|
||||
|
||||
// Update Toolbar
|
||||
if ((App.AppFilename == null) || (File.Exists(App.AppFilename) != true))
|
||||
|
||||
Reference in New Issue
Block a user