Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
8LWXpg committed May 14, 2024
1 parent bbd41ae commit df8f165
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 217 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
6 changes: 3 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
Expand Down Expand Up @@ -46,9 +46,9 @@

###############################################################################
# diff behavior for common document formats
#
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,4 @@ MigrationBackup/
FodyWeavers.xsd

# Custom
*.zip
*.zip
226 changes: 113 additions & 113 deletions ProcessKiller/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,117 +6,117 @@

namespace Community.PowerToys.Run.Plugin.ProcessKiller
{
public class Main : IPlugin, IPluginI18n, ISettingProvider, IReloadable, IDisposable
{
private PluginInitContext? _context;

private bool _disposed;

public string Name => Resources.plugin_name;
public string Description => Resources.plugin_description;
public static string PluginID => "78844AE082E24C0C8AC9DB222FF67317";

private const string KillAllCount = nameof(KillAllCount);
private int? _killAllCount;

public IEnumerable<PluginAdditionalOption> AdditionalOptions =>
[
new()
{
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Numberbox,
Key = KillAllCount,
DisplayLabel = Resources.plugin_setting_kill_all_count,
NumberValue = 5,
NumberBoxMin = 2,
}
];

public void UpdateSettings(PowerLauncherPluginSettings settings) => _killAllCount = (int?)(settings?.AdditionalOptions?.FirstOrDefault(x => x.Key == KillAllCount)?.NumberValue) ?? 5;

public List<Result> Query(Query query)
{
var search = query.Search;
List<ProcessResult> processes = ProcessHelper.GetMatchingProcesses(search);

if (processes.Count == 0)
{
return [];
}

var sortedResults = processes.ConvertAll(pr =>
{
System.Diagnostics.Process p = pr.Process;
var path = ProcessHelper.TryGetProcessFilename(p);
return new Result()
{
IcoPath = path,
Title = $"{p.ProcessName} - {p.Id}",
SubTitle = path,
TitleHighlightData = StringMatcher.FuzzySearch(search, p.ProcessName).MatchData,
Score = pr.Score,
ContextData = p.ProcessName,
Action = c =>
{
ProcessHelper.TryKill(p);
// Re-query to refresh process list
_context!.API.ChangeQuery(query.RawQuery, true);
return true;
}
};
}).OrderBy(x => x.Title).ToList();

// When there are multiple results AND all of them are instances of the same executable
// add a quick option to kill them all at the top of the results.
Result? firstResult = sortedResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.SubTitle));
if (processes.Count > 1 && !string.IsNullOrEmpty(search) && sortedResults.Count(r => r.SubTitle == firstResult?.SubTitle) >= _killAllCount)
{
sortedResults.Insert(1, new Result()
{
IcoPath = firstResult?.IcoPath,
Title = string.Format(Resources.plugin_kill_all, firstResult?.ContextData),
SubTitle = string.Format(Resources.plugin_kill_all_count, processes.Count),
Score = 200,
Action = c =>
{
processes.ForEach(p => ProcessHelper.TryKill(p.Process));
// Re-query to refresh process list
_context!.API.ChangeQuery(query.RawQuery, true);
return true;
}
});
}

return sortedResults;
}

public void Init(PluginInitContext context) => _context = context ?? throw new ArgumentNullException(nameof(context));

public string GetTranslatedPluginTitle() => Resources.plugin_name;

public string GetTranslatedPluginDescription() => Resources.plugin_description;

public Control CreateSettingPanel() => throw new NotImplementedException();

public void ReloadData()
{
if (_context is null)
{
return;
}
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (!_disposed && disposing)
{
_disposed = true;
}
}
}
public class Main : IPlugin, IPluginI18n, ISettingProvider, IReloadable, IDisposable
{
private PluginInitContext? _context;

private bool _disposed;

public string Name => Resources.plugin_name;
public string Description => Resources.plugin_description;
public static string PluginID => "78844AE082E24C0C8AC9DB222FF67317";

private const string KillAllCount = nameof(KillAllCount);
private int? _killAllCount;

public IEnumerable<PluginAdditionalOption> AdditionalOptions =>
[
new()
{
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Numberbox,
Key = KillAllCount,
DisplayLabel = Resources.plugin_setting_kill_all_count,
NumberValue = 5,
NumberBoxMin = 2,
}
];

public void UpdateSettings(PowerLauncherPluginSettings settings) => _killAllCount = (int?)(settings?.AdditionalOptions?.FirstOrDefault(x => x.Key == KillAllCount)?.NumberValue) ?? 5;

public List<Result> Query(Query query)
{
var search = query.Search;
List<ProcessResult> processes = ProcessHelper.GetMatchingProcesses(search);

if (processes.Count == 0)
{
return [];
}

var sortedResults = processes.ConvertAll(pr =>
{
System.Diagnostics.Process p = pr.Process;
var path = ProcessHelper.TryGetProcessFilename(p);
return new Result()
{
IcoPath = path,
Title = $"{p.ProcessName} - {p.Id}",
SubTitle = path,
TitleHighlightData = StringMatcher.FuzzySearch(search, p.ProcessName).MatchData,
Score = pr.Score,
ContextData = p.ProcessName,
Action = c =>
{
ProcessHelper.TryKill(p);
// Re-query to refresh process list
_context!.API.ChangeQuery(query.RawQuery, true);
return true;
}
};
}).OrderBy(x => x.Title).ToList();

// When there are multiple results AND all of them are instances of the same executable
// add a quick option to kill them all at the top of the results.
Result? firstResult = sortedResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.SubTitle));
if (processes.Count > 1 && !string.IsNullOrEmpty(search) && sortedResults.Count(r => r.SubTitle == firstResult?.SubTitle) >= _killAllCount)
{
sortedResults.Insert(1, new Result()
{
IcoPath = firstResult?.IcoPath,
Title = string.Format(Resources.plugin_kill_all, firstResult?.ContextData),
SubTitle = string.Format(Resources.plugin_kill_all_count, processes.Count),
Score = 200,
Action = c =>
{
processes.ForEach(p => ProcessHelper.TryKill(p.Process));
// Re-query to refresh process list
_context!.API.ChangeQuery(query.RawQuery, true);
return true;
}
});
}

return sortedResults;
}

public void Init(PluginInitContext context) => _context = context ?? throw new ArgumentNullException(nameof(context));

public string GetTranslatedPluginTitle() => Resources.plugin_name;

public string GetTranslatedPluginDescription() => Resources.plugin_description;

public Control CreateSettingPanel() => throw new NotImplementedException();

public void ReloadData()
{
if (_context is null)
{
return;
}
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (!_disposed && disposing)
{
_disposed = true;
}
}
}
}
Loading

0 comments on commit df8f165

Please sign in to comment.