Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/Jarvis.Addin.Processes/Jarvis.Addin.Processes.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AE5C446D-B1D3-4E98-941D-A751B80CA74F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Jarvis.Addin.Processes</RootNamespace>
<AssemblyName>Jarvis.Addin.Processes</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=4.6.2.0, Culture=neutral, PublicKeyToken=17863af14b0044da">
<HintPath>..\packages\Autofac.4.6.2\lib\net45\Autofac.dll</HintPath>
</Reference>
<Reference Include="JetBrains.Annotations, Version=11.1.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325">
<HintPath>..\packages\JetBrains.Annotations.11.1.0\lib\net20\JetBrains.Annotations.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ProcessAddin.cs" />
<Compile Include="ProcessProvider.cs" />
<Compile Include="ProcessResult.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\stylecop.json" Link="stylecop.json" />
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Jarvis.Core\Jarvis.Core.csproj">
<Project>{5826d320-9026-4be9-8c82-893c55b80871}</Project>
<Name>Jarvis.Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
13 changes: 13 additions & 0 deletions src/Jarvis.Addin.Processes/ProcessAddin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Autofac;
using Jarvis.Core;

namespace Jarvis.Addin.Processes
{
public sealed class ProcessAddin : IAddin
{
public void Configure(ContainerBuilder builder)
{
builder.RegisterType<ProcessProvider>().As<IQueryProvider>().SingleInstance();
}
}
}
60 changes: 60 additions & 0 deletions src/Jarvis.Addin.Processes/ProcessProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Jarvis.Addin.Processes;
using Jarvis.Core;
using Jarvis.Core.Diagnostics;
using Jarvis.Core.Interop;
using Jarvis.Core.Scoring;
using JetBrains.Annotations;

namespace Jarvis.Addin.Processes
{
[UsedImplicitly]
internal sealed class ProcessProvider : QueryProvider<ProcessResult>
{
private readonly IJarvisLog _log;

public ProcessProvider(IJarvisLog log)
{
_log = log;
}

protected override Task<ImageSource> GetIconAsync(ProcessResult result)
{
return Task.FromResult(null as ImageSource);
}

public override Task<IEnumerable<IQueryResult>> QueryAsync(Query query)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the speed using C# Process class, when I was testing it got pretty slow

{
return Task.Run(() =>
{
var results = Process.GetProcesses()
.Where(process => process.MainWindowTitle.IndexOf(query.Raw, StringComparison.OrdinalIgnoreCase) >= 0)
.Select(process => (IQueryResult) new ProcessResult(process.Id, process.MainWindowTitle, process.ProcessName, LevenshteinScorer.Score(process.MainWindowTitle, query.Raw, false), LevenshteinScorer.Score(process.MainWindowTitle, query.Raw)))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should break line in the middle

.ToList();

return results.AsEnumerable();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simplify by removing results variable

});
}

protected override Task ExecuteAsync(ProcessResult result)
{
var process = Process.GetProcessById(result.ProcessId);
Win32.Window.SetForegroundWindow(process.MainWindowHandle);

var rect = new Win32.W32Rect();
Win32.Window.GetWindowRect(process.MainWindowHandle, ref rect);
if (rect.Top < 0 && rect.Right < 0 && rect.Bottom < 0 && rect.Left < 0) // Window is minimized
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
Win32.Window.ShowWindow(process.MainWindowHandle, 1);
}

return Task.CompletedTask;
}
}
}
51 changes: 51 additions & 0 deletions src/Jarvis.Addin.Processes/ProcessResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Diagnostics;
using Jarvis.Core;
using JetBrains.Annotations;

namespace Jarvis.Addin.Processes
{
[UsedImplicitly]
[DebuggerDisplay("{" + nameof(Title) + ",nq}")]
internal struct ProcessResult : IQueryResult, IEquatable<ProcessResult>
{
public int ProcessId { get; }
public string Title { get; }
public string Description { get; }
public float Distance { get; }
public float Score { get; }
public QueryResultType Type => QueryResultType.Application;

public ProcessResult(int processId, string title, string description,
float distance, float score)
{
ProcessId = processId;
Title = title;
Description = description;
Distance = distance;
Score = score;
}

public bool Equals(IQueryResult obj)
{
return obj != null && obj.GetType() == GetType()
&& Equals((ProcessResult) obj);
}

public override bool Equals(object obj)
{
return obj != null && (obj.GetType() == GetType()
&& Equals((ProcessResult) obj));
}

public bool Equals(ProcessResult other)
{
return other.ProcessId.Equals(ProcessId);
}

public override int GetHashCode()
{
return ProcessId.GetHashCode();
}
}
}
21 changes: 21 additions & 0 deletions src/Jarvis.Addin.Processes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;
using System.Runtime.InteropServices;
using Jarvis.Addin.Processes;
using Jarvis.Core;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Jarvis.Addin.Processes")]
[assembly: AssemblyDescription("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("AE5C446D-B1D3-4E98-941D-A751B80CA74F")]

// The addin definition.
[assembly: Addin(typeof(ProcessAddin))]
6 changes: 6 additions & 0 deletions src/Jarvis.Core/Interop/Win32.Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public static class Window

[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref W32Rect rectangle);

[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hwnd);

[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
}
}
}
7 changes: 7 additions & 0 deletions src/Jarvis.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jarvis.Addin.Wikipedia", "J
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jarvis.Tests", "Jarvis.Tests\Jarvis.Tests.csproj", "{B3874102-B91F-408C-A32C-A1F8F8921376}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jarvis.Addin.Processes", "Jarvis.Addin.Processes\Jarvis.Addin.Processes.csproj", "{AE5C446D-B1D3-4E98-941D-A751B80CA74F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -47,6 +49,10 @@ Global
{B3874102-B91F-408C-A32C-A1F8F8921376}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3874102-B91F-408C-A32C-A1F8F8921376}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3874102-B91F-408C-A32C-A1F8F8921376}.Release|Any CPU.Build.0 = Release|Any CPU
{AE5C446D-B1D3-4E98-941D-A751B80CA74F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE5C446D-B1D3-4E98-941D-A751B80CA74F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE5C446D-B1D3-4E98-941D-A751B80CA74F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE5C446D-B1D3-4E98-941D-A751B80CA74F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -55,6 +61,7 @@ Global
{6E2C9A93-08D3-42C8-9822-9C17D118E646} = {511CB402-AE1B-4E3B-BFA1-80E585EE3AB5}
{630865D0-C44B-41BD-AA6E-4697A4A12BD9} = {511CB402-AE1B-4E3B-BFA1-80E585EE3AB5}
{CBB05832-5634-4611-ADA1-E3793C5765D6} = {511CB402-AE1B-4E3B-BFA1-80E585EE3AB5}
{AE5C446D-B1D3-4E98-941D-A751B80CA74F} = {511CB402-AE1B-4E3B-BFA1-80E585EE3AB5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7AC5E44D-16BB-4EA9-97C7-0B74E46083C4}
Expand Down
4 changes: 3 additions & 1 deletion src/Jarvis/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Caliburn.Micro;
using Jarvis.Addin.Files;
using Jarvis.Addin.Google;
using Jarvis.Addin.Processes;
using Jarvis.Addin.Wikipedia;
using Jarvis.Bootstrapping;
using Jarvis.Core;
Expand Down Expand Up @@ -46,7 +47,8 @@ protected override void Configure()
builder.RegisterModule(new AddinModule(
typeof(FileAddin).Assembly,
typeof(GoogleAddin).Assembly,
typeof(WikipediaAddin).Assembly));
typeof(WikipediaAddin).Assembly,
typeof(ProcessAddin).Assembly));

// Build the container.
_container = builder.Build();
Expand Down
4 changes: 4 additions & 0 deletions src/Jarvis/Jarvis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@
<Project>{630865d0-c44b-41bd-aa6e-4697a4a12bd9}</Project>
<Name>Jarvis.Addin.Google</Name>
</ProjectReference>
<ProjectReference Include="..\Jarvis.Addin.Processes\Jarvis.Addin.Processes.csproj">
<Project>{AE5C446D-B1D3-4E98-941D-A751B80CA74F}</Project>
<Name>Jarvis.Addin.Processes</Name>
</ProjectReference>
<ProjectReference Include="..\Jarvis.Addin.Wikipedia\Jarvis.Addin.Wikipedia.csproj">
<Project>{cbb05832-5634-4611-ada1-e3793c5765d6}</Project>
<Name>Jarvis.Addin.Wikipedia</Name>
Expand Down