Existing ASP.NET API with vanilla JS SPA, WindowWatcher, Chrome extension, and MCP server. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
namespace WindowWatcher;
|
|
|
|
public class TrayApplicationContext : ApplicationContext
|
|
{
|
|
private readonly NotifyIcon _trayIcon;
|
|
private readonly CancellationTokenSource _hostCts;
|
|
private bool _trackingPaused;
|
|
|
|
public TrayApplicationContext(CancellationTokenSource hostCts)
|
|
{
|
|
_hostCts = hostCts;
|
|
|
|
_trayIcon = new NotifyIcon
|
|
{
|
|
Icon = SystemIcons.Application,
|
|
Text = "Work Context Tracker",
|
|
Visible = true,
|
|
ContextMenuStrip = CreateMenu()
|
|
};
|
|
}
|
|
|
|
private ContextMenuStrip CreateMenu()
|
|
{
|
|
var menu = new ContextMenuStrip();
|
|
|
|
var pauseItem = new ToolStripMenuItem("Pause Tracking");
|
|
pauseItem.Click += (_, _) =>
|
|
{
|
|
_trackingPaused = !_trackingPaused;
|
|
pauseItem.Text = _trackingPaused ? "Resume Tracking" : "Pause Tracking";
|
|
_trayIcon.Text = _trackingPaused ? "Work Context Tracker (Paused)" : "Work Context Tracker";
|
|
};
|
|
|
|
var exitItem = new ToolStripMenuItem("Exit");
|
|
exitItem.Click += (_, _) =>
|
|
{
|
|
_trayIcon.Visible = false;
|
|
_hostCts.Cancel();
|
|
Application.Exit();
|
|
};
|
|
|
|
menu.Items.Add(pauseItem);
|
|
menu.Items.Add(new ToolStripSeparator());
|
|
menu.Items.Add(exitItem);
|
|
|
|
return menu;
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
_trayIcon.Visible = false;
|
|
_trayIcon.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|