Initial commit to new repository
This commit is contained in:
96
src/AxCopilot/Handlers/RunHandler.cs
Normal file
96
src/AxCopilot/Handlers/RunHandler.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using AxCopilot.SDK;
|
||||
using AxCopilot.Themes;
|
||||
using AxCopilot.Views;
|
||||
|
||||
namespace AxCopilot.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Windows 실행(Run) 핸들러. "^" 프리픽스로 사용합니다.
|
||||
/// Windows 실행 창(Win+R)에서 입력하는 것과 동일하게 작동합니다.
|
||||
/// 예: ^ notepad → 메모장 실행
|
||||
/// ^ cmd → 명령 프롬프트
|
||||
/// ^ calc → 계산기
|
||||
/// ^ mspaint → 그림판
|
||||
/// ^ control → 제어판
|
||||
/// </summary>
|
||||
public class RunHandler : IActionHandler
|
||||
{
|
||||
public string? Prefix => "^";
|
||||
|
||||
public PluginMetadata Metadata => new(
|
||||
"Run",
|
||||
"Windows 실행 명령",
|
||||
"1.0",
|
||||
"AX Copilot");
|
||||
|
||||
public Task<IEnumerable<LauncherItem>> GetItemsAsync(string query, CancellationToken ct)
|
||||
{
|
||||
var q = query.Trim();
|
||||
|
||||
if (string.IsNullOrEmpty(q))
|
||||
{
|
||||
return Task.FromResult<IEnumerable<LauncherItem>>(
|
||||
[
|
||||
new LauncherItem(
|
||||
"Windows 실행 명령",
|
||||
"Win+R 실행 창과 동일 · 명령어 입력 후 Enter",
|
||||
null, null,
|
||||
Symbol: Symbols.LaunchIcon),
|
||||
new LauncherItem(
|
||||
"^ notepad",
|
||||
"메모장 실행",
|
||||
null, null, Symbol: Symbols.Info),
|
||||
new LauncherItem(
|
||||
"^ cmd",
|
||||
"명령 프롬프트",
|
||||
null, null, Symbol: Symbols.Info),
|
||||
new LauncherItem(
|
||||
"^ control",
|
||||
"제어판",
|
||||
null, null, Symbol: Symbols.Info),
|
||||
new LauncherItem(
|
||||
"^ calc",
|
||||
"계산기",
|
||||
null, null, Symbol: Symbols.Info),
|
||||
]);
|
||||
}
|
||||
|
||||
return Task.FromResult<IEnumerable<LauncherItem>>(
|
||||
[
|
||||
new LauncherItem(
|
||||
$"실행: {q}",
|
||||
"Enter → Windows 실행 명령으로 실행",
|
||||
null, $"__RUN__{q}",
|
||||
Symbol: Symbols.LaunchIcon)
|
||||
]);
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(LauncherItem item, CancellationToken ct)
|
||||
{
|
||||
var data = item.Data as string;
|
||||
if (data == null || !data.StartsWith("__RUN__")) return Task.CompletedTask;
|
||||
|
||||
var cmd = data["__RUN__".Length..].Trim();
|
||||
if (string.IsNullOrEmpty(cmd)) return Task.CompletedTask;
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(cmd)
|
||||
{
|
||||
UseShellExecute = true
|
||||
})?.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
CustomMessageBox.Show(
|
||||
$"실행 실패: {ex.Message}",
|
||||
"AX Copilot",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user