From 413624397e176f9ae512c861cce44b5db564244f Mon Sep 17 00:00:00 2001 From: Andrey Nekrasov Date: Tue, 17 Oct 2023 18:35:49 +0200 Subject: [PATCH 1/8] [VCM]Do not trigger cascade of un/mute changes (#29131) --- .../VideoConferenceModule.cpp | 21 ------------------- .../VideoConferenceModule.h | 1 - 2 files changed, 22 deletions(-) diff --git a/src/modules/videoconference/VideoConferenceModule/VideoConferenceModule.cpp b/src/modules/videoconference/VideoConferenceModule/VideoConferenceModule.cpp index 5f2825c940..fa692895f4 100644 --- a/src/modules/videoconference/VideoConferenceModule/VideoConferenceModule.cpp +++ b/src/modules/videoconference/VideoConferenceModule/VideoConferenceModule.cpp @@ -342,7 +342,6 @@ void VideoConferenceModule::onMicrophoneConfigurationChanged() toolbar.setMicrophoneMute(muted); }); } - setMuteChangedCallback(); } VideoConferenceModule::VideoConferenceModule() @@ -406,25 +405,6 @@ void VideoConferenceModule::set_config(const wchar_t* config) } } -void VideoConferenceModule::setMuteChangedCallback() -{ - // Keep all controlledMic mute state same _microphoneTrackedInUI - // Should not change manually in Control Panel - for (const auto& controlledMic : _controlledMicrophones) - { - if (controlledMic->id() != _microphoneTrackedInUI->id()) - { - controlledMic->set_mute_changed_callback([&](const bool muted) { - auto muteState = getMicrophoneMuteState(); - if (muted != muteState) - { - controlledMic->set_muted(muteState); - } - }); - } - } -} - void VideoConferenceModule::init_settings() { try @@ -552,7 +532,6 @@ void VideoConferenceModule::updateControlledMicrophones(const std::wstring_view controlledMic->set_muted(true); } } - setMuteChangedCallback(); } MicrophoneDevice* VideoConferenceModule::controlledDefaultMic() diff --git a/src/modules/videoconference/VideoConferenceModule/VideoConferenceModule.h b/src/modules/videoconference/VideoConferenceModule/VideoConferenceModule.h index 6e327df25b..f3b835867a 100644 --- a/src/modules/videoconference/VideoConferenceModule/VideoConferenceModule.h +++ b/src/modules/videoconference/VideoConferenceModule/VideoConferenceModule.h @@ -73,7 +73,6 @@ public: private: - void setMuteChangedCallback(); void init_settings(); void updateControlledMicrophones(const std::wstring_view new_mic); MicrophoneDevice* controlledDefaultMic(); From ec47805634d31392c613bd54cf11f46c5caf0db2 Mon Sep 17 00:00:00 2001 From: gokcekantarci <115616017+gokcekantarci@users.noreply.github.com> Date: Tue, 17 Oct 2023 19:53:20 +0300 Subject: [PATCH 2/8] [STLThumbnail]Fix crashes on invalid files (#29172) * [StlThumbnailProvider] STL reader is added to try catch block. Model checks are increased. * [StlThumbnailProvider] Spellcheck fix --- .../StlThumbnailProvider.cs | 95 ++++++++++--------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/src/modules/previewpane/StlThumbnailProvider/StlThumbnailProvider.cs b/src/modules/previewpane/StlThumbnailProvider/StlThumbnailProvider.cs index aeecf4599a..ea0b033bdc 100644 --- a/src/modules/previewpane/StlThumbnailProvider/StlThumbnailProvider.cs +++ b/src/modules/previewpane/StlThumbnailProvider/StlThumbnailProvider.cs @@ -2,11 +2,9 @@ // 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.IO; -using System.Runtime.InteropServices.ComTypes; using System.Windows; using System.Windows.Media; using System.Windows.Media.Media3D; -using Common.Utilities; using HelixToolkit.Wpf; using Microsoft.PowerToys.Settings.UI.Library; using Bitmap = System.Drawing.Bitmap; @@ -61,54 +59,61 @@ namespace Microsoft.PowerToys.ThumbnailHandler.Stl DefaultMaterial = new DiffuseMaterial(new SolidColorBrush(DefaultMaterialColor)), }; - var model = stlReader.Read(stream); + try + { + var model = stlReader.Read(stream); - if (model.Bounds == Rect3D.Empty) + if (model == null || model.Children.Count == 0 || model.Bounds == Rect3D.Empty) + { + return null; + } + + var viewport = new System.Windows.Controls.Viewport3D(); + + viewport.Measure(new System.Windows.Size(cx, cx)); + viewport.Arrange(new Rect(0, 0, cx, cx)); + + var modelVisual = new ModelVisual3D() + { + Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 180)), + }; + viewport.Children.Add(modelVisual); + viewport.Children.Add(new DefaultLights()); + + var perspectiveCamera = new PerspectiveCamera + { + Position = new Point3D(1, 2, 1), + LookDirection = new Vector3D(-1, -2, -1), + UpDirection = new Vector3D(0, 0, 1), + FieldOfView = 20, + NearPlaneDistance = 0.1, + FarPlaneDistance = double.PositiveInfinity, + }; + viewport.Camera = perspectiveCamera; + + modelVisual.Content = model; + + perspectiveCamera.ZoomExtents(viewport); + + var bitmapExporter = new BitmapExporter + { + Background = new SolidColorBrush(Colors.Transparent), + OversamplingMultiplier = 1, + }; + + var bitmapStream = new MemoryStream(); + + bitmapExporter.Export(viewport, bitmapStream); + + bitmapStream.Position = 0; + + thumbnail = new Bitmap(bitmapStream); + } + catch (Exception) { return null; } - var viewport = new System.Windows.Controls.Viewport3D(); - - viewport.Measure(new System.Windows.Size(cx, cx)); - viewport.Arrange(new Rect(0, 0, cx, cx)); - - var modelVisual = new ModelVisual3D() - { - Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 180)), - }; - viewport.Children.Add(modelVisual); - viewport.Children.Add(new DefaultLights()); - - var perspectiveCamera = new PerspectiveCamera - { - Position = new Point3D(1, 2, 1), - LookDirection = new Vector3D(-1, -2, -1), - UpDirection = new Vector3D(0, 0, 1), - FieldOfView = 20, - NearPlaneDistance = 0.1, - FarPlaneDistance = double.PositiveInfinity, - }; - viewport.Camera = perspectiveCamera; - - modelVisual.Content = model; - - perspectiveCamera.ZoomExtents(viewport); - - var bitmapExporter = new BitmapExporter - { - Background = new SolidColorBrush(Colors.Transparent), - OversamplingMultiplier = 1, - }; - - var bitmapStream = new MemoryStream(); - - bitmapExporter.Export(viewport, bitmapStream); - - bitmapStream.Position = 0; - - thumbnail = new Bitmap(bitmapStream); - return thumbnail; } From cd99a2e8488e3376fb012fcd996d2933307a580c Mon Sep 17 00:00:00 2001 From: Garrett Vernon <70212190+garv5014@users.noreply.github.com> Date: Wed, 18 Oct 2023 01:07:48 -0600 Subject: [PATCH 3/8] [FZ Editor]Add tests to editor #197 + feedback (#29051) * here are the tests for the fancy zones * Wrote tests for GridLayoutModel * Move FancyZonesEditor tests to right place, tests for default layout model * fixed SettingTheVerticalLayoutShouldBeTheDefault test * removed coverlet in the test project * Fixes for comments on pr * squashed and updated for comments * Added the test to the pipeline --------- Co-authored-by: Drew Gordon Co-authored-by: Caleb Wightman --- .../ci/templates/build-powertoys-steps.yml | 1 + PowerToys.sln | 15 +++ .../DefaultLayoutsModelTests.cs | 59 ++++++++++++ .../GridLayoutModelTests.cs | 95 +++++++++++++++++++ .../UnitTests-FancyZonesEditor.csproj | 29 ++++++ .../UnitTests-FancyZonesEditor/Usings.cs | 5 + 6 files changed, 204 insertions(+) create mode 100644 src/modules/fancyzones/UnitTests-FancyZonesEditor/DefaultLayoutsModelTests.cs create mode 100644 src/modules/fancyzones/UnitTests-FancyZonesEditor/GridLayoutModelTests.cs create mode 100644 src/modules/fancyzones/UnitTests-FancyZonesEditor/UnitTests-FancyZonesEditor.csproj create mode 100644 src/modules/fancyzones/UnitTests-FancyZonesEditor/Usings.cs diff --git a/.pipelines/ci/templates/build-powertoys-steps.yml b/.pipelines/ci/templates/build-powertoys-steps.yml index b9bb635f88..ba7aec6f36 100644 --- a/.pipelines/ci/templates/build-powertoys-steps.yml +++ b/.pipelines/ci/templates/build-powertoys-steps.yml @@ -197,6 +197,7 @@ steps: **\UnitTests-PdfThumbnailProvider.dll **\Settings.UI.UnitTests.dll **\UnitTests-GcodePreviewHandler.dll + **\UnitTests-FancyZonesEditor.dll **\UnitTests-PdfPreviewHandler.dll **\UnitTests-PreviewHandlerCommon.dll **\Microsoft.PowerToys.Run.Plugin.Registry.UnitTests.dll diff --git a/PowerToys.sln b/PowerToys.sln index f0d4f78656..d629d970d4 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -537,6 +537,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CropAndLock", "src\modules\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CropAndLockModuleInterface", "src\modules\CropAndLock\CropAndLockModuleInterface\CropAndLockModuleInterface.vcxproj", "{3157FA75-86CF-4EE2-8F62-C43F776493C6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests-FancyZonesEditor", "src\modules\fancyzones\UnitTests-FancyZonesEditor\UnitTests-FancyZonesEditor.csproj", "{FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -2307,6 +2309,18 @@ Global {3157FA75-86CF-4EE2-8F62-C43F776493C6}.Release|x64.Build.0 = Release|x64 {3157FA75-86CF-4EE2-8F62-C43F776493C6}.Release|x86.ActiveCfg = Release|x64 {3157FA75-86CF-4EE2-8F62-C43F776493C6}.Release|x86.Build.0 = Release|x64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Debug|ARM64.Build.0 = Debug|ARM64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Debug|x64.ActiveCfg = Debug|x64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Debug|x64.Build.0 = Debug|x64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Debug|x86.ActiveCfg = Debug|x64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Debug|x86.Build.0 = Debug|x64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Release|ARM64.ActiveCfg = Release|ARM64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Release|ARM64.Build.0 = Release|ARM64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Release|x64.ActiveCfg = Release|x64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Release|x64.Build.0 = Release|x64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Release|x86.ActiveCfg = Release|x64 + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2501,6 +2515,7 @@ Global {3B227528-4BA6-4CAF-B44A-A10C78A64849} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {F5E1146E-B7B3-4E11-85FD-270A500BD78C} = {3B227528-4BA6-4CAF-B44A-A10C78A64849} {3157FA75-86CF-4EE2-8F62-C43F776493C6} = {3B227528-4BA6-4CAF-B44A-A10C78A64849} + {FC8EB78F-F061-4BD9-A3F6-507BEA965E2B} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/modules/fancyzones/UnitTests-FancyZonesEditor/DefaultLayoutsModelTests.cs b/src/modules/fancyzones/UnitTests-FancyZonesEditor/DefaultLayoutsModelTests.cs new file mode 100644 index 0000000000..7f495cb207 --- /dev/null +++ b/src/modules/fancyzones/UnitTests-FancyZonesEditor/DefaultLayoutsModelTests.cs @@ -0,0 +1,59 @@ +// 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 FancyZonesEditor.Models; + +namespace UnitTestsFancyZonesEditor; + +[TestClass] +public class DefaultLayoutsModelTests +{ + [TestMethod] + public void LayoutCapacityShouldBeNumberOfMonitorConfigurations() + { + var defaultLayoutsModel = new DefaultLayoutsModel(); + var expectedOptionCount = Enum.GetValues(typeof(MonitorConfigurationType)).Length; + + var actualCapacity = defaultLayoutsModel.Layouts.Capacity; + + Assert.AreEqual(expectedOptionCount, actualCapacity); + } + + [TestMethod] + public void OverridingLayoutClearsOldDefault() + { + var defaultLayoutsModel = new DefaultLayoutsModel(); + GridLayoutModel firstLayout = new GridLayoutModel(); + CanvasLayoutModel secondLayout = new CanvasLayoutModel("steve"); + + defaultLayoutsModel.Set(firstLayout, MonitorConfigurationType.Horizontal); + Assert.AreEqual(defaultLayoutsModel.Layouts[(int)MonitorConfigurationType.Horizontal], firstLayout); + + defaultLayoutsModel.Set(secondLayout, MonitorConfigurationType.Horizontal); + Assert.AreNotEqual(defaultLayoutsModel.Layouts[(int)MonitorConfigurationType.Horizontal], firstLayout); + Assert.AreEqual(defaultLayoutsModel.Layouts[(int)MonitorConfigurationType.Horizontal], secondLayout); + } + + [TestMethod] + public void SettingTheVerticalLayoutShouldBeTheDefault() + { + var defaultLayoutsModel = new DefaultLayoutsModel(); + GridLayoutModel firstLayout = new GridLayoutModel(); + defaultLayoutsModel.Set(firstLayout, MonitorConfigurationType.Horizontal); + defaultLayoutsModel.Set(firstLayout, MonitorConfigurationType.Vertical); + + Assert.AreEqual(defaultLayoutsModel.Layouts[(int)MonitorConfigurationType.Vertical], firstLayout); + } + + [TestMethod] + public void RestoringLayoutShouldSetLayouts() + { + var defaultLayoutsModel = new DefaultLayoutsModel(); + GridLayoutModel firstLayout = new GridLayoutModel(); + CanvasLayoutModel secondLayout = new CanvasLayoutModel("steve"); + var restoredLayouts = new List { firstLayout, secondLayout }; + defaultLayoutsModel.Restore(restoredLayouts); + + CollectionAssert.AreEqual(defaultLayoutsModel.Layouts, restoredLayouts); + } +} diff --git a/src/modules/fancyzones/UnitTests-FancyZonesEditor/GridLayoutModelTests.cs b/src/modules/fancyzones/UnitTests-FancyZonesEditor/GridLayoutModelTests.cs new file mode 100644 index 0000000000..60153dde69 --- /dev/null +++ b/src/modules/fancyzones/UnitTests-FancyZonesEditor/GridLayoutModelTests.cs @@ -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 FancyZonesEditor.Models; + +namespace UnitTestsFancyZonesEditor; + +[TestClass] +public class GridLayoutModelTests +{ + [TestMethod] + public void EmptyGridLayoutModelIsNotValid() + { + GridLayoutModel gridLayoutModel = new GridLayoutModel(); + Assert.IsFalse(gridLayoutModel.IsModelValid()); + } + + [TestMethod] + public void GridLayoutModelWithInvalidRowAndColumnCountsIsNotValid() + { + GridLayoutModel gridLayoutModel = new GridLayoutModel(); + gridLayoutModel.Rows = 0; + gridLayoutModel.Columns = 0; + Assert.IsFalse(gridLayoutModel.IsModelValid()); + } + + [TestMethod] + public void GridLayoutModelWithInvalidRowPercentsIsNotValid() + { + GridLayoutModel gridLayoutModel = new GridLayoutModel(); + gridLayoutModel.Rows = 1; + gridLayoutModel.Columns = 1; + gridLayoutModel.RowPercents = new List { 0 }; // Invalid percentage + Assert.IsFalse(gridLayoutModel.IsModelValid()); + } + + [TestMethod] + public void GridLayoutModelWithInvalidColumnPercentsIsNotValid() + { + GridLayoutModel gridLayoutModel = new GridLayoutModel(); + gridLayoutModel.Rows = 1; + gridLayoutModel.Columns = 1; + gridLayoutModel.ColumnPercents = new List { 0 }; // Invalid percentage + Assert.IsFalse(gridLayoutModel.IsModelValid()); + } + + [TestMethod] + public void GridLayoutModelWithInvalidCellChildMapLengthIsNotValid() + { + GridLayoutModel gridLayoutModel = new GridLayoutModel(); + gridLayoutModel.Rows = 2; + gridLayoutModel.Columns = 2; + gridLayoutModel.CellChildMap = new int[2, 1]; // Invalid length + Assert.IsFalse(gridLayoutModel.IsModelValid()); + } + + [TestMethod] + public void GridLayoutModelWithInvalidZoneCountIsNotValid() + { + GridLayoutModel gridLayoutModel = new GridLayoutModel(); + gridLayoutModel.Rows = 2; + gridLayoutModel.Columns = 2; + gridLayoutModel.CellChildMap = new int[,] + { + { 1, 2 }, + { 3, 4 }, + }; // Invalid zone count + Assert.IsFalse(gridLayoutModel.IsModelValid()); + } + + [TestMethod] + public void GridLayoutModelWithValidPropertiesIsValid() + { + GridLayoutModel gridLayoutModel = new GridLayoutModel(); + + // Set valid row and column counts + gridLayoutModel.Rows = 2; + gridLayoutModel.Columns = 2; + + // Set valid percentages for rows and columns + // Should add up to 10000 + gridLayoutModel.RowPercents = new List { 5000, 5000 }; + gridLayoutModel.ColumnPercents = new List { 5000, 5000 }; + + // Set a valid CellChildMap + gridLayoutModel.CellChildMap = new int[,] + { + { 0, 1 }, + { 2, 3 }, + }; // corresponds to 4 zones + + Assert.IsTrue(gridLayoutModel.IsModelValid(), "GridLayoutModel with valid properties should be valid."); + } +} diff --git a/src/modules/fancyzones/UnitTests-FancyZonesEditor/UnitTests-FancyZonesEditor.csproj b/src/modules/fancyzones/UnitTests-FancyZonesEditor/UnitTests-FancyZonesEditor.csproj new file mode 100644 index 0000000000..a146ad62b2 --- /dev/null +++ b/src/modules/fancyzones/UnitTests-FancyZonesEditor/UnitTests-FancyZonesEditor.csproj @@ -0,0 +1,29 @@ + + + + net7.0-windows10.0.20348.0 + 10.0.19041.0 + 10.0.19041.0 + enable + false + enable + + false + true + ..\..\..\..\$(Platform)\$(Configuration)\tests\UnitTest-FancyZonesEditor\ + + + + + + + + + + + + + + + + diff --git a/src/modules/fancyzones/UnitTests-FancyZonesEditor/Usings.cs b/src/modules/fancyzones/UnitTests-FancyZonesEditor/Usings.cs new file mode 100644 index 0000000000..8df48eacab --- /dev/null +++ b/src/modules/fancyzones/UnitTests-FancyZonesEditor/Usings.cs @@ -0,0 +1,5 @@ +// 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. + +global using Microsoft.VisualStudio.TestTools.UnitTesting; From 50cb279d2a39a8e29c86b2a786f3fceda97aaa71 Mon Sep 17 00:00:00 2001 From: Heiko <61519853+htcfreek@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:45:00 +0200 Subject: [PATCH 4/8] [PTRun][TimeDate]Unix Time in milliseconds, fix negative unix time input, error message improvement (#29149) * add unix time in ms * update dev docs * unit tests * fix spell check * tool tip * fix negative unix time input, improve regex, update unit tests, improve error message * Update error handling and tests * add tests and fix spelling * small fixes --- .github/actions/spell-check/expect.txt | 1 + .../modules/launcher/plugins/timedate.md | 2 + .../ImageTests.cs | 2 + .../QueryTests.cs | 60 ++++++++++++------- .../StringParserTests.cs | 5 ++ .../Components/AvailableResultsList.cs | 8 +++ .../Components/ResultHelper.cs | 1 + .../Components/SearchController.cs | 3 +- .../Components/TimeAndDateHelper.cs | 25 ++++++-- .../Properties/Resources.Designer.cs | 11 +++- .../Properties/Resources.resx | 5 +- 11 files changed, 94 insertions(+), 29 deletions(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index aff7937142..425ec9bbd0 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -1983,6 +1983,7 @@ uipi UIs ULARGE ULONGLONG +ums unapply unassign uncompilable diff --git a/doc/devdocs/modules/launcher/plugins/timedate.md b/doc/devdocs/modules/launcher/plugins/timedate.md index 6ad856657a..ca04b53293 100644 --- a/doc/devdocs/modules/launcher/plugins/timedate.md +++ b/doc/devdocs/modules/launcher/plugins/timedate.md @@ -18,6 +18,7 @@ The 'Time and Date' plugin shows the date and time in different formats. For the **Remarks** - The following formats requires a prefix in the query: - Unix Timestamp: `u` + - Unix Timestamp in milliseconds: `ums` - Windows file time: `ft` - On invalid number inputs we show a warning that tells the user which prefixes are allowed/required. @@ -33,6 +34,7 @@ The following formats are currently available: | Time UTC | 4:10 PM | x | x | | Now UTC | 3/5/2022 4:10 PM | x | x | | Unix Timestamp | 1646496622 | x | x | +| Unix Timestamp in milliseconds | 1646496622500 | x | x | | Hour | 10 | x | | | Minute | 30 | x | | | Second | 45 | x | | diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/ImageTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/ImageTests.cs index 094e525852..a51e2c4540 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/ImageTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/ImageTests.cs @@ -36,6 +36,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests [DataRow("now", "Now -", "Images\\timeDate.dark.png")] [DataRow("now u", "Now UTC -", "Images\\timeDate.dark.png")] [DataRow("unix", "Unix epoch time -", "Images\\timeDate.dark.png")] + [DataRow("unix epoch time in", "Unix epoch time in milliseconds -", "Images\\timeDate.dark.png")] [DataRow("hour", "Hour -", "Images\\time.dark.png")] [DataRow("minute", "Minute -", "Images\\time.dark.png")] [DataRow("second", "Second -", "Images\\time.dark.png")] @@ -82,6 +83,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests [DataRow("now", "Now -", "Images\\timeDate.light.png")] [DataRow("now u", "Now UTC -", "Images\\timeDate.light.png")] [DataRow("unix", "Unix epoch time -", "Images\\timeDate.light.png")] + [DataRow("unix epoch time in", "Unix epoch time in milliseconds -", "Images\\timeDate.light.png")] [DataRow("hour", "Hour -", "Images\\time.light.png")] [DataRow("minute", "Minute -", "Images\\time.light.png")] [DataRow("second", "Second -", "Images\\time.light.png")] diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs index 8fbcaf41e7..68d962d102 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/QueryTests.cs @@ -31,13 +31,13 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests } [DataTestMethod] - [DataRow("time", 2)] - [DataRow("date", 2)] - [DataRow("now", 3)] - [DataRow("current", 3)] - [DataRow("year", 0)] - [DataRow("time::10:10:10", 0)] - [DataRow("date::10/10/10", 0)] + [DataRow("time", 2)] // Setting 'Only Date, Time, Now on global results' is default on + [DataRow("date", 2)] // Setting 'Only Date, Time, Now on global results' is default on + [DataRow("now", 3)] // Setting 'Only Date, Time, Now on global results' is default on + [DataRow("current", 3)] // Setting 'Only Date, Time, Now on global results' is default on + [DataRow("year", 0)] // Setting 'Only Date, Time, Now on global results' is default on + [DataRow("time::10:10:10", 0)] // Setting 'Only Date, Time, Now on global results' is default on + [DataRow("date::10/10/10", 0)] // Setting 'Only Date, Time, Now on global results' is default on public void CountWithoutPluginKeyword(string typedString, int expectedResultCount) { // Setup @@ -52,12 +52,12 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests } [DataTestMethod] - [DataRow("(time", 17)] - [DataRow("(date", 25)] + [DataRow("(time", 18)] + [DataRow("(date", 26)] [DataRow("(year", 7)] - [DataRow("(now", 31)] - [DataRow("(current", 31)] - [DataRow("(", 31)] + [DataRow("(now", 32)] + [DataRow("(current", 32)] + [DataRow("(", 32)] [DataRow("(now::10:10:10", 1)] // Windows file time [DataRow("(current::10:10:10", 0)] public void CountWithPluginKeyword(string typedString, int expectedResultCount) @@ -104,6 +104,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests [DataRow("(now", "Now -")] [DataRow("(now u", "Now UTC -")] [DataRow("(unix", "Unix epoch time -")] + [DataRow("(unix epoch time in milli", "Unix epoch time in milliseconds -")] [DataRow("(file", "Windows file time (Int64 number) ")] [DataRow("(hour", "Hour -")] [DataRow("(minute", "Minute -")] @@ -156,6 +157,11 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests [DataRow("(12:30", "Time -")] [DataRow("(10.10.2022", "Date -")] [DataRow("(u1646408119", "Date and time -")] + [DataRow("(u+1646408119", "Date and time -")] + [DataRow("(u-1646408119", "Date and time -")] + [DataRow("(ums1646408119", "Date and time -")] + [DataRow("(ums+1646408119", "Date and time -")] + [DataRow("(ums-1646408119", "Date and time -")] [DataRow("(ft637820085517321977", "Date and time -")] public void DateTimeNumberOnlyInput(string typedString, string expectedResult) { @@ -176,15 +182,10 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests [DataTestMethod] [DataRow("(abcdefg")] [DataRow("(timmmmeeee")] - [DataRow("(10.10.20.aa.22")] - [DataRow("(12::55")] - [DataRow("(12:aa:55")] [DataRow("(timtaaaetetaae::u1646408119")] [DataRow("(time:eeee")] [DataRow("(time::eeee")] [DataRow("(time//eeee")] - [DataRow("(date::12::55")] - [DataRow("(date::12:aa:55")] public void InvalidInputNotShowsResults(string typedString) { // Setup @@ -201,8 +202,23 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests [DataTestMethod] [DataRow("(ug1646408119")] // Invalid prefix [DataRow("(u9999999999999")] // Unix number + prefix is longer than 12 characters + [DataRow("(ums999999999999999")] // Unix number in milliseconds + prefix is longer than 17 characters + [DataRow("(-u99999999999")] // Unix number with wrong placement of - sign + [DataRow("(+ums9999999999")] // Unix number in milliseconds with wrong placement of + sign [DataRow("(0123456")] // Missing prefix [DataRow("(ft63782008ab55173dasdas21977")] // Number contains letters + [DataRow("(ft63782008ab55173dasdas")] // Number contains letters at the end + [DataRow("(ft12..548")] // Number contains wrong punctuation + [DataRow("(ft12..54//8")] // Number contains wrong punctuation and other characters + [DataRow("(time::ft12..54//8")] // Number contains wrong punctuation and other characters + [DataRow("(ut2ed.5555")] // Number contains letters + [DataRow("(12..54//8")] // Number contains punctuation and other characters, but no special prefix + [DataRow("(ft::1288gg8888")] // Number contains delimiter and letters, but no special prefix + [DataRow("(date::12::55")] + [DataRow("(date::12:aa:55")] + [DataRow("(10.aa.22")] + [DataRow("(12::55")] + [DataRow("(12:aa:55")] public void InvalidNumberInputShowsErrorMessage(string typedString) { // Setup @@ -217,10 +233,12 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests } [DataTestMethod] - [DataRow("(ft12..548")] // Number contains punctuation - [DataRow("(ft12..54//8")] // Number contains punctuation and other characters - [DataRow("(12..54//8")] // Number contains punctuation and other characters - [DataRow("(ft::1288gg8888")] // Number contains delimiter and other characters + [DataRow("(ft1 2..548")] // Input contains space + [DataRow("(ft12..54 //8")] // Input contains space + [DataRow("(time::ft12..54 //8")] // Input contains space + [DataRow("(10.10aa")] // Input contains . (Can be part of a date.) + [DataRow("(10:10aa")] // Input contains : (Can be part of a time.) + [DataRow("(10/10aa")] // Input contains / (Can be part of a date.) public void InvalidInputNotShowsErrorMessage(string typedString) { // Setup diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/StringParserTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/StringParserTests.cs index 322592a457..1a868c0f8f 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/StringParserTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/StringParserTests.cs @@ -34,6 +34,11 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests [DataRow("5:05:10 PM", true, "T", "5:05:10 PM")] [DataRow("10456", false, "", "")] [DataRow("u10456", true, "", "")] // Value is UTC and can be different based on system + [DataRow("u-10456", true, "", "")] // Value is UTC and can be different based on system + [DataRow("u+10456", true, "", "")] // Value is UTC and can be different based on system + [DataRow("ums10456", true, "", "")] // Value is UTC and can be different based on system + [DataRow("ums-10456", true, "", "")] // Value is UTC and can be different based on system + [DataRow("ums+10456", true, "", "")] // Value is UTC and can be different based on system [DataRow("ft10456", true, "", "")] // Value is UTC and can be different based on system public void ConvertStringToDateTime(string typedString, bool expectedBool, string stringType, string expectedString) { diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/AvailableResultsList.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/AvailableResultsList.cs index 2fc553f822..ab6c77f1ea 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/AvailableResultsList.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/AvailableResultsList.cs @@ -61,6 +61,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components { // We use long instead of int for unix time stamp because int is too small after 03:14:07 UTC 2038-01-19 long unixTimestamp = (long)dateTimeNowUtc.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + long unixTimestampMilliseconds = (long)dateTimeNowUtc.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds; int weekOfYear = calendar.GetWeekOfYear(dateTimeNow, DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek); string era = DateTimeFormatInfo.CurrentInfo.GetEraName(calendar.GetEra(dateTimeNow)); string eraShort = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedEraName(calendar.GetEra(dateTimeNow)); @@ -89,6 +90,13 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components IconType = ResultIconType.DateTime, }, new AvailableResult() + { + Value = unixTimestampMilliseconds.ToString(CultureInfo.CurrentCulture), + Label = Resources.Microsoft_plugin_timedate_Unix_Milliseconds, + AlternativeSearchTag = ResultHelper.SelectStringFromResources(isSystemDateTime, "Microsoft_plugin_timedate_SearchTagFormat"), + IconType = ResultIconType.DateTime, + }, + new AvailableResult() { Value = dateTimeNow.Hour.ToString(CultureInfo.CurrentCulture), Label = Resources.Microsoft_plugin_timedate_Hour, diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/ResultHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/ResultHelper.cs index a2f3dfe6af..5d4e3eb8f4 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/ResultHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/ResultHelper.cs @@ -86,6 +86,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components { Title = Resources.Microsoft_plugin_timedate_ErrorResultTitle, SubTitle = Resources.Microsoft_plugin_timedate_ErrorResultSubTitle, + ToolTipData = new ToolTipData(Resources.Microsoft_plugin_timedate_ErrorResultTitle, Resources.Microsoft_plugin_timedate_ErrorResultSubTitle), IcoPath = $"Images\\Warning.{theme}.png", }; } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/SearchController.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/SearchController.cs index 708dc7e39b..219f2c5556 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/SearchController.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/SearchController.cs @@ -121,8 +121,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components } // If search term is only a number that can't be parsed return an error message - if (!isEmptySearchInput && results.Count == 0 && searchTerm.Any(char.IsNumber) && Regex.IsMatch(searchTerm, @"\w+\d+$") && - !searchTerm.Contains(InputDelimiter) && !searchTerm.Any(char.IsWhiteSpace) && !searchTerm.Any(char.IsPunctuation)) + if (!isEmptySearchInput && results.Count == 0 && Regex.IsMatch(searchTerm, @"\w+\d+.*$") && !searchTerm.Any(char.IsWhiteSpace) && (TimeAndDateHelper.IsSpecialInputParsing(searchTerm) || !Regex.IsMatch(searchTerm, @"\d+[\.:/]\d+"))) { // Without plugin key word show only if message is not hidden by setting if (isKeywordSearch || !TimeDateSettings.Instance.HideNumberMessageOnGlobalQuery) diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/TimeAndDateHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/TimeAndDateHelper.cs index 86294474c6..ed1f5097b8 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/TimeAndDateHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/TimeAndDateHelper.cs @@ -96,17 +96,24 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components // Known date/time format return true; } - else if (Regex.IsMatch(input, @"^u\d+") && input.Length <= 12 && long.TryParse(input.TrimStart('u'), out long secondsInt)) + else if (Regex.IsMatch(input, @"^u[\+-]?\d{1,10}$") && long.TryParse(input.TrimStart('u'), out long secondsU)) { // unix time stamp // we use long instead of int because int is too small after 03:14:07 UTC 2038-01-19 - timestamp = new DateTime(1970, 1, 1).AddSeconds(secondsInt).ToLocalTime(); + timestamp = new DateTime(1970, 1, 1).AddSeconds(secondsU).ToLocalTime(); return true; } - else if (Regex.IsMatch(input, @"^ft\d+") && long.TryParse(input.TrimStart("ft".ToCharArray()), out long secondsLong)) + else if (Regex.IsMatch(input, @"^ums[\+-]?\d{1,13}$") && long.TryParse(input.TrimStart("ums".ToCharArray()), out long millisecondsUms)) + { + // unix time stamp in milliseconds + // we use long instead of int because int is too small after 03:14:07 UTC 2038-01-19 + timestamp = new DateTime(1970, 1, 1).AddMilliseconds(millisecondsUms).ToLocalTime(); + return true; + } + else if (Regex.IsMatch(input, @"^ft\d+$") && long.TryParse(input.TrimStart("ft".ToCharArray()), out long secondsFt)) { // windows file time - timestamp = new DateTime(secondsLong); + timestamp = new DateTime(secondsFt); return true; } else @@ -115,6 +122,16 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components return false; } } + + /// + /// Test if input is special parsing for Unix time, Unix time in milliseconds or File time. + /// + /// String with date/time + /// True if yes, otherwise false + internal static bool IsSpecialInputParsing(string input) + { + return Regex.IsMatch(input, @"^.*(u|ums|ft)\d"); + } } /// diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.Designer.cs index 41c0fc0398..69689b7980 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.Designer.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.Designer.cs @@ -160,7 +160,7 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Properties { } /// - /// Looks up a localized string similar to Valid prefixes: 'u' for Unix Timestamp, 'ft' for Windows file time. + /// Looks up a localized string similar to Valid prefixes: 'u' for Unix Timestamp, 'ums' for Unix Timestamp in milliseconds, 'ft' for Windows file time. /// internal static string Microsoft_plugin_timedate_ErrorResultSubTitle { get { @@ -555,6 +555,15 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Properties { } } + /// + /// Looks up a localized string similar to Unix epoch time in milliseconds. + /// + internal static string Microsoft_plugin_timedate_Unix_Milliseconds { + get { + return ResourceManager.GetString("Microsoft_plugin_timedate_Unix_Milliseconds", resourceCulture); + } + } + /// /// Looks up a localized string similar to Week of the month. /// diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.resx b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.resx index c5cd40c0a3..acdb4aa3f4 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.resx +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.resx @@ -153,7 +153,7 @@ Era abbreviation - Valid prefixes: 'u' for Unix Timestamp, 'ft' for Windows file time + Valid prefixes: 'u' for Unix Timestamp, 'ums' for Unix Timestamp in milliseconds, 'ft' for Windows file time Error: Invalid number input @@ -312,4 +312,7 @@ Year + + Unix epoch time in milliseconds + \ No newline at end of file From 6a9d44fb4d299439eaa10c9c90b28b9febb9ea43 Mon Sep 17 00:00:00 2001 From: Garrett Vernon <70212190+garv5014@users.noreply.github.com> Date: Wed, 18 Oct 2023 04:14:16 -0600 Subject: [PATCH 5/8] [FZ Editor] Replace list with a dictionary for the DefaultLayouts (#29135) * Dictionary Implementation to fix temporal coupling. Swapped the setting order as proof * changed Dictionary to use the monitor config and not int --- .../editor/FancyZonesEditor/LayoutBackup.cs | 4 ++-- .../Models/DefaultLayoutsModel.cs | 21 +++++++------------ .../FancyZonesEditor/Models/LayoutModel.cs | 4 ++-- .../Models/MainWindowSettingsModel.cs | 2 +- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/LayoutBackup.cs b/src/modules/fancyzones/editor/FancyZonesEditor/LayoutBackup.cs index feeb49724d..a245db0e26 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/LayoutBackup.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/LayoutBackup.cs @@ -12,7 +12,7 @@ namespace FancyZonesEditor { private LayoutModel _backup; private string _hotkeyBackup; - private List _defaultLayoutsBackup; + private Dictionary _defaultLayoutsBackup; public LayoutBackup() { @@ -30,7 +30,7 @@ namespace FancyZonesEditor } _hotkeyBackup = MainWindowSettingsModel.LayoutHotkeys.Key(model.Uuid); - _defaultLayoutsBackup = new List(MainWindowSettingsModel.DefaultLayouts.Layouts); + _defaultLayoutsBackup = new Dictionary(MainWindowSettingsModel.DefaultLayouts.Layouts); } public void Restore(LayoutModel layoutToRestore) diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/DefaultLayoutsModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/DefaultLayoutsModel.cs index 770c5ec626..8ae5e3ac84 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/DefaultLayoutsModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/DefaultLayoutsModel.cs @@ -13,7 +13,7 @@ namespace FancyZonesEditor.Models { private static int Count { get; } = Enum.GetValues(typeof(MonitorConfigurationType)).Length; - public List Layouts { get; } = new List(Count); + public Dictionary Layouts { get; } = new Dictionary(Count); public DefaultLayoutsModel() { @@ -36,12 +36,12 @@ namespace FancyZonesEditor.Models public void Reset(string uuid) { - if (Layouts[(int)MonitorConfigurationType.Horizontal].Uuid == uuid) + if (Layouts[MonitorConfigurationType.Horizontal].Uuid == uuid) { Set(MainWindowSettingsModel.TemplateModels[(int)LayoutType.PriorityGrid], MonitorConfigurationType.Horizontal); } - if (Layouts[(int)MonitorConfigurationType.Vertical].Uuid == uuid) + if (Layouts[MonitorConfigurationType.Vertical].Uuid == uuid) { Set(MainWindowSettingsModel.TemplateModels[(int)LayoutType.Rows], MonitorConfigurationType.Vertical); } @@ -49,23 +49,16 @@ namespace FancyZonesEditor.Models public void Set(LayoutModel layout, MonitorConfigurationType type) { - if (Layouts.Count <= (int)type) - { - Layouts.Insert((int)type, layout); - } - else - { - Layouts[(int)type] = layout; - } + Layouts[type] = layout; FirePropertyChanged(); } - public void Restore(List layouts) + public void Restore(Dictionary layouts) { - for (int i = 0; i < Count; i++) + foreach (var monitorConfigurationType in layouts.Keys) { - Set(layouts[i], (MonitorConfigurationType)i); + Set(layouts[monitorConfigurationType], monitorConfigurationType); } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs index 8968ef6e21..95b4f5f064 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs @@ -166,7 +166,7 @@ namespace FancyZonesEditor.Models { get { - return MainWindowSettingsModel.DefaultLayouts.Layouts[(int)MonitorConfigurationType.Vertical].Uuid == this.Uuid; + return MainWindowSettingsModel.DefaultLayouts.Layouts[MonitorConfigurationType.Vertical].Uuid == this.Uuid; } } @@ -174,7 +174,7 @@ namespace FancyZonesEditor.Models { get { - return MainWindowSettingsModel.DefaultLayouts.Layouts[(int)MonitorConfigurationType.Vertical].Uuid != this.Uuid; + return MainWindowSettingsModel.DefaultLayouts.Layouts[MonitorConfigurationType.Vertical].Uuid != this.Uuid; } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs index 0e5391f724..5e64d2fdb1 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs @@ -80,8 +80,8 @@ namespace FancyZonesEditor TemplateModels.Insert((int)LayoutType.PriorityGrid, priorityGridModel); // set default layouts - DefaultLayouts.Set(priorityGridModel, MonitorConfigurationType.Horizontal); DefaultLayouts.Set(rowsModel, MonitorConfigurationType.Vertical); + DefaultLayouts.Set(priorityGridModel, MonitorConfigurationType.Horizontal); } // IsShiftKeyPressed - is the shift key currently being held down From 8b92789f78101d87d8f1ef9610276ae024d3a607 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Wed, 18 Oct 2023 12:33:10 +0200 Subject: [PATCH 6/8] [Peek] Fix first preview stuck loading (#29183) * fix first preview stuck loading * comment --- .../peek/Peek.UI/MainWindowViewModel.cs | 5 +++-- .../peek/Peek.UI/PeekXAML/MainWindow.xaml.cs | 21 +++++++++++-------- .../Peek.UI/Services/NeighboringItemsQuery.cs | 7 +------ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/modules/peek/Peek.UI/MainWindowViewModel.cs b/src/modules/peek/Peek.UI/MainWindowViewModel.cs index 7a01340d5e..c7d57bd83e 100644 --- a/src/modules/peek/Peek.UI/MainWindowViewModel.cs +++ b/src/modules/peek/Peek.UI/MainWindowViewModel.cs @@ -9,6 +9,7 @@ using Microsoft.UI.Xaml; using Peek.Common.Helpers; using Peek.Common.Models; using Peek.UI.Models; +using Windows.Win32.Foundation; namespace Peek.UI { @@ -40,11 +41,11 @@ namespace Peek.UI NavigationThrottleTimer.Interval = TimeSpan.FromMilliseconds(NavigationThrottleDelayMs); } - public void Initialize() + public void Initialize(HWND foregroundWindowHandle) { try { - Items = NeighboringItemsQuery.GetNeighboringItems(); + Items = NeighboringItemsQuery.GetNeighboringItems(foregroundWindowHandle); } catch (Exception ex) { diff --git a/src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml.cs b/src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml.cs index a3b72dcb18..b28fed13c0 100644 --- a/src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml.cs +++ b/src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml.cs @@ -85,20 +85,24 @@ namespace Peek.UI /// private void OnPeekHotkey() { + // Need to read the foreground HWND before activating Peek to avoid focus stealing + // Foreground HWND must always be Explorer or Desktop + var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow(); + // First Peek activation if (!activated) { Activate(); - Initialize(); + Initialize(foregroundWindowHandle); activated = true; return; } if (AppWindow.IsVisible) { - if (IsNewSingleSelectedItem()) + if (IsNewSingleSelectedItem(foregroundWindowHandle)) { - Initialize(); + Initialize(foregroundWindowHandle); } else { @@ -107,7 +111,7 @@ namespace Peek.UI } else { - Initialize(); + Initialize(foregroundWindowHandle); } } @@ -126,12 +130,12 @@ namespace Peek.UI Uninitialize(); } - private void Initialize() + private void Initialize(Windows.Win32.Foundation.HWND foregroundWindowHandle) { var bootTime = new System.Diagnostics.Stopwatch(); bootTime.Start(); - ViewModel.Initialize(); + ViewModel.Initialize(foregroundWindowHandle); ViewModel.ScalingFactor = this.GetMonitorScale(); bootTime.Stop(); @@ -156,6 +160,7 @@ namespace Peek.UI private void FilePreviewer_PreviewSizeChanged(object sender, PreviewSizeChangedArgs e) { var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow(); + var monitorSize = foregroundWindowHandle.GetMonitorSize(); var monitorScale = foregroundWindowHandle.GetMonitorScale(); @@ -210,12 +215,10 @@ namespace Peek.UI Uninitialize(); } - private bool IsNewSingleSelectedItem() + private bool IsNewSingleSelectedItem(Windows.Win32.Foundation.HWND foregroundWindowHandle) { try { - var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow(); - var selectedItems = FileExplorerHelper.GetSelectedItems(foregroundWindowHandle); var selectedItemsCount = selectedItems?.GetCount() ?? 0; if (selectedItems == null || selectedItemsCount == 0 || selectedItemsCount > 1) diff --git a/src/modules/peek/Peek.UI/Services/NeighboringItemsQuery.cs b/src/modules/peek/Peek.UI/Services/NeighboringItemsQuery.cs index 78d0f97a5d..efc23316d7 100644 --- a/src/modules/peek/Peek.UI/Services/NeighboringItemsQuery.cs +++ b/src/modules/peek/Peek.UI/Services/NeighboringItemsQuery.cs @@ -2,10 +2,7 @@ // 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.Diagnostics; using CommunityToolkit.Mvvm.ComponentModel; -using Peek.Common.Models; -using Peek.UI.Extensions; using Peek.UI.Helpers; using Peek.UI.Models; @@ -16,10 +13,8 @@ namespace Peek.UI [ObservableProperty] private bool isMultipleFilesActivation; - public NeighboringItems? GetNeighboringItems() + public NeighboringItems? GetNeighboringItems(Windows.Win32.Foundation.HWND foregroundWindowHandle) { - var foregroundWindowHandle = Windows.Win32.PInvoke.GetForegroundWindow(); - var selectedItemsShellArray = FileExplorerHelper.GetSelectedItems(foregroundWindowHandle); var selectedItemsCount = selectedItemsShellArray?.GetCount() ?? 0; From a370c17918afe82f887fca5a1644f7e74f319460 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Wed, 18 Oct 2023 13:01:41 +0200 Subject: [PATCH 7/8] [Peek] Fix previous video flashing when peek is invoked (#29243) --- src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs index 0137b58aff..72c75b0474 100644 --- a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs +++ b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs @@ -217,6 +217,7 @@ namespace Peek.FilePreviewer partial void OnPreviewerChanging(IPreviewer? value) { VideoPreview.MediaPlayer.Pause(); + VideoPreview.MediaPlayer.Source = null; VideoPreview.Source = null; ImagePreview.Source = null; From b6fa827e783660267648d1bc5ee56cb29753227e Mon Sep 17 00:00:00 2001 From: Seraphima Zykova Date: Wed, 18 Oct 2023 13:27:39 +0200 Subject: [PATCH 8/8] [Build]Fix broken FZEditor test after concurrent merges(#29282) * no longer needed test * update --- .../DefaultLayoutsModelTests.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/modules/fancyzones/UnitTests-FancyZonesEditor/DefaultLayoutsModelTests.cs b/src/modules/fancyzones/UnitTests-FancyZonesEditor/DefaultLayoutsModelTests.cs index 7f495cb207..2c6f33f18e 100644 --- a/src/modules/fancyzones/UnitTests-FancyZonesEditor/DefaultLayoutsModelTests.cs +++ b/src/modules/fancyzones/UnitTests-FancyZonesEditor/DefaultLayoutsModelTests.cs @@ -8,17 +8,6 @@ namespace UnitTestsFancyZonesEditor; [TestClass] public class DefaultLayoutsModelTests { - [TestMethod] - public void LayoutCapacityShouldBeNumberOfMonitorConfigurations() - { - var defaultLayoutsModel = new DefaultLayoutsModel(); - var expectedOptionCount = Enum.GetValues(typeof(MonitorConfigurationType)).Length; - - var actualCapacity = defaultLayoutsModel.Layouts.Capacity; - - Assert.AreEqual(expectedOptionCount, actualCapacity); - } - [TestMethod] public void OverridingLayoutClearsOldDefault() { @@ -42,7 +31,7 @@ public class DefaultLayoutsModelTests defaultLayoutsModel.Set(firstLayout, MonitorConfigurationType.Horizontal); defaultLayoutsModel.Set(firstLayout, MonitorConfigurationType.Vertical); - Assert.AreEqual(defaultLayoutsModel.Layouts[(int)MonitorConfigurationType.Vertical], firstLayout); + Assert.AreEqual(defaultLayoutsModel.Layouts[MonitorConfigurationType.Vertical], firstLayout); } [TestMethod] @@ -51,7 +40,7 @@ public class DefaultLayoutsModelTests var defaultLayoutsModel = new DefaultLayoutsModel(); GridLayoutModel firstLayout = new GridLayoutModel(); CanvasLayoutModel secondLayout = new CanvasLayoutModel("steve"); - var restoredLayouts = new List { firstLayout, secondLayout }; + var restoredLayouts = new Dictionary { { MonitorConfigurationType.Horizontal, firstLayout }, { MonitorConfigurationType.Vertical, secondLayout } }; defaultLayoutsModel.Restore(restoredLayouts); CollectionAssert.AreEqual(defaultLayoutsModel.Layouts, restoredLayouts);