Skip to content

Move focus to main window of process if it's already running (using ProcessAddin)#60

Open
jonstodle wants to merge 11 commits into
spectresystems:developfrom
jonstodle:focus-on-window-via-process
Open

Move focus to main window of process if it's already running (using ProcessAddin)#60
jonstodle wants to merge 11 commits into
spectresystems:developfrom
jonstodle:focus-on-window-via-process

Conversation

@jonstodle
Copy link
Copy Markdown

After having difficulty getting #49 to work i propose this alternative solution. Using an addin to query the currently running processes and provide them as query results.

This still needs some work regarding UWP processes, as it currently includes the background processes of UWP apps.

This closes #38, #49

Add addin project
Add StyleCop references
Add ProcessResult
Add ProcessProvider
Add ProcessAddin
Add addin definition
Add ProcessAddin when bootstrapping
{
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

.Select(process => (IQueryResult) new ProcessResult(process.Id, process.MainWindowTitle, process.ProcessName, LevenshteinScorer.Score(process.MainWindowTitle, query.Raw, false), LevenshteinScorer.Score(process.MainWindowTitle, query.Raw)))
.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


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.

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

Remove return variable and hard wrap lines
Use IsIconic to check whether window is minimized
Ensure there is a GUI when fitlering processes
Add simple cache of processes
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Focus application if open, instead of launching new instance

3 participants