fix TrayIcon not disappearing and proper app exit

This commit is contained in:
gered 2012-05-29 13:02:20 -04:00
parent cea61f8b7d
commit c34b51cff5
2 changed files with 34 additions and 19 deletions

View file

@ -18,9 +18,12 @@ public partial class App : Application
{
public static MainWindow Window { get; set; }
private TrayIcon _trayIcon = null;
private void Application_Startup(object sender, StartupEventArgs e)
{
TrayIcon.Show();
_trayIcon = new TrayIcon(this);
_trayIcon.Show();
// Version check updating disabled because this is a fork and it would obviously
// be bad of us to update this forked version with the original...
@ -100,6 +103,7 @@ bool KeyboardListener_KeyDown(KeyboardListener.KeyHookEventArgs e)
private void Application_Exit(object sender, ExitEventArgs e)
{
_trayIcon.Close();
KeyboardListener.UnRegister();
AppleKeyboardHID2.Shutdown();
}

View file

@ -9,43 +9,54 @@
namespace AppleWirelessKeyboard
{
public static class TrayIcon
public class TrayIcon
{
static TrayIcon()
{
NotifyIcon icon = new NotifyIcon();
icon.Text = "AppleWirelessKeyboard";
icon.Icon = new Icon(App.GetResourceStream(new Uri("pack://application:,,,/Gnome-Preferences-Desktop-Keyboard-Shortcuts.ico")).Stream);
icon.Visible = true;
private System.Windows.Application _application = null;
private NotifyIcon _icon = null;
MenuItem[] menuItems = new[] {
public TrayIcon(System.Windows.Application application)
{
_application = application;
}
public void Show()
{
_icon = new NotifyIcon();
_icon.Text = "AppleWirelessKeyboard";
_icon.Icon = new Icon(App.GetResourceStream(new Uri("pack://application:,,,/Gnome-Preferences-Desktop-Keyboard-Shortcuts.ico")).Stream);
_icon.Visible = true;
MenuItem[] menuItems = new[] {
new MenuItem("Configure", TriggerConfigure),
new MenuItem("Restart", TriggerRestart),
new MenuItem("Refresh", TriggerRefresh),
new MenuItem("Exit", TriggerExit)
};
ContextMenu menu = new ContextMenu(menuItems);
icon.ContextMenu = menu;
}
ContextMenu menu = new ContextMenu(menuItems);
_icon.ContextMenu = menu;
}
public static void Show() { }
public void Close()
{
_icon.Visible = false;
_icon = null;
}
private static void TriggerRestart(object sender, EventArgs e)
private void TriggerRestart(object sender, EventArgs e)
{
Application.Restart();
}
private static void TriggerConfigure(object sender, EventArgs e)
private void TriggerConfigure(object sender, EventArgs e)
{
(new Configuration()).Show();
}
private static void TriggerExit(object sender, EventArgs e)
private void TriggerExit(object sender, EventArgs e)
{
//Application.Exit();
Environment.Exit(0);
_application.Shutdown();
}
public static void TriggerRefresh(object sender, EventArgs e)
public void TriggerRefresh(object sender, EventArgs e)
{
if (AppleKeyboardHID2.Registered)
AppleKeyboardHID2.Shutdown();