more baseline cleanup efforts

This commit is contained in:
Clint Rutkas
2024-09-04 20:58:15 -07:00
parent 5001d88c44
commit fd464f1a3a
25 changed files with 79 additions and 122 deletions

View File

@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using System.Threading.Tasks;
using AllApps.Programs;
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
@@ -19,6 +18,7 @@ internal sealed class AppAction : InvokableCommand
this._app = app;
this._Icon = new(_app.IcoPath);
}
internal static async Task StartApp(string amuid)
{
var appManager = new ApplicationActivationManager();
@@ -34,15 +34,18 @@ internal sealed class AppAction : InvokableCommand
}
}).ConfigureAwait(false);
}
internal static async Task StartExe(string path)
{
var appManager = new ApplicationActivationManager();
// const ActivateOptions noFlags = ActivateOptions.None;
await Task.Run(() =>
{
Process.Start(new ProcessStartInfo(path) { UseShellExecute = true });
});
}
internal async Task Launch()
{
if (string.IsNullOrEmpty(_app.ExePath))
@@ -54,6 +57,7 @@ internal sealed class AppAction : InvokableCommand
await StartExe(_app.ExePath);
}
}
public override ActionResult Invoke()
{
_ = Launch();

View File

@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
namespace WindowsCommandPalette.BuiltinCommands.AllApps;
@@ -11,7 +10,8 @@ namespace WindowsCommandPalette.BuiltinCommands.AllApps;
// NOTE this is pretty close to what we'd put in the SDK
internal sealed class OpenPathAction(string target) : InvokableCommand
{
private readonly string _Target = target;
private readonly string _target = target;
internal static async Task LaunchTarget(string t)
{
await Task.Run(() =>
@@ -19,9 +19,11 @@ internal sealed class OpenPathAction(string target) : InvokableCommand
Process.Start(new ProcessStartInfo(t) { UseShellExecute = true });
});
}
public override ActionResult Invoke()
{
LaunchTarget(this._Target).Start();
LaunchTarget(_target).Start();
return ActionResult.GoHome();
}
}

View File

@@ -2,7 +2,6 @@
// 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;
using System.Runtime.InteropServices;
namespace AllApps.Programs;
@@ -12,4 +11,4 @@ namespace AllApps.Programs;
[ComImport]
public class AppxFactory
{
}
}

View File

@@ -2,7 +2,6 @@
// 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;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -44,4 +43,4 @@ public class ApplicationActivationManager : IApplicationActivationManager
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public extern IntPtr ActivateForProtocol([In] string appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out uint processId);
}
}

View File

@@ -17,4 +17,4 @@ public interface IAppxFactory
void _VtblGap0_2(); // skip 2 methods
internal IAppxManifestReader CreateManifestReader(IStream inputStream);
}
}

View File

@@ -2,9 +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;
using System.Runtime.InteropServices;
// using Wox.Plugin.Common.Win32;
namespace AllApps.Programs;
@@ -17,4 +15,4 @@ public interface IAppxManifestApplication
[PreserveSig]
int GetAppUserModelId([MarshalAs(UnmanagedType.LPWStr)] out string value);
}
}

View File

@@ -17,4 +17,4 @@ namespace AllApps.Programs
bool MoveNext();
}
}
}

View File

@@ -2,9 +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;
using System.Runtime.InteropServices;
// using Wox.Plugin.Common.Win32;
namespace AllApps.Programs
{
@@ -18,4 +16,4 @@ namespace AllApps.Programs
[PreserveSig]
int GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
}
}
}

View File

@@ -24,4 +24,4 @@ public interface IAppxManifestReader
void _VtblGap1_5(); // skip 5 methods
IAppxManifestApplicationsEnumerator GetApplications();
}
}

View File

@@ -2,20 +2,19 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace AllApps.Programs
namespace AllApps.Programs;
public interface IPackage
{
public interface IPackage
{
string Name { get; }
string Name { get; }
string FullName { get; }
string FullName { get; }
string FamilyName { get; }
string FamilyName { get; }
bool IsFramework { get; }
bool IsFramework { get; }
bool IsDevelopmentMode { get; }
bool IsDevelopmentMode { get; }
string InstalledLocation { get; }
}
}
string InstalledLocation { get; }
}

View File

@@ -2,12 +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.Collections.Generic;
namespace AllApps.Programs;
namespace AllApps.Programs
public interface IPackageManager
{
public interface IPackageManager
{
IEnumerable<IPackage> FindPackagesForCurrentUser();
}
}
IEnumerable<IPackage> FindPackagesForCurrentUser();
}

View File

@@ -23,13 +23,13 @@ public sealed class FilteredListSection : ISection, INotifyCollectionChanged
public string Title => string.Empty;
private readonly MainViewModel _mainViewModel;
private readonly DispatcherQueue DispatcherQueue = DispatcherQueue.GetForCurrentThread();
private readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
// Top-level list items, from builtin commands and extensions
internal ObservableCollection<MainListItem> _Items { get; set; }
public ObservableCollection<MainListItem> TopLevelItems { get; set; }
// Apps, from the apps built in command.
private IEnumerable<IListItem> _apps => _mainViewModel.apps.GetItems().First().Items;
private IEnumerable<IListItem> AllApps => _mainViewModel.apps.GetItems().First().Items;
// Results from the last searched text
private IEnumerable<IListItem>? lastSearchResults;
@@ -40,21 +40,21 @@ public sealed class FilteredListSection : ISection, INotifyCollectionChanged
// * OR one of:
// * Just the top-level actions (if there's no query)
// * OR the top-level actions AND the apps (if there's a query)
private IEnumerable<IListItem> itemsToEnumerate =>
private IEnumerable<IListItem> ItemsToEnumerate =>
lastSearchResults != null ?
lastSearchResults :
_Items.Concat(_apps);
TopLevelItems.Concat(AllApps);
internal string lastQuery = string.Empty;
private string _lastQuery = string.Empty;
// Setting this will enumerate all the actions and installed apps.
internal string Query
{
get => lastQuery;
get => _lastQuery;
set
{
if (string.IsNullOrEmpty(value) ||
!lastQuery.StartsWith(value, true, System.Globalization.CultureInfo.CurrentCulture))
!_lastQuery.StartsWith(value, true, System.Globalization.CultureInfo.CurrentCulture))
{
lastSearchResults = null;
}
@@ -66,8 +66,8 @@ public sealed class FilteredListSection : ISection, INotifyCollectionChanged
this.lastSearchResults = null;
}
lastQuery = value;
var results = ListHelpers.FilterList(itemsToEnumerate, Query);
_lastQuery = value;
var results = ListHelpers.FilterList(ItemsToEnumerate, Query);
this.lastSearchResults = string.IsNullOrEmpty(value) ? null : results;
}
}
@@ -81,20 +81,20 @@ public sealed class FilteredListSection : ISection, INotifyCollectionChanged
//
// instead run the query once when the action query changes, and store the
// results.
public IListItem[] Items => itemsToEnumerate.Where(i => i != null).ToArray();
public IListItem[] Items => ItemsToEnumerate.Where(i => i != null).ToArray();
public FilteredListSection(MainViewModel viewModel)
{
this._mainViewModel = viewModel;
// TODO: We should probably just get rid of MainListItem entirely, so I'm leaveing these uncaught
_Items = new(_mainViewModel.TopLevelCommands.Where(wrapper => wrapper.Unsafe != null).Select(wrapper => new MainListItem(wrapper.Unsafe!)));
_Items.CollectionChanged += Bubble_CollectionChanged;
TopLevelItems = new(_mainViewModel.TopLevelCommands.Where(wrapper => wrapper.Unsafe != null).Select(wrapper => new MainListItem(wrapper.Unsafe!)));
TopLevelItems.CollectionChanged += Bubble_CollectionChanged;
}
private void Bubble_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
DispatcherQueue.TryEnqueue(() =>
_dispatcherQueue.TryEnqueue(() =>
{
CollectionChanged?.Invoke(this, e);
});
@@ -102,7 +102,7 @@ public sealed class FilteredListSection : ISection, INotifyCollectionChanged
internal void Reset()
{
_Items.Clear();
TopLevelItems.Clear();
lastSearchResults = null;
}
}

View File

@@ -48,6 +48,7 @@ public sealed class MainListItem : ListItem
{
this.MoreCommands = this._listItem.MoreCommands;
}
OnPropertyChanged(args.PropertyName);
}
}

View File

@@ -16,7 +16,7 @@ public sealed class MainListPage : DynamicListPage
private readonly MainListSection _mainSection;
private readonly RecentsListSection _recentsListSection;
private readonly FilteredListSection _filteredSection;
private readonly ISection[] _Sections;
private readonly ISection[] _sections;
public MainListPage(MainViewModel viewModel)
{
@@ -28,7 +28,7 @@ public sealed class MainListPage : DynamicListPage
_mainViewModel.TopLevelCommands.CollectionChanged += TopLevelCommands_CollectionChanged;
_Sections = [
_sections = [
_recentsListSection,
_mainSection
];
@@ -40,7 +40,7 @@ public sealed class MainListPage : DynamicListPage
public override ISection[] GetItems()
{
return _Sections;
return _sections;
}
public override ISection[] GetItems(string query)
@@ -49,7 +49,7 @@ public sealed class MainListPage : DynamicListPage
_mainSection.UpdateQuery(query);
if (string.IsNullOrEmpty(query))
{
return _Sections;
return _sections;
}
else
{
@@ -71,7 +71,7 @@ public sealed class MainListPage : DynamicListPage
_mainSection._Items.Add(new MainListItem(listItem.Unsafe));
}
_filteredSection._Items.Add(new MainListItem(listItem.Unsafe));
_filteredSection.TopLevelItems.Add(new MainListItem(listItem.Unsafe));
}
}
}

View File

@@ -22,7 +22,7 @@ public sealed class MainListSection : ISection, INotifyCollectionChanged
public string Title => "Actions";
private readonly MainViewModel _mainViewModel;
private readonly DispatcherQueue DispatcherQueue = DispatcherQueue.GetForCurrentThread();
private readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
// Top-level list items, from builtin commands and extensions
internal ObservableCollection<MainListItem> _Items { get; set; }
@@ -65,7 +65,7 @@ public sealed class MainListSection : ISection, INotifyCollectionChanged
private void Bubble_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
DispatcherQueue.TryEnqueue(() =>
_dispatcherQueue.TryEnqueue(() =>
{
CollectionChanged?.Invoke(this, e);
});

View File

@@ -1,18 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Runtime.InteropServices;
using Microsoft.CmdPal.Common.Services;
using Microsoft.Windows.CommandPalette.Extensions;
using Windows.ApplicationModel;
using Windows.ApplicationModel.AppExtensions;
using Windows.Win32;
using Windows.Win32.System.Com;
using WinRT;
// 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.
namespace CmdPal.Models;
public class ExtensionObject<T> // where T : IInspectable
public class ExtensionObject<T> // where T : IInspectable
{
private readonly T _value;

View File

@@ -22,7 +22,7 @@ public class ExtensionWrapper : IExtensionWrapper
private readonly Dictionary<Type, ProviderType> _providerTypeMap = new()
{
[typeof(ICommandProvider)] = ProviderType.Commands
[typeof(ICommandProvider)] = ProviderType.Commands,
};
private IExtension? _extensionObject;

View File

@@ -18,7 +18,7 @@ public sealed class RecentsListSection : ListSection, INotifyCollectionChanged
{
public event NotifyCollectionChangedEventHandler? CollectionChanged;
private readonly DispatcherQueue DispatcherQueue = DispatcherQueue.GetForCurrentThread();
private readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
private readonly MainViewModel _mainViewModel;
internal ObservableCollection<MainListItem> _Items { get; set; } = [];
@@ -46,7 +46,7 @@ public sealed class RecentsListSection : ListSection, INotifyCollectionChanged
private void Bubble_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
DispatcherQueue.TryEnqueue(() =>
_dispatcherQueue.TryEnqueue(() =>
{
CollectionChanged?.Invoke(this, e);
});

View File

@@ -16,8 +16,6 @@ namespace Microsoft.Windows.CommandPalette.Services;
public class ExtensionService : IExtensionService, IDisposable
{
// private readonly ILogger _log = Log.ForContext("SourceContext", nameof(ExtensionService));
public event EventHandler OnExtensionsChanged = (_, _) => { };
private static readonly PackageCatalog _catalog = PackageCatalog.OpenForCurrentUser();

View File

@@ -2,25 +2,10 @@
// 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;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.Terminal.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.CommandPalette.Extensions;
using Windows.ApplicationModel.AppExtensions;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
namespace DeveloperCommandPalette;
@@ -46,10 +31,10 @@ public sealed class TagViewModel : INotifyPropertyChanged
internal Brush BackgroundBrush => new SolidColorBrush(Tag.Color.A == 0 ? Tag.Color : Color.FromArgb((byte)(Tag.Color.A / 4), Tag.Color.R, Tag.Color.G, Tag.Color.B));
public TagViewModel(ITag tag)
{
this.Tag = tag;
// this.Tag.PropChanged += Tag_PropertyChanged;
}

View File

@@ -14,19 +14,19 @@ namespace WindowsCommandPalette.Views;
public sealed partial class FormPage : Page
{
private FormPageViewModel? ViewModel;
private readonly AdaptiveCardRenderer Renderer = new();
private FormPageViewModel? ViewModel;
public FormPage()
{
this.InitializeComponent();
UISettings settings = new UISettings();
// yep this is the way to check if you're in light theme or dark.
// yep it's this dumb
var foreground = settings.GetColorValue(UIColorType.Foreground);
var lightTheme = foreground.R < 128;
Renderer.HostConfig = AdaptiveHostConfig.FromJsonString(lightTheme ? LightHostConfig : DarkHostConfig).HostConfig;
}
private void AddCardElement(FormViewModel form)
@@ -39,9 +39,15 @@ public sealed partial class FormPage : Page
base.OnNavigatedTo(e);
ViewModel = (FormPageViewModel?)e.Parameter;
if (ViewModel == null) return;
ViewModel.InitialRender().ContinueWith((t) => {
DispatcherQueue.TryEnqueue(() => {
if (ViewModel == null)
{
return;
}
ViewModel.InitialRender().ContinueWith((t) =>
{
DispatcherQueue.TryEnqueue(() =>
{
foreach (var form in this.ViewModel.Forms)
{
AddCardElement(form);
@@ -62,7 +68,6 @@ public sealed partial class FormPage : Page
ViewModel?.GoBack();
}
private static readonly string DarkHostConfig = """
{
"spacing": {

View File

@@ -2,22 +2,15 @@
// 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;
using System.Collections.ObjectModel;
using System.ComponentModel;
using AdaptiveCards.ObjectModel.WinUI3;
using AdaptiveCards.Rendering.WinUI3;
using AdaptiveCards.Templating;
using DeveloperCommandPalette;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.CommandPalette.Extensions;
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
using Windows.Foundation;
using Windows.System;
using Windows.UI.ViewManagement;
namespace WindowsCommandPalette.Views;
@@ -90,6 +83,7 @@ public sealed class FormViewModel : System.ComponentModel.INotifyPropertyChanged
var inputs = args.Inputs.AsJson().Stringify();
_ = data;
_ = inputs;
// Process them as desired
var handlers = RequestSubmitForm;
handlers?.Invoke(this, new() { FormData = inputs, Form = form });

View File

@@ -3,18 +3,9 @@
// See the LICENSE file in the project root for more information.
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Runtime.InteropServices;
using DeveloperCommandPalette;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.CommandPalette.Extensions;
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
@@ -31,10 +22,11 @@ public sealed class ListPageViewModel : PageViewModel
private IDynamicListPage? dynamicPage => Page as IDynamicListPage;
private readonly DispatcherQueue DispatcherQueue = DispatcherQueue.GetForCurrentThread();
private readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
internal string Query = string.Empty;
public ListPageViewModel(IListPage page) : base(page)
public ListPageViewModel(IListPage page)
: base(page)
{
}

View File

@@ -37,7 +37,8 @@ public sealed partial class MarkdownPage : Page, INotifyPropertyChanged
return;
}
ViewModel.InitialRender(this).ContinueWith((t) => {
ViewModel.InitialRender(this).ContinueWith((t) =>
{
DispatcherQueue.TryEnqueue(() =>
{
if (ViewModel.MarkdownContent.Length > 0)

View File

@@ -2,14 +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.ComponentModel;
using DeveloperCommandPalette;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.CommandPalette.Extensions;
namespace WindowsCommandPalette.Views;