/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/cmdpal/Microsoft.CmdPal.UI/RunHistoryService.cs
85 строк
3 KB
Mike Griese
CmdPal: fix initializing the Run history in AOT builds (#48463)
18 июн 2026, 20:55
Не верифицирован
18 июн 2026, 20:55
fb0f429
Код
Авторство
О чём код?
// 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 System.Collections.Immutable; using Microsoft.CmdPal.Common.Services; using Microsoft.CmdPal.Ext.Run; using Microsoft.CmdPal.UI.ViewModels; using Microsoft.CmdPal.UI.ViewModels.Services; namespace Microsoft.CmdPal.UI; internal sealed class RunHistoryService : IRunHistoryService { private readonly IAppStateService _appStateService; public RunHistoryService(IAppStateService appStateService) { _appStateService = appStateService; } public IReadOnlyList<string> GetRunHistory() { if (_appStateService.State.RunHistory.IsEmpty) { var history = Microsoft.Terminal.UI.RunHistory.CreateRunHistory(); // Copy the WinRT-projected IVector<string> into a plain List<string> // before building the ImmutableList. ImmutableList.CreateRange tries to // cast the source to IReadOnlyCollection<string>, which requires a WinRT // helper type that isn't available in AOT builds and throws // NotSupportedException. var historyList = new List<string>(history.Count); for (var i = 0; i < history.Count; i++) { historyList.Add(history[i]); } _appStateService.UpdateState(state => state with { RunHistory = historyList.ToImmutableList(), }); } return _appStateService.State.RunHistory; } public void ClearRunHistory() { _appStateService.UpdateState(state => state with { RunHistory = ImmutableList<string>.Empty, }); } public void AddRunHistoryItem(string item) { if (string.IsNullOrWhiteSpace(item)) { return; } _appStateService.UpdateState(state => state with { RunHistory = state.RunHistory .Remove(item) .Insert(0, item), }); } public long RunCommand(string commandLine, string workingDir, bool asAdmin, ulong hwnd) { return RunHistory.ExecuteCommandline(commandLine, workingDir, hwnd, asAdmin); } public ParseCommandlineResult ParseCommandline(string commandLine, string workingDirectory) { return RunHistory.ParseCommandline(commandLine, workingDirectory); } public string QualifyCommandLineDirectory(string commandLine, string fullFilePath, string defaultDirectory) { return RunHistory.QualifyCommandLineDirectory(commandLine, fullFilePath, defaultDirectory); } }