mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +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);
|
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;
|
string fileContents = string.Empty;
|
||||||
|
string storageFile = Path.Combine(path, filename);
|
||||||
try
|
if (File.Exists(storageFile))
|
||||||
{
|
{
|
||||||
storageFolder = await StorageFolder.GetFolderFromPathAsync(path);
|
try
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (storageFolder != null)
|
|
||||||
{
|
{
|
||||||
storageFile = await storageFolder.GetFileAsync(filename);
|
TextReader reader = new StreamReader(storageFile);
|
||||||
|
fileContents = reader.ReadToEnd();
|
||||||
|
reader.Close();
|
||||||
}
|
}
|
||||||
}
|
catch
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (storageFile != null)
|
|
||||||
{
|
{
|
||||||
fileContents = await Windows.Storage.FileIO.ReadTextAsync(storageFile);
|
// set up default JSON blob
|
||||||
|
fileContents = "{ }";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,9 +40,10 @@ namespace RegistryPreview
|
|||||||
// Initialize the string table
|
// Initialize the string table
|
||||||
resourceLoader = ResourceLoader.GetForViewIndependentUse();
|
resourceLoader = ResourceLoader.GetForViewIndependentUse();
|
||||||
|
|
||||||
// Removed this on 2/15/23 as it doesn't seem to be doing anything any more
|
// Open settings file; this moved to after the window tweak because it gives the window time to start up
|
||||||
// Attempts to force the visual tree to load faster
|
settingsFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\PowerToys\" + APPNAME;
|
||||||
// this.Activate();
|
settingsFile = APPNAME + "_settings.json";
|
||||||
|
OpenSettingsFile(settingsFolder, settingsFile);
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -51,36 +52,27 @@ namespace RegistryPreview
|
|||||||
appWindow.SetIcon("app.ico");
|
appWindow.SetIcon("app.ico");
|
||||||
appWindow.Closing += AppWindow_Closing;
|
appWindow.Closing += AppWindow_Closing;
|
||||||
|
|
||||||
// Open settings file; this moved to after the window tweak because it gives the window time to start up
|
// if have settings, update the location of the window
|
||||||
settingsFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\PowerToys\" + APPNAME;
|
if (jsonSettings != null)
|
||||||
settingsFile = APPNAME + "_settings.json";
|
{
|
||||||
OpenSettingsFile(settingsFolder, settingsFile);
|
// 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
|
// reposition the window
|
||||||
// Calling it from here only successfully resizes/moves the window and it seems to be based off timing, which is horrible.
|
if (jsonSettings.ContainsKey("appWindow.Position.X") && jsonSettings.ContainsKey("appWindow.Position.Y"))
|
||||||
// Calling it from GridPreview_Loaded() works 100% of the time, but the initial state of the window flashes before sizing/moving it
|
{
|
||||||
//
|
PointInt32 point;
|
||||||
// // if have settings, update the location of the window
|
point.X = (int)jsonSettings.GetNamedNumber("appWindow.Position.X");
|
||||||
// if (jsonSettings != null)
|
point.Y = (int)jsonSettings.GetNamedNumber("appWindow.Position.Y");
|
||||||
// {
|
appWindow.Move(point);
|
||||||
// // 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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Update Toolbar
|
// Update Toolbar
|
||||||
if ((App.AppFilename == null) || (File.Exists(App.AppFilename) != true))
|
if ((App.AppFilename == null) || (File.Exists(App.AppFilename) != true))
|
||||||
|
|||||||
Reference in New Issue
Block a user