fix TrayIcon not disappearing and proper app exit
This commit is contained in:
parent
cea61f8b7d
commit
c34b51cff5
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -9,14 +9,22 @@
|
|||
|
||||
namespace AppleWirelessKeyboard
|
||||
{
|
||||
public static class TrayIcon
|
||||
public class TrayIcon
|
||||
{
|
||||
static TrayIcon()
|
||||
private System.Windows.Application _application = null;
|
||||
private NotifyIcon _icon = null;
|
||||
|
||||
public TrayIcon(System.Windows.Application application)
|
||||
{
|
||||
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;
|
||||
_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),
|
||||
|
@ -26,26 +34,29 @@ static TrayIcon()
|
|||
};
|
||||
|
||||
ContextMenu menu = new ContextMenu(menuItems);
|
||||
icon.ContextMenu = menu;
|
||||
_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();
|
||||
|
|
Reference in a new issue