removing some older references, breaking stuff into diff class files

This commit is contained in:
Clint Rutkas
2024-08-28 23:13:57 -07:00
parent b29d8cdb8b
commit 2bc3606b59
19 changed files with 281 additions and 259 deletions

View File

@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using Windows.Foundation;
using Microsoft.Windows.CommandPalette.Extensions;
using Windows.UI;
namespace Microsoft.Windows.CommandPalette.Extensions.Helpers;
// TODO! We probably want to have OnPropertyChanged raise the event

View File

@@ -1,15 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wox.Infrastructure;
namespace Microsoft.Windows.CommandPalette.Extensions.Helpers;
public class ListHelpers
{
// Generate a score for a list item.

View File

@@ -7,7 +7,7 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
namespace Wox.Infrastructure;
namespace Microsoft.Windows.CommandPalette.Extensions.Helpers;
public class MatchOption
{

View File

@@ -2,13 +2,11 @@
// 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;
using System.Runtime.CompilerServices;
using static Wox.Infrastructure.StringMatcher;
[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
namespace Wox.Infrastructure;
namespace Microsoft.Windows.CommandPalette.Extensions.Helpers;
public class MatchResult
{

View File

@@ -23,7 +23,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" >
<PackageReference Include="Microsoft.Windows.CsWin32">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View File

@@ -0,0 +1,16 @@
// 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.
//[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
//[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.System.UnitTests")]
//[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests")]
namespace Microsoft.Windows.CommandPalette.Extensions.Helpers;
public enum SearchPrecisionScore
{
Regular = 50,
Low = 20,
None = 0,
}

View File

@@ -2,17 +2,13 @@
// 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.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
//[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
//[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.System.UnitTests")]
//[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests")]
namespace Wox.Infrastructure;
namespace Microsoft.Windows.CommandPalette.Extensions.Helpers;
public class StringMatcher
{
@@ -311,11 +307,4 @@ public class StringMatcher
return score;
}
public enum SearchPrecisionScore
{
Regular = 50,
Low = 20,
None = 0,
}
}
}

View File

@@ -1,219 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Windows.CommandPalette.Extensions;
using AllApps.Programs;
using System.Diagnostics;
using Wox.Infrastructure;
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
namespace AllApps;
public sealed class AppCache
{
internal IList<Win32Program> Win32s = AllApps.Programs.Win32Program.All();
internal IList<UWPApplication> UWPs = Programs.UWP.All();
public static readonly Lazy<AppCache> Instance = new(() => new());
}
internal sealed class AppItem {
public string Name { get; set; } = "";
public string Subtitle { get; set; } = "";
public string IcoPath { get; set; } = "";
public string ExePath { get; set; } = "";
public string DirPath { get; set; } = "";
public string UserModelId { get; set; } = "";
public AppItem()
{
}
}
// 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;
internal static async Task LaunchTarget(string t)
{
await Task.Run(() =>
{
Process.Start(new ProcessStartInfo(t) { UseShellExecute = true });
});
}
public override ActionResult Invoke()
{
LaunchTarget(this._Target).Start();
return ActionResult.GoHome();
}
}
internal sealed class AppAction : InvokableCommand
{
private readonly AppItem _app;
internal AppAction(AppItem app) {
this._Name = "Run";
this._app = app;
this._Icon = new(_app.IcoPath);
}
internal static async Task StartApp(string amuid)
{
var appManager = new ApplicationActivationManager();
const ActivateOptions noFlags = ActivateOptions.None;
await Task.Run(() =>
{
try
{
appManager.ActivateApplication(amuid, /*queryArguments*/ "", noFlags, out var unusedPid);
}
catch (System.Exception)
{
}
}).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))
{
await StartApp(_app.UserModelId);
}
else
{
await StartExe(_app.ExePath);
}
}
public override ActionResult Invoke()
{
_ = Launch();
return ActionResult.GoHome();
}
}
internal sealed class AppListItem : ListItem
{
private readonly AppItem app;
public AppListItem(AppItem app) : base(new AppAction(app))
{
this.app = app;
this.Title = app.Name;
this.Subtitle = app.Subtitle;
this.Details = new Details() { Title = this.Title, HeroImage = this.Command.Icon, Body="### App" };
this.Tags = [new Tag() { Text = "App" }];
if (string.IsNullOrEmpty(app.UserModelId))
{
// Win32 exe or other non UWP app
this._MoreCommands = [
new CommandContextItem(new OpenPathAction(app.DirPath){ Name = "Open location", Icon=new("\ue838") })
];
}
else
{
// UWP app
this._MoreCommands = [];
}
}
}
public sealed class AllAppsPage : ListPage
{
private ISection allAppsSection;
public AllAppsPage()
{
StringMatcher.Instance = new StringMatcher();
this.Name = "All Apps";
this.Icon = new("\ue71d");
this.ShowDetails = true;
this.Loading = true;
this.PlaceholderText = "Search installed apps...";
}
public override ISection[] GetItems()
{
if (this.allAppsSection == null)
{
PopulateApps();
}
return [ this.allAppsSection ];
}
private void PopulateApps()
{
var apps = GetPrograms();
this.Loading = false;
this.allAppsSection = new ListSection()
{
Title = "Apps",
Items = apps
.Select((app) => new AppListItem(app))
.ToArray()
};
}
internal static List<AppItem> GetPrograms()
{
// NOTE TO SELF:
//
// There's logic in Win32Program.All() here to pick the "sources" for programs.
// I've manually hardcoded it to:
// * StartMenuProgramPaths
// * DesktopProgramPaths
// * RegistryAppProgramPaths
// for now. I've disabled the "PATH" source too, because it's n o i s y
//
// This also doesn't include Packaged apps, cause they're enumerated entirely seperately.
var cache = AppCache.Instance.Value;
var uwps = cache.UWPs;
var win32s = cache.Win32s;
var uwpResults = uwps
.Where((application)=>application.Enabled /*&& application.Valid*/)
.Select(app =>
new AppItem
{
Name = app.Name,
Subtitle = app.Description,
IcoPath = app.LogoType != LogoType.Error? app.LogoPath : "",
//ExePath = app.FullPath,
DirPath = app.Location,
UserModelId = app.UserModelId,
});
var win32Results = win32s
.Where((application) => application.Enabled /*&& application.Valid*/)
.Select(app =>
new AppItem
{
Name = app.Name,
Subtitle = app.Description,
IcoPath = app.FullPath, // similarly, this should be IcoPath, but :shrug:
ExePath = app.FullPath,
DirPath = app.Location,
});
return uwpResults.Concat(win32Results).OrderBy(app=>app.Name).ToList();
}
}
//internal sealed class AppAndScore
//{
// public AppItem app;
// public int score;
//}
//internal sealed class AppSearchState
//{
// public string Query { get; set; } = "";
// public List<AppAndScore> Results { get; set; } = new();
//}

View File

@@ -0,0 +1,102 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.Linq;
using Microsoft.Windows.CommandPalette.Extensions;
using AllApps.Programs;
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
namespace AllApps;
public sealed class AllAppsPage : ListPage
{
private ISection allAppsSection;
public AllAppsPage()
{
StringMatcher.Instance = new StringMatcher();
this.Name = "All Apps";
this.Icon = new("\ue71d");
this.ShowDetails = true;
this.Loading = true;
this.PlaceholderText = "Search installed apps...";
}
public override ISection[] GetItems()
{
if (this.allAppsSection == null)
{
PopulateApps();
}
return [this.allAppsSection];
}
private void PopulateApps()
{
var apps = GetPrograms();
this.Loading = false;
this.allAppsSection = new ListSection()
{
Title = "Apps",
Items = apps
.Select((app) => new AppListItem(app))
.ToArray()
};
}
internal static List<AppItem> GetPrograms()
{
// NOTE TO SELF:
//
// There's logic in Win32Program.All() here to pick the "sources" for programs.
// I've manually hardcoded it to:
// * StartMenuProgramPaths
// * DesktopProgramPaths
// * RegistryAppProgramPaths
// for now. I've disabled the "PATH" source too, because it's n o i s y
//
// This also doesn't include Packaged apps, cause they're enumerated entirely seperately.
var cache = AppCache.Instance.Value;
var uwps = cache.UWPs;
var win32s = cache.Win32s;
var uwpResults = uwps
.Where((application) => application.Enabled /*&& application.Valid*/)
.Select(app =>
new AppItem
{
Name = app.Name,
Subtitle = app.Description,
IcoPath = app.LogoType != LogoType.Error ? app.LogoPath : "",
//ExePath = app.FullPath,
DirPath = app.Location,
UserModelId = app.UserModelId,
});
var win32Results = win32s
.Where((application) => application.Enabled /*&& application.Valid*/)
.Select(app =>
new AppItem
{
Name = app.Name,
Subtitle = app.Description,
IcoPath = app.FullPath, // similarly, this should be IcoPath, but :shrug:
ExePath = app.FullPath,
DirPath = app.Location,
});
return uwpResults.Concat(win32Results).OrderBy(app => app.Name).ToList();
}
}
//internal sealed class AppAndScore
//{
// public AppItem app;
// public int score;
//}
//internal sealed class AppSearchState
//{
// public string Query { get; set; } = "";
// public List<AppAndScore> Results { get; set; } = new();
//}

View File

@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Threading.Tasks;
using AllApps.Programs;
using System.Diagnostics;
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
namespace AllApps;
internal sealed class AppAction : InvokableCommand
{
private readonly AppItem _app;
internal AppAction(AppItem app)
{
this._Name = "Run";
this._app = app;
this._Icon = new(_app.IcoPath);
}
internal static async Task StartApp(string amuid)
{
var appManager = new ApplicationActivationManager();
const ActivateOptions noFlags = ActivateOptions.None;
await Task.Run(() =>
{
try
{
appManager.ActivateApplication(amuid, /*queryArguments*/ "", noFlags, out var unusedPid);
}
catch (System.Exception)
{
}
}).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))
{
await StartApp(_app.UserModelId);
}
else
{
await StartExe(_app.ExePath);
}
}
public override ActionResult Invoke()
{
_ = Launch();
return ActionResult.GoHome();
}
}

View File

@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using AllApps.Programs;
namespace AllApps;
public sealed class AppCache
{
internal IList<Win32Program> Win32s = AllApps.Programs.Win32Program.All();
internal IList<UWPApplication> UWPs = Programs.UWP.All();
public static readonly Lazy<AppCache> Instance = new(() => new());
}

View File

@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace AllApps;
internal sealed class AppItem
{
public string Name { get; set; } = "";
public string Subtitle { get; set; } = "";
public string IcoPath { get; set; } = "";
public string ExePath { get; set; } = "";
public string DirPath { get; set; } = "";
public string UserModelId { get; set; } = "";
public AppItem()
{
}
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
namespace AllApps;
internal sealed class AppListItem : ListItem
{
private readonly AppItem app;
public AppListItem(AppItem app) : base(new AppAction(app))
{
this.app = app;
this.Title = app.Name;
this.Subtitle = app.Subtitle;
this.Details = new Details() { Title = this.Title, HeroImage = this.Command.Icon, Body = "### App" };
this.Tags = [new Tag() { Text = "App" }];
if (string.IsNullOrEmpty(app.UserModelId))
{
// Win32 exe or other non UWP app
this._MoreCommands = [
new CommandContextItem(new OpenPathAction(app.DirPath){ Name = "Open location", Icon=new("\ue838") })
];
}
else
{
// UWP app
this._MoreCommands = [];
}
}
}

View File

@@ -5,7 +5,7 @@
using System.Diagnostics;
using System.IO.Abstractions;
namespace Wox.Infrastructure.FileSystemHelper;
namespace AllApps;
public class FileVersionInfoWrapper : IFileVersionInfoWrapper
{

View File

@@ -4,7 +4,7 @@
using System.Diagnostics;
namespace Wox.Infrastructure.FileSystemHelper;
namespace AllApps;
public interface IFileVersionInfoWrapper
{

View File

@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
namespace 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;
internal static async Task LaunchTarget(string t)
{
await Task.Run(() =>
{
Process.Start(new ProcessStartInfo(t) { UseShellExecute = true });
});
}
public override ActionResult Invoke()
{
LaunchTarget(this._Target).Start();
return ActionResult.GoHome();
}
}

View File

@@ -2,7 +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.
namespace Wox.Infrastructure;
namespace AllApps;
public interface IShellLinkHelper
{

View File

@@ -9,7 +9,7 @@ using System.Text;
//using Accessibility;
//using Wox.Plugin.Logger;
namespace Wox.Infrastructure;
namespace AllApps;
public class ShellLinkHelper : IShellLinkHelper
{

View File

@@ -5,20 +5,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Security;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Input;
// using Microsoft.Plugin.Program.Logger;
// using Microsoft.Plugin.Program.Utils;
using Microsoft.Win32;
using Wox.Infrastructure;
using Wox.Infrastructure.FileSystemHelper;
// using Wox.Plugin;
// using Wox.Plugin.Logger;
// using DirectoryWrapper = Wox.Infrastructure.FileSystemHelper.DirectoryWrapper;