Skip to content

Commit

Permalink
App now minimized to tray if setting enabled. Fixes #10.
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed Nov 18, 2015
1 parent f83c653 commit 4008e40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Application/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ public ISettingsManager Save(Settings settings)
var cmd = File.Exists(link) ? link : Assembly.GetEntryAssembly().Location;
_registryKey.SetValue("VPDB Agent", "\"" + cmd + "\"");
} else {
_registryKey.DeleteValue("VPDB Agent");
if (_registryKey.GetValue("VPDB Agent") != null) {
_registryKey.DeleteValue("VPDB Agent");
}

}
});

Expand Down
11 changes: 9 additions & 2 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public partial class MainWindow

private static readonly ISettingsManager SettingsManager = Locator.CurrentMutable.GetService<ISettingsManager>();

private bool _minimizing = false;

public MainWindow(AppViewModel appViewModel)
{
RestoreWindowPlacement();
Expand Down Expand Up @@ -71,7 +73,10 @@ private void RestoreWindowPlacement()

private void Window_StateChanged(object sender, EventArgs e)
{
Console.WriteLine("Window state changed.");
if (WindowState == WindowState.Minimized && SettingsManager.Settings.MinimizeToTray) {
_minimizing = true;
Close();
}
}

public void Window_Closing(object sender, CancelEventArgs e)
Expand All @@ -86,7 +91,9 @@ public void Window_Closing(object sender, CancelEventArgs e)
};
SettingsManager.SaveInternal(settings).Subscribe(_ => {
System.Windows.Application.Current.Dispatcher.Invoke(delegate {
System.Windows.Application.Current.Shutdown();
if (!_minimizing) {
System.Windows.Application.Current.Shutdown();
}
});
});
}
Expand Down

0 comments on commit 4008e40

Please sign in to comment.