114 lines
3.6 KiB
C#
114 lines
3.6 KiB
C#
using ChrisKaczor.Wpf.Windows;
|
|
using H.NotifyIcon;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using WorkIndicator.Audio;
|
|
using WorkIndicator.Properties;
|
|
using WorkIndicator.SettingsWindow;
|
|
|
|
namespace WorkIndicator;
|
|
|
|
internal static class NotificationIcon
|
|
{
|
|
private static TaskbarIcon _notificationIcon;
|
|
private static readonly Dictionary<Status, MenuItem> StatusMenuItems = new();
|
|
|
|
public static void Initialize()
|
|
{
|
|
// Create the notification icon
|
|
_notificationIcon = new TaskbarIcon { Icon = Resources.ApplicationIcon };
|
|
_notificationIcon.TrayMouseDoubleClick += _notificationIcon_TrayMouseDoubleClick;
|
|
|
|
// Set up the menu
|
|
var contextMenu = new ContextMenu();
|
|
contextMenu.Opened += HandleContextMenuOpening;
|
|
|
|
AddStatusMenuItem(contextMenu, Resources.StatusAuto, Status.Auto);
|
|
AddStatusMenuItem(contextMenu, Resources.StatusFree, Status.Free);
|
|
AddStatusMenuItem(contextMenu, Resources.StatusWorking, Status.Working);
|
|
AddStatusMenuItem(contextMenu, Resources.StatusOnPhone, Status.OnPhone);
|
|
AddStatusMenuItem(contextMenu, Resources.StatusTalking, Status.Talking);
|
|
|
|
contextMenu.Items.Add(new Separator());
|
|
|
|
var menuItem = new MenuItem
|
|
{
|
|
Header = Resources.NotificationIconContextMenuSettings
|
|
};
|
|
menuItem.Click += ShowSettings;
|
|
contextMenu.Items.Add(menuItem);
|
|
|
|
contextMenu.Items.Add(new Separator());
|
|
|
|
menuItem = new MenuItem
|
|
{
|
|
Header = Resources.NotificationIconContextMenuExit
|
|
};
|
|
menuItem.Click += HandleContextMenuExitClick;
|
|
contextMenu.Items.Add(menuItem);
|
|
|
|
// Set the menu into the icon
|
|
_notificationIcon.ContextMenu = contextMenu;
|
|
|
|
// Show the icon
|
|
_notificationIcon.ForceCreate(false);
|
|
}
|
|
|
|
private static void _notificationIcon_TrayMouseDoubleClick(object sender, RoutedEventArgs e)
|
|
{
|
|
LightController.LogAudioState();
|
|
}
|
|
|
|
private static void ShowSettings(object sender, RoutedEventArgs e)
|
|
{
|
|
var categoryPanels = new List<CategoryPanelBase>
|
|
{
|
|
new GeneralSettingsPanel(),
|
|
new UpdateSettingsPanel(),
|
|
new AboutSettingsPanel()
|
|
};
|
|
|
|
var settingsWindow = new CategoryWindow(categoryPanels, Resources.SettingsTitle, Resources.CloseButtonText);
|
|
|
|
settingsWindow.ShowDialog();
|
|
}
|
|
|
|
private static void HandleContextMenuOpening(object sender, RoutedEventArgs e)
|
|
{
|
|
foreach (var menuItem in StatusMenuItems)
|
|
{
|
|
menuItem.Value.IsChecked = menuItem.Key == LightController.Status;
|
|
}
|
|
}
|
|
|
|
private static void HandleContextMenuExitClick(object sender, System.EventArgs e)
|
|
{
|
|
Application.Current.Shutdown();
|
|
}
|
|
|
|
public static void Dispose()
|
|
{
|
|
// Get rid of the icon
|
|
_notificationIcon?.Dispose();
|
|
_notificationIcon = null;
|
|
}
|
|
|
|
public static void ShowBalloonTip(string text, H.NotifyIcon.Core.NotificationIcon icon)
|
|
{
|
|
_notificationIcon.ShowNotification(Resources.ApplicationName, text, icon);
|
|
}
|
|
|
|
private static void AddStatusMenuItem(ContextMenu contextMenu, string text, Status status)
|
|
{
|
|
var menuItem = new MenuItem
|
|
{
|
|
Header = text,
|
|
IsCheckable = true,
|
|
IsChecked = status == LightController.Status
|
|
};
|
|
menuItem.Click += (_, _) => LightController.Status = status;
|
|
contextMenu.Items.Add(menuItem);
|
|
StatusMenuItems[status] = menuItem;
|
|
}
|
|
} |