mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #3468 from Flow-Launcher/revert_property
Revert delegate to fields
This commit is contained in:
commit
5cc3124037
7 changed files with 79 additions and 21 deletions
|
|
@ -128,12 +128,12 @@ namespace Flow.Launcher.Plugin
|
|||
/// <summary>
|
||||
/// Delegate to load an icon for this result.
|
||||
/// </summary>
|
||||
public IconDelegate Icon { get; set; }
|
||||
public IconDelegate Icon = null;
|
||||
|
||||
/// <summary>
|
||||
/// Delegate to load an icon for the badge of this result.
|
||||
/// </summary>
|
||||
public IconDelegate BadgeIcon { get; set; }
|
||||
public IconDelegate BadgeIcon = null;
|
||||
|
||||
/// <summary>
|
||||
/// Information for Glyph Icon (Prioritized than IcoPath/Icon if user enable Glyph Icons)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
<system:String x:Key="flowlauncher_plugin_processkiller_kill_all_count">kill {0} processes</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_processkiller_kill_instances">kill all instances</system:String>
|
||||
|
||||
<system:String x:Key="flowlauncher_plugin_processkiller_show_window_title">Show title for processes with visible windows</system:String>
|
||||
<system:String x:Key="flowlauncher_plugin_processkiller_put_visible_window_process_top">Put processes with visible windows on the top</system:String>
|
||||
|
||||
</ResourceDictionary>
|
||||
|
|
@ -81,7 +81,10 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
|||
// Filter processes based on search term
|
||||
var searchTerm = query.Search;
|
||||
var processlist = new List<ProcessResult>();
|
||||
var processWindowTitle = ProcessHelper.GetProcessesWithNonEmptyWindowTitle();
|
||||
var processWindowTitle =
|
||||
Settings.ShowWindowTitle || Settings.PutVisibleWindowProcessesTop ?
|
||||
ProcessHelper.GetProcessesWithNonEmptyWindowTitle() :
|
||||
new Dictionary<int, string>();
|
||||
if (string.IsNullOrWhiteSpace(searchTerm))
|
||||
{
|
||||
foreach (var p in allPocessList)
|
||||
|
|
@ -91,12 +94,22 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
|||
if (processWindowTitle.TryGetValue(p.Id, out var windowTitle))
|
||||
{
|
||||
// Add score to prioritize processes with visible windows
|
||||
// And use window title for those processes
|
||||
processlist.Add(new ProcessResult(p, Settings.PutVisibleWindowProcessesTop ? 200 : 0, windowTitle, null, progressNameIdTitle));
|
||||
// Use window title for those processes if enabled
|
||||
processlist.Add(new ProcessResult(
|
||||
p,
|
||||
Settings.PutVisibleWindowProcessesTop ? 200 : 0,
|
||||
Settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
|
||||
null,
|
||||
progressNameIdTitle));
|
||||
}
|
||||
else
|
||||
{
|
||||
processlist.Add(new ProcessResult(p, 0, progressNameIdTitle, null, progressNameIdTitle));
|
||||
processlist.Add(new ProcessResult(
|
||||
p,
|
||||
0,
|
||||
progressNameIdTitle,
|
||||
null,
|
||||
progressNameIdTitle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -115,13 +128,17 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
|||
if (score > 0)
|
||||
{
|
||||
// Add score to prioritize processes with visible windows
|
||||
// And use window title for those processes
|
||||
// Use window title for those processes
|
||||
if (Settings.PutVisibleWindowProcessesTop)
|
||||
{
|
||||
score += 200;
|
||||
}
|
||||
processlist.Add(new ProcessResult(p, score, windowTitle,
|
||||
score == windowTitleMatch.Score ? windowTitleMatch : null, progressNameIdTitle));
|
||||
processlist.Add(new ProcessResult(
|
||||
p,
|
||||
score,
|
||||
Settings.ShowWindowTitle ? windowTitle : progressNameIdTitle,
|
||||
score == windowTitleMatch.Score ? windowTitleMatch : null,
|
||||
progressNameIdTitle));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -130,7 +147,12 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
|||
var score = processNameIdMatch.Score;
|
||||
if (score > 0)
|
||||
{
|
||||
processlist.Add(new ProcessResult(p, score, progressNameIdTitle, processNameIdMatch, progressNameIdTitle));
|
||||
processlist.Add(new ProcessResult(
|
||||
p,
|
||||
score,
|
||||
progressNameIdTitle,
|
||||
processNameIdMatch,
|
||||
progressNameIdTitle));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
using Microsoft.Win32.SafeHandles;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.Threading;
|
||||
|
|
@ -72,8 +74,21 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
|||
/// </summary>
|
||||
public static unsafe Dictionary<int, string> GetProcessesWithNonEmptyWindowTitle()
|
||||
{
|
||||
var processDict = new Dictionary<int, string>();
|
||||
// Collect all window handles
|
||||
var windowHandles = new List<HWND>();
|
||||
PInvoke.EnumWindows((hWnd, _) =>
|
||||
{
|
||||
if (PInvoke.IsWindowVisible(hWnd))
|
||||
{
|
||||
windowHandles.Add(hWnd);
|
||||
}
|
||||
return true;
|
||||
}, IntPtr.Zero);
|
||||
|
||||
// Concurrently process each window handle
|
||||
var processDict = new ConcurrentDictionary<int, string>();
|
||||
var processedProcessIds = new ConcurrentDictionary<int, byte>();
|
||||
Parallel.ForEach(windowHandles, hWnd =>
|
||||
{
|
||||
var windowTitle = GetWindowTitle(hWnd);
|
||||
if (!string.IsNullOrWhiteSpace(windowTitle) && PInvoke.IsWindowVisible(hWnd))
|
||||
|
|
@ -82,20 +97,26 @@ namespace Flow.Launcher.Plugin.ProcessKiller
|
|||
var result = PInvoke.GetWindowThreadProcessId(hWnd, &processId);
|
||||
if (result == 0u || processId == 0u)
|
||||
{
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
var process = Process.GetProcessById((int)processId);
|
||||
if (!processDict.ContainsKey((int)processId))
|
||||
// Ensure each process ID is processed only once
|
||||
if (processedProcessIds.TryAdd((int)processId, 0))
|
||||
{
|
||||
processDict.Add((int)processId, windowTitle);
|
||||
try
|
||||
{
|
||||
var process = Process.GetProcessById((int)processId);
|
||||
processDict.TryAdd((int)processId, windowTitle);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Handle exceptions (e.g., process exited)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}, IntPtr.Zero);
|
||||
|
||||
return processDict;
|
||||
return new Dictionary<int, string>(processDict);
|
||||
}
|
||||
|
||||
private static unsafe string GetWindowTitle(HWND hwnd)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
{
|
||||
public class Settings
|
||||
{
|
||||
public bool ShowWindowTitle { get; set; } = true;
|
||||
|
||||
public bool PutVisibleWindowProcessesTop { get; set; } = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,12 @@
|
|||
Settings = settings;
|
||||
}
|
||||
|
||||
public bool ShowWindowTitle
|
||||
{
|
||||
get => Settings.ShowWindowTitle;
|
||||
set => Settings.ShowWindowTitle = value;
|
||||
}
|
||||
|
||||
public bool PutVisibleWindowProcessesTop
|
||||
{
|
||||
get => Settings.PutVisibleWindowProcessesTop;
|
||||
|
|
|
|||
|
|
@ -12,10 +12,16 @@
|
|||
<Grid.ColumnDefinitions />
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<CheckBox
|
||||
Grid.Row="0"
|
||||
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
||||
Content="{DynamicResource flowlauncher_plugin_processkiller_show_window_title}"
|
||||
IsChecked="{Binding ShowWindowTitle}" />
|
||||
<CheckBox
|
||||
Grid.Row="1"
|
||||
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
|
||||
Content="{DynamicResource flowlauncher_plugin_processkiller_put_visible_window_process_top}"
|
||||
IsChecked="{Binding PutVisibleWindowProcessesTop}" />
|
||||
</Grid>
|
||||
|
|
|
|||
Loading…
Reference in a new issue