Compare commits

..

3 Commits

Author SHA1 Message Date
Leilei Zhang
ae753518c9 change logic 2025-07-03 16:33:01 +08:00
Leilei Zhang
03d2ff68bd check 2025-07-03 14:25:28 +08:00
Leilei Zhang
6f0c1ce88a fix settings page 2025-07-03 12:02:03 +08:00
19 changed files with 106 additions and 238 deletions

View File

@@ -55,7 +55,7 @@ The `OneFuzzConfig.json` file provides critical information for deploying fuzzin
],
"adoTemplate": [
{
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"jobNotificationEmail": "PowerToys@microsoft.com"
}
],

View File

@@ -9,6 +9,7 @@ using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using static Microsoft.PowerToys.UITest.WindowHelper;
namespace Microsoft.PowerToys.UITest
{
@@ -41,18 +42,6 @@ namespace Microsoft.PowerToys.UITest
this.locationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
CheckWinAppDriverAndRoot();
var runnerProcessInfo = new ProcessStartInfo
{
FileName = locationPath + this.runnerPath,
Verb = "runas",
};
if (scope == PowerToysModule.PowerToysSettings)
{
this.ExitExe(runnerProcessInfo.FileName);
this.runner = Process.Start(runnerProcessInfo);
}
}
/// <summary>
@@ -76,6 +65,7 @@ namespace Microsoft.PowerToys.UITest
public SessionHelper Init()
{
this.ExitExe(this.locationPath + this.sessionPath);
this.StartExe(this.locationPath + this.sessionPath);
Assert.IsNotNull(this.Driver, $"Failed to initialize the test environment. Driver is null.");
@@ -89,19 +79,6 @@ namespace Microsoft.PowerToys.UITest
public void Cleanup()
{
ExitScopeExe();
try
{
if (this.scope == PowerToysModule.PowerToysSettings)
{
runner?.Kill();
runner?.WaitForExit(); // Optional: Wait for the process to exit
}
}
catch (Exception ex)
{
// Handle exceptions if needed
Debug.WriteLine($"Exception during Cleanup: {ex.Message}");
}
}
/// <summary>
@@ -135,10 +112,65 @@ namespace Microsoft.PowerToys.UITest
public void StartExe(string appPath)
{
var opts = new AppiumOptions();
opts.AddAdditionalCapability("app", appPath);
// if we want to start settings, we need to use the runner exe to open settings
if (scope == PowerToysModule.PowerToysSettings)
{
TryLaunchPowerToysSettings(opts);
}
else
{
opts.AddAdditionalCapability("app", appPath);
}
this.Driver = NewWindowsDriver(opts);
}
private void TryLaunchPowerToysSettings(AppiumOptions opts)
{
CheckWinAppDriverAndRoot();
var runnerProcessInfo = new ProcessStartInfo
{
FileName = locationPath + this.runnerPath,
Verb = "runas",
Arguments = "--open-settings",
};
this.ExitExe(runnerProcessInfo.FileName);
this.runner = Process.Start(runnerProcessInfo);
Thread.Sleep(5000);
if (root != null)
{
const int maxRetries = 3;
const int delayMs = 5000;
var windowName = "PowerToys Settings";
for (int attempt = 1; attempt <= maxRetries; attempt++)
{
var settingsWindow = ApiHelper.FindDesktopWindowHandler(
new[] { windowName, AdministratorPrefix + windowName });
if (settingsWindow.Count > 0)
{
var hexHwnd = settingsWindow[0].HWnd.ToString("x");
opts.AddAdditionalCapability("appTopLevelWindow", hexHwnd);
return;
}
if (attempt < maxRetries)
{
Thread.Sleep(delayMs);
}
else
{
throw new TimeoutException("Failed to find PowerToys Settings window after multiple attempts.");
}
}
}
}
/// <summary>
/// Starts a new exe and takes control of it.
/// </summary>
@@ -176,6 +208,19 @@ namespace Microsoft.PowerToys.UITest
public void ExitScopeExe()
{
ExitExe(sessionPath);
try
{
if (this.scope == PowerToysModule.PowerToysSettings)
{
runner?.Kill();
runner?.WaitForExit(); // Optional: Wait for the process to exit
}
}
catch (Exception ex)
{
// Handle exceptions if needed
Debug.WriteLine($"Exception during Cleanup: {ex.Message}");
}
}
/// <summary>

View File

@@ -77,16 +77,6 @@ namespace Microsoft.PowerToys.UITest
this.sessionHelper = new SessionHelper(scope).Init();
this.Session = new Session(this.sessionHelper.GetRoot(), this.sessionHelper.GetDriver(), scope, size);
if (this.scope == PowerToysModule.PowerToysSettings)
{
// close Debug warning dialog if any
// Such debug warning dialog seems only appear in PowerToys Settings
if (this.FindAll("DEBUG").Count > 0)
{
this.Find("DEBUG").Find<Button>("Close").Click();
}
}
}
/// <summary>

View File

@@ -16,7 +16,7 @@
// project, where bugs will be filed
"org": "microsoft",
"project": "OS",
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
"IterationPath": "OS\\Future"
},

View File

@@ -16,7 +16,7 @@
// project, where bugs will be filed
"org": "microsoft",
"project": "OS",
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
"IterationPath": "OS\\Future"
},
@@ -57,7 +57,7 @@
// project, where bugs will be filed
"org": "microsoft",
"project": "OS",
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
"IterationPath": "OS\\Future"
},
@@ -98,7 +98,7 @@
// project, where bugs will be filed
"org": "microsoft",
"project": "OS",
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
"IterationPath": "OS\\Future"
},
@@ -139,7 +139,7 @@
// project, where bugs will be filed
"org": "microsoft",
"project": "OS",
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
"IterationPath": "OS\\Future"
},

View File

@@ -264,17 +264,6 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext
if (model != null)
{
model.ItemsChanged -= Model_ItemsChanged;
if (model is IDisposable disposableModel)
{
try
{
disposableModel.Dispose();
}
catch
{
// Ignore exceptions during cleanup
}
}
}
}
}

View File

@@ -571,17 +571,6 @@ public partial class ListViewModel : PageViewModel, IDisposable
if (model != null)
{
model.ItemsChanged -= Model_ItemsChanged;
if (model is IDisposable disposableModel)
{
try
{
disposableModel.Dispose();
}
catch
{
// Ignore exceptions during cleanup
}
}
}
}
}

View File

@@ -243,17 +243,6 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext
if (model != null)
{
model.PropChanged -= Model_PropChanged;
if (model is IDisposable disposableModel)
{
try
{
disposableModel.Dispose();
}
catch
{
// Ignore exceptions during cleanup
}
}
}
}
}

View File

@@ -18,7 +18,7 @@ using WinRT;
namespace Microsoft.CmdPal.UI.ViewModels;
public partial class ShellViewModel(IServiceProvider _serviceProvider, TaskScheduler _scheduler) : ObservableObject, IDisposable
public partial class ShellViewModel(IServiceProvider _serviceProvider, TaskScheduler _scheduler) : ObservableObject
{
[ObservableProperty]
public partial bool IsLoaded { get; set; } = false;
@@ -31,8 +31,6 @@ public partial class ShellViewModel(IServiceProvider _serviceProvider, TaskSched
private PageViewModel _currentPage = new LoadingPageViewModel(null, _scheduler);
private bool _isDisposed;
public PageViewModel CurrentPage
{
get => _currentPage;
@@ -203,48 +201,6 @@ public partial class ShellViewModel(IServiceProvider _serviceProvider, TaskSched
SetActiveExtension(null);
}
protected virtual void Dispose(bool disposing)
{
if (!_isDisposed)
{
_isDisposed = true;
if (disposing)
{
// Dispose managed resources
if (_mainListPage is IDisposable disposable)
{
try
{
disposable.Dispose();
}
catch (Exception)
{
}
}
if (_currentPage is IDisposable disposablePage)
{
try
{
disposablePage.Dispose();
}
catch
{
}
}
_mainListPage = null;
_activeExtension = null;
}
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
// You may ask yourself, why aren't we using CsWin32 for this?
// The CsWin32 projected version includes some object marshalling, like so:
//

View File

@@ -21,8 +21,6 @@ internal sealed partial class FallbackOpenFileItem : FallbackCommandItem, System
private uint _queryCookie = 10;
private bool _isDisposed;
public FallbackOpenFileItem()
: base(new NoOpCommand(), Resources.Indexer_Find_Path_fallback_display_title)
{
@@ -122,17 +120,9 @@ internal sealed partial class FallbackOpenFileItem : FallbackCommandItem, System
}
}
protected override void Dispose(bool disposing)
public void Dispose()
{
if (!_isDisposed)
{
_isDisposed = true;
if (disposing)
{
_searchEngine?.Dispose();
}
}
base.Dispose(disposing);
_searchEngine.Dispose();
GC.SuppressFinalize(this);
}
}

View File

@@ -21,7 +21,6 @@ internal sealed partial class ActionsListContextItem : CommandContextItem, IDisp
{
private readonly string fullPath;
private readonly List<CommandContextItem> actions = [];
private bool _isDisposed;
private static readonly Lock UpdateMoreCommandsLock = new();
private static ActionRuntime actionRuntime;
@@ -98,24 +97,14 @@ internal sealed partial class ActionsListContextItem : CommandContextItem, IDisp
}
}
protected override void Dispose(bool disposing)
public void Dispose()
{
if (!_isDisposed)
lock (UpdateMoreCommandsLock)
{
_isDisposed = true;
if (disposing)
if (actionRuntime != null)
{
lock (UpdateMoreCommandsLock)
{
if (actionRuntime != null)
{
actionRuntime.ActionCatalog.Changed -= ActionCatalog_Changed;
actionRuntime = null;
}
}
actionRuntime.ActionCatalog.Changed -= ActionCatalog_Changed;
}
}
base.Dispose(disposing);
}
}

View File

@@ -21,8 +21,6 @@ internal sealed partial class IndexerPage : DynamicListPage, IDisposable
private string initialQuery = string.Empty;
private bool _isDisposed;
public IndexerPage()
{
Id = "com.microsoft.indexer.fileSearch";
@@ -35,7 +33,6 @@ internal sealed partial class IndexerPage : DynamicListPage, IDisposable
public IndexerPage(string query, SearchEngine searchEngine, uint queryCookie, IList<IListItem> firstPageData)
{
disposeSearchEngine = false;
Icon = Icons.FileExplorer;
Name = Resources.Indexer_Title;
_searchEngine = searchEngine;
@@ -43,6 +40,7 @@ internal sealed partial class IndexerPage : DynamicListPage, IDisposable
_indexerListItems.AddRange(firstPageData);
initialQuery = query;
SearchText = query;
disposeSearchEngine = false;
}
public override void UpdateSearchText(string oldSearch, string newSearch)
@@ -78,21 +76,12 @@ internal sealed partial class IndexerPage : DynamicListPage, IDisposable
_searchEngine.Query(query, _queryCookie);
}
protected override void Dispose(bool disposing)
public void Dispose()
{
if (!_isDisposed)
if (disposeSearchEngine)
{
_isDisposed = true;
if (disposing)
{
if (disposeSearchEngine)
{
_searchEngine?.Dispose();
}
}
_searchEngine.Dispose();
GC.SuppressFinalize(this);
}
base.Dispose(disposing);
}
}

View File

@@ -34,8 +34,6 @@ internal sealed partial class WinGetExtensionPage : DynamicListPage, IDisposable
private IEnumerable<CatalogPackage>? _results;
private bool _disposed;
public static IconInfo WinGetIcon { get; } = IconHelpers.FromRelativePath("Assets\\WinGet.svg");
public static IconInfo ExtensionsIcon { get; } = IconHelpers.FromRelativePath("Assets\\Extension.svg");
@@ -191,7 +189,7 @@ internal sealed partial class WinGetExtensionPage : DynamicListPage, IDisposable
return [];
}
var searchDebugText = $"{query}{(HasTag ? "+" : string.Empty)}{_tag}";
string searchDebugText = $"{query}{(HasTag ? "+" : string.Empty)}{_tag}";
Logger.LogDebug($"Starting search for '{searchDebugText}'");
HashSet<CatalogPackage> results = new(new PackageIdCompare());
@@ -273,19 +271,7 @@ internal sealed partial class WinGetExtensionPage : DynamicListPage, IDisposable
return results;
}
protected override void Dispose(bool disposing)
{
if (!_disposed)
{
_disposed = true;
if (disposing)
{
_cancellationTokenSource?.Dispose();
}
}
base.Dispose(disposing);
}
public void Dispose() => throw new NotImplementedException();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "I just like it")]

View File

@@ -46,17 +46,21 @@ internal sealed partial class WindowWalkerListPage : DynamicListPage, IDisposabl
public override IListItem[] GetItems() => Query(SearchText).ToArray();
protected override void Dispose(bool disposing)
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
public void Dispose(bool disposing)
{
if (!_disposed)
{
_disposed = true;
if (disposing)
{
_cancellationTokenSource?.Dispose();
_disposed = true;
}
}
base.Dispose(disposing);
}
}

View File

@@ -10,39 +10,12 @@ namespace Microsoft.CommandPalette.Extensions.Toolkit;
// asynchronously, so as to not block the extension app while it's being
// processed in the host app.
// (also consider this for ItemsChanged in ListPage)
public partial class BaseObservable : INotifyPropChanged, IDisposable
public partial class BaseObservable : INotifyPropChanged
{
private bool _isDisposed;
public event TypedEventHandler<object, IPropChangedEventArgs>? PropChanged;
// Protected implementation of Dispose pattern.
protected virtual void Dispose(bool disposing)
{
if (!_isDisposed)
{
_isDisposed = true;
if (disposing)
{
PropChanged = null;
}
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected void OnPropertyChanged(string propertyName)
{
if (_isDisposed)
{
return;
}
try
{
// TODO #181 - This is dangerous! If the original host goes away,

View File

@@ -6,7 +6,7 @@ using Windows.Foundation;
namespace Microsoft.CommandPalette.Extensions.Toolkit;
public partial class ListPage : Page, IListPage, IDisposable
public partial class ListPage : Page, IListPage
{
private string _placeholderText = string.Empty;
private string _searchText = string.Empty;
@@ -15,7 +15,6 @@ public partial class ListPage : Page, IListPage, IDisposable
private IFilters? _filters;
private IGridProperties? _gridProperties;
private ICommandItem? _emptyContent;
private bool _isDisposed;
public event TypedEventHandler<object, IItemsChangedEventArgs>? ItemsChanged;
@@ -95,28 +94,8 @@ public partial class ListPage : Page, IListPage, IDisposable
{
}
protected override void Dispose(bool disposing)
{
if (!_isDisposed)
{
_isDisposed = true;
if (disposing)
{
ItemsChanged = null;
}
}
base.Dispose(disposing);
}
protected void RaiseItemsChanged(int totalItems = -1)
{
if (_isDisposed)
{
return;
}
try
{
// TODO #181 - This is the same thing that BaseObservable has to deal with.

View File

@@ -16,7 +16,7 @@
// project, where bugs will be filed
"org": "microsoft",
"project": "OS",
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
"IterationPath": "OS\\Future"
},

View File

@@ -11,7 +11,7 @@
// project, where bugs will be filed
"org": "microsoft",
"project": "OS",
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
"IterationPath": "OS\\Future"
},

View File

@@ -19,7 +19,7 @@
// project, where bugs will be filed
"org": "microsoft",
"project": "OS",
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
"IterationPath": "OS\\Future"
},
@@ -60,7 +60,7 @@
// project, where bugs will be filed
"org": "microsoft",
"project": "OS",
"AssignedTo": "leilzh@microsoft.com",
"AssignedTo": "PowerToys@microsoft.com",
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DFX-Developer Fundamentals and Experiences\\DEFT\\SALT",
"IterationPath": "OS\\Future"
},