Files
king 06af036f86 feat(project): PC tray notifier for mentions and assignments
Windows tray app (desktop/notifier, C# .NET Framework 4.8 WinForms,
single exe, no installer/admin) that shows the same big alert popup as
the web even when the browser is in the background: layered topmost
window that does not steal focus, blinking border, open/close actions,
sound, autostart toggle, DPAPI-encrypted token.

Server side (project_db migration 023):
- notifier_links / notifier_tokens (SHA-256 hashes only)
- device link flow: link/start -> browser approve at /project/notifier
  -> link/poll issues token once
- Bearer API for alerts/read/logout reusing _alerts_payload; token
  re-checks current user record and project permission each call
- /project/notifier page (approve, connected PCs, revoke, download)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:21:58 +09:00

84 lines
3.3 KiB
C#

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace DbxNotifier
{
/// <summary>그리기 도우미 — 둥근 사각형, 종 아이콘, 색 섞기, 내장 아이콘.</summary>
internal static class Gfx
{
public static GraphicsPath Round(RectangleF r, float radius)
{
var p = new GraphicsPath();
float d = Math.Min(radius * 2, Math.Min(r.Width, r.Height));
if (d <= 0.5f)
{
p.AddRectangle(r);
return p;
}
p.AddArc(r.X, r.Y, d, d, 180, 90);
p.AddArc(r.Right - d, r.Y, d, d, 270, 90);
p.AddArc(r.Right - d, r.Bottom - d, d, d, 0, 90);
p.AddArc(r.X, r.Bottom - d, d, d, 90, 90);
p.CloseFigure();
return p;
}
public static Color Mix(Color a, Color b, double t) => Color.FromArgb(
(int)(a.A + (b.A - a.A) * t), (int)(a.R + (b.R - a.R) * t),
(int)(a.G + (b.G - a.G) * t), (int)(a.B + (b.B - a.B) * t));
public static Color Hex(string hex, int alpha = 255)
{
int v = Convert.ToInt32(hex.TrimStart('#'), 16);
return Color.FromArgb(alpha, (v >> 16) & 255, (v >> 8) & 255, v & 255);
}
/// <summary>울리는 종(웹 팝업 머리의 notifications_active 와 같은 느낌) — 24 격자를 r 에 맞춰 그린다.</summary>
public static void Bell(Graphics g, RectangleF r, Color color)
{
GraphicsState st = g.Save();
g.TranslateTransform(r.X, r.Y);
g.ScaleTransform(r.Width / 24f, r.Height / 24f);
using (var b = new SolidBrush(color))
using (var body = new GraphicsPath())
{
body.AddLine(5f, 17f, 6.6f, 15.2f);
body.AddLine(6.6f, 15.2f, 6.6f, 10.6f);
body.AddBezier(6.6f, 10.6f, 6.6f, 7.2f, 9.0f, 4.9f, 12f, 4.9f);
body.AddBezier(12f, 4.9f, 15.0f, 4.9f, 17.4f, 7.2f, 17.4f, 10.6f);
body.AddLine(17.4f, 10.6f, 17.4f, 15.2f);
body.AddLine(17.4f, 15.2f, 19f, 17f);
body.CloseFigure();
g.FillPath(b, body);
g.FillEllipse(b, 10.1f, 16.7f, 3.8f, 3.8f);
g.FillEllipse(b, 10.9f, 3.3f, 2.2f, 2.2f);
}
using (var pen = new Pen(color, 1.7f) { StartCap = LineCap.Round, EndCap = LineCap.Round })
{
g.DrawArc(pen, 2.4f, 1.0f, 19.2f, 19.2f, 198, 40);
g.DrawArc(pen, 2.4f, 1.0f, 19.2f, 19.2f, 302, 40);
}
g.Restore(st);
}
/// <summary>exe 에 넣은 app.ico 에서 원하는 크기 아이콘(트레이 = 작은 아이콘 크기).</summary>
public static Icon AppIcon(Size size)
{
using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("DbxNotifier.app.ico"))
return s == null ? SystemIcons.Information : new Icon(s, size);
}
public static Icon TrayIcon() => AppIcon(SystemInformation.SmallIconSize);
public static float SystemScale()
{
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
return Math.Max(1f, g.DpiX / 96f);
}
}
}