Skip to content

Commit

Permalink
Program plugin fully on stylecop (#5964)
Browse files Browse the repository at this point in the history
  • Loading branch information
crutkas committed Aug 14, 2020
1 parent be5d58c commit e0a1b47
Show file tree
Hide file tree
Showing 31 changed files with 361 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class UWPTests
public void AllShouldReturnPackagesWithDevelopmentModeWhenCalled()
{
// Arrange
Main._settings = new ProgramPluginSettings();
Main.Settings = new ProgramPluginSettings();
List<IPackage> packages = new List<IPackage>() { DevelopmentModeApp, PackagedApp };
var mock = new Mock<IPackageManager>();
mock.Setup(x => x.FindPackagesForCurrentUser()).Returns(packages);
Expand All @@ -60,7 +60,7 @@ public void AllShouldReturnPackagesWithDevelopmentModeWhenCalled()
public void AllShouldNotReturnPackageFrameworksWhenCalled()
{
// Arrange
Main._settings = new ProgramPluginSettings();
Main.Settings = new ProgramPluginSettings();
List<IPackage> packages = new List<IPackage>() { FrameworkApp, PackagedApp };
var mock = new Mock<IPackageManager>();
mock.Setup(x => x.FindPackagesForCurrentUser()).Returns(packages);
Expand All @@ -79,7 +79,7 @@ public void PowerToysRunShouldNotAddInvalidAppWhenIndexingUWPApplications()
{
// Arrange
PackageWrapper invalidPackagedApp = new PackageWrapper();
Main._settings = new ProgramPluginSettings();
Main.Settings = new ProgramPluginSettings();
List<IPackage> packages = new List<IPackage>() { invalidPackagedApp };
var mock = new Mock<IPackageManager>();
mock.Setup(x => x.FindPackagesForCurrentUser()).Returns(packages);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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 Microsoft.Plugin.Program
{
public class DisabledProgramSource : ProgramSource
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ internal static void LogException(string classname, string callingMethodName, st

innerExceptionNumber++;
e = e.InnerException;
} while (e != null);
}
while (e != null);

logger.Error("------------- END Microsoft.Plugin.Program exception -------------");
}
Expand Down
27 changes: 11 additions & 16 deletions src/modules/launcher/Plugins/Microsoft.Plugin.Program/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Threading.Tasks;
using Microsoft.Plugin.Program.Programs;
using Microsoft.Plugin.Program.Storage;
using Microsoft.PowerToys.Settings.UI.Lib;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
Expand All @@ -19,9 +18,9 @@ namespace Microsoft.Plugin.Program
{
public class Main : IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable, IDisposable
{
internal static ProgramPluginSettings _settings { get; set; }
internal static ProgramPluginSettings Settings { get; set; }

private static bool IsStartupIndexProgramsRequired => _settings.LastIndexTime.AddDays(3) < DateTime.Today;
private static bool IsStartupIndexProgramsRequired => Settings.LastIndexTime.AddDays(3) < DateTime.Today;

private static PluginInitContext _context;

Expand All @@ -34,13 +33,13 @@ public class Main : IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable, I
public Main()
{
_settingsStorage = new PluginJsonStorage<ProgramPluginSettings>();
_settings = _settingsStorage.Load();
Settings = _settingsStorage.Load();

// This helper class initializes the file system watchers based on the locations to watch
_win32ProgramRepositoryHelper = new Win32ProgramFileSystemWatchers();

// Initialize the Win32ProgramRepository with the settings object
_win32ProgramRepository = new Win32ProgramRepository(_win32ProgramRepositoryHelper._fileSystemWatchers.Cast<IFileSystemWatcherWrapper>().ToList(), new BinaryStorage<IList<Programs.Win32Program>>("Win32"), _settings, _win32ProgramRepositoryHelper._pathsToWatch);
_win32ProgramRepository = new Win32ProgramRepository(_win32ProgramRepositoryHelper.FileSystemWatchers.Cast<IFileSystemWatcherWrapper>().ToList(), new BinaryStorage<IList<Programs.Win32Program>>("Win32"), Settings, _win32ProgramRepositoryHelper.PathsToWatch);

Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Preload programs cost", () =>
{
Expand All @@ -67,7 +66,7 @@ public Main()

Task.WaitAll(a, b);

_settings.LastIndexTime = DateTime.Today;
Settings.LastIndexTime = DateTime.Today;
}

public void Save()
Expand All @@ -89,7 +88,7 @@ public List<Result> Query(Query query)

var result = results1.Concat(results2).Where(r => r != null && r.Score > 0);
var maxScore = result.Max(x => x.Score);
result = result.Where(x => x.Score > _settings.MinScoreThreshold * maxScore);
result = result.Where(x => x.Score > Settings.MinScoreThreshold * maxScore);

return result.ToList();
}
Expand All @@ -98,12 +97,13 @@ public void Init(PluginInitContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_context.API.ThemeChanged += OnThemeChanged;

UpdateUWPIconPath(_context.API.GetCurrentTheme());
}

public void OnThemeChanged(Theme _, Theme currentTheme)
public void OnThemeChanged(Theme currentTheme, Theme newTheme)
{
UpdateUWPIconPath(currentTheme);
UpdateUWPIconPath(newTheme);
}

public void UpdateUWPIconPath(Theme theme)
Expand All @@ -121,7 +121,7 @@ public void IndexPrograms()

Task.WaitAll(t1, t2);

_settings.LastIndexTime = DateTime.Today;
Settings.LastIndexTime = DateTime.Today;
}

public string GetTranslatedPluginTitle()
Expand All @@ -142,8 +142,7 @@ public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
}

var menuOptions = new List<ContextMenuResult>();
var program = selectedResult.ContextData as Programs.IProgram;
if (program != null)
if (selectedResult.ContextData is Programs.IProgram program)
{
menuOptions = program.ContextMenus(_context.API);
}
Expand Down Expand Up @@ -180,10 +179,6 @@ public void ReloadData()
{
IndexPrograms();
}

public static void UpdateSettings(PowerLauncherSettings _)
{
}

public void Dispose()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
</AssemblyAttribute>
</ItemGroup>

<!--<ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
Expand All @@ -154,5 +154,5 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>-->
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Collections.Generic;
using System.IO;

namespace Microsoft.Plugin.Program
{
Expand All @@ -30,29 +29,4 @@ public class ProgramPluginSettings

internal const char SuffixSeparator = ';';
}

/// <summary>
/// Contains user added folder location contents as well as all user disabled applications
/// </summary>
/// <remarks>
/// <para>Win32 class applications set UniqueIdentifier using their full file path</para>
/// <para>UWP class applications set UniqueIdentifier using their Application User Model ID</para>
/// <para>Custom user added program sources set UniqueIdentifier using their location</para>
/// </remarks>
public class ProgramSource
{
private string name;

public string Location { get; set; }

public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }

public bool Enabled { get; set; } = true;

public string UniqueIdentifier { get; set; }
}

public class DisabledProgramSource : ProgramSource
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.IO;

namespace Microsoft.Plugin.Program
{
/// <summary>
/// Contains user added folder location contents as well as all user disabled applications
/// </summary>
/// <remarks>
/// <para>Win32 class applications set UniqueIdentifier using their full file path</para>
/// <para>UWP class applications set UniqueIdentifier using their Application User Model ID</para>
/// <para>Custom user added program sources set UniqueIdentifier using their location</para>
/// </remarks>
public class ProgramSource
{
private string name;

public string Location { get; set; }

public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }

public bool Enabled { get; set; } = true;

public string UniqueIdentifier { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
// 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.

// 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;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
{
// Reference : https://github.com/MicrosoftEdge/edge-launcher/blob/108e63df0b4cb5cd9d5e45aa7a264690851ec51d/MIcrosoftEdgeLauncherCsharp/Program.cs
[Flags]
public enum ActivateOptions
{
None = 0x00000000,
DesignMode = 0x00000001,
NoErrorUI = 0x00000002,
NoSplashScreen = 0x00000004,
}

// ApplicationActivationManager
[ComImport]
[Guid("2e941141-7f97-4756-ba1d-9decde894a3d")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IApplicationActivationManager
{
IntPtr ActivateApplication([In] string appUserModelId, [In] string arguments, [In] ActivateOptions options, [Out] out uint processId);

IntPtr ActivateForFile([In] string appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] string verb, [Out] out uint processId);

IntPtr ActivateForProtocol([In] string appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out uint processId);
}

{
// Application Activation Manager Class
[ComImport]
[ComImport]
[Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]
public class ApplicationActivationManager : IApplicationActivationManager
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

using System;
using System.Runtime.InteropServices;

namespace Microsoft.Plugin.Program.Programs
{
// Reference : https://stackoverflow.com/questions/32122679/getting-icon-of-modern-windows-app-from-a-desktop-application
[Guid("5842a140-ff9f-4166-8f5c-62f5b7b0c781")]
[ComImport]
public class AppxFactory
{
}
}

0 comments on commit e0a1b47

Please sign in to comment.