Files
AX-Copilot-Codex/src/AxCopilot/Handlers/BrightHandler.cs
lacvet 0336904258 AX Commander 비교본 런처 기능 대량 이식
변경 목적: Agent Compare 아래 비교본의 개발 문서와 런처 소스를 기준으로 현재 AX Commander에 빠져 있던 신규 런처 기능을 동일한 흐름으로 옮겨, 비교본 수준의 기능 폭을 현재 제품에 반영했습니다.

핵심 수정사항: 비교본의 신규 런처 핸들러 다수를 src/AxCopilot/Handlers로 이식하고 App.xaml.cs 등록 흐름에 연결했습니다. 빠른 링크, 파일 태그, 알림 센터, 포모도로, 파일 브라우저, 핫키 관리, OCR, 세션/스케줄/매크로, Git/정규식/네트워크/압축/해시/UUID/JWT/QR 등 AX Commander 기능을 추가했습니다.

핵심 수정사항: 신규 기능이 실제 동작하도록 AppSettings 확장, SchedulerService/FileTagService/NotificationCenterService/IconCacheService/UrlTemplateEngine/PomodoroService 추가, 배치 이름변경/세션/스케줄/매크로 편집 창 추가, NotificationService와 Symbols 보강, QR/OCR용 csproj 의존성과 Windows 타겟 프레임워크를 반영했습니다.

문서 반영: README.md와 docs/DEVELOPMENT.md에 비교본 기반 런처 기능 이식 이력과 검증 결과를 업데이트했습니다.

검증 결과: dotnet build src/AxCopilot/AxCopilot.csproj -c Release -v minimal -p:OutputPath=bin\\verify\\ -p:IntermediateOutputPath=obj\\verify\\ 실행 기준 경고 0개, 오류 0개를 확인했습니다.
2026-04-05 00:59:45 +09:00

154 lines
5.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Diagnostics;
using AxCopilot.SDK;
using AxCopilot.Services;
namespace AxCopilot.Handlers;
/// <summary>
/// L27-5: 화면 밝기 제어 핸들러. "bright" 프리픽스로 사용합니다.
///
/// 예: bright → 현재 밝기 표시
/// bright 70 → 밝기 70% 설정
/// bright up / down → ±10% 조절
/// Enter → 해당 밝기로 설정.
/// WMI (WmiMonitorBrightness) 사용 — 노트북 내장 디스플레이 대상.
/// </summary>
public class BrightHandler : IActionHandler
{
public string? Prefix => "bright";
public PluginMetadata Metadata => new(
"밝기 제어",
"화면 밝기 조절 — 설정·증감 (노트북)",
"1.0",
"AX");
public Task<IEnumerable<LauncherItem>> GetItemsAsync(string query, CancellationToken ct)
{
var q = query.Trim().ToLowerInvariant();
var items = new List<LauncherItem>();
// 현재 밝기 읽기
int current = GetCurrentBrightness();
if (current < 0)
{
items.Add(new LauncherItem(
"밝기 센서를 찾을 수 없습니다",
"노트북 내장 디스플레이에서만 동작합니다 (외장 모니터 미지원)",
null, null, Symbol: "\uE7BA"));
return Task.FromResult<IEnumerable<LauncherItem>>(items);
}
var bar = BrightnessBar(current);
if (string.IsNullOrWhiteSpace(q))
{
items.Add(new LauncherItem(
$"현재 밝기: {current}%",
$"{bar} · bright 70 / bright up / bright down",
null, null, Symbol: "\uE706"));
items.Add(new LauncherItem("bright up", "밝기 +10%", null, ("set", Math.Min(current + 10, 100)), Symbol: "\uE706"));
items.Add(new LauncherItem("bright down", "밝기 10%", null, ("set", Math.Max(current - 10, 0)), Symbol: "\uE706"));
foreach (var p in new[] { 10, 25, 50, 75, 100 })
items.Add(new LauncherItem($"bright {p}", $"밝기 {p}%", null, ("set", p), Symbol: "\uE706"));
return Task.FromResult<IEnumerable<LauncherItem>>(items);
}
if (q is "up" or "올려" or "+")
{
var target = Math.Min(current + 10, 100);
items.Add(new LauncherItem($"밝기 +10% → {target}%", BrightnessBar(target), null, ("set", target), Symbol: "\uE706"));
}
else if (q is "down" or "내려" or "-")
{
var target = Math.Max(current - 10, 0);
items.Add(new LauncherItem($"밝기 10% → {target}%", BrightnessBar(target), null, ("set", target), Symbol: "\uE706"));
}
else if (int.TryParse(q, out int val) && val is >= 0 and <= 100)
{
items.Add(new LauncherItem(
$"밝기 {val}% 설정",
$"{BrightnessBar(val)} (현재 {current}%)",
null, ("set", val), Symbol: "\uE706"));
}
else
{
items.Add(new LauncherItem($"'{query}' — 알 수 없는 명령",
"사용법: bright 70 / bright up / bright down",
null, null, Symbol: "\uE7BA"));
}
return Task.FromResult<IEnumerable<LauncherItem>>(items);
}
public Task ExecuteAsync(LauncherItem item, CancellationToken ct)
{
if (item.Data is ("set", int level))
{
bool ok = SetBrightness(level);
if (ok)
NotificationService.Notify("bright", $"밝기 {level}%");
else
NotificationService.Notify("bright", "밝기 설정 실패 — 노트북 내장 디스플레이에서만 동작합니다.");
}
return Task.CompletedTask;
}
private static string BrightnessBar(int pct)
{
int filled = pct / 5;
return "[" + new string('█', filled) + new string('░', 20 - filled) + "]";
}
// ─── WMI 밝기 읽기/쓰기 (PowerShell subprocess) ──────────────────────────
private static int GetCurrentBrightness()
{
try
{
var output = RunPowerShell(
"(Get-CimInstance -Namespace root/WMI -ClassName WmiMonitorBrightness -ErrorAction Stop).CurrentBrightness");
if (int.TryParse(output.Trim(), out int val))
return val;
}
catch { }
return -1;
}
private static bool SetBrightness(int level)
{
try
{
level = Math.Clamp(level, 0, 100);
var cmd = $"$m = Get-CimInstance -Namespace root/WMI -ClassName WmiMonitorBrightnessMethods -ErrorAction Stop; " +
$"Invoke-CimMethod -InputObject $m -MethodName WmiSetBrightness -Arguments @{{Timeout=1; Brightness={level}}}";
RunPowerShell(cmd);
return true;
}
catch { return false; }
}
private static string RunPowerShell(string command)
{
using var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "powershell.exe",
Arguments = $"-NoProfile -NonInteractive -Command \"{command}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
proc.Start();
var output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit(3000);
return output;
}
}