22using ScriptFUSION . WarframeAlertTracker . Warframe ;
33using System ;
44using System . Collections . Generic ;
5+ using System . Diagnostics ;
56using System . Linq ;
67using System . Windows . Forms ;
78using ScriptFUSION . WarframeAlertTracker . Alerts ;
89using ScriptFUSION . WarframeAlertTracker . Controls ;
910
1011namespace ScriptFUSION . WarframeAlertTracker . Forms {
1112 public partial class WatForm : Form {
13+ private FormWindowState lastWindowState ;
14+
1215 private WatApplication Application { get ; }
1316
17+ /// <summary>
18+ /// Gets or sets the last non-minimized window state.
19+ /// </summary>
20+ private FormWindowState LastWindowState
21+ {
22+ get => lastWindowState ;
23+ set
24+ {
25+ Debug . Assert ( value != FormWindowState . Minimized ) ;
26+
27+ lastWindowState = value ;
28+ }
29+ }
30+
1431 internal WatForm ( WatApplication application ) {
1532 InitializeComponent ( ) ;
1633
1734 Application = application ;
35+ LastWindowState = WindowState ;
1836
1937 application . CurrentWorldState . Update +=
2038 async worldState => OnWorldStateUpdate ( worldState . Fissures , await application . SolNodes ) ;
@@ -26,9 +44,10 @@ internal WatForm(WatApplication application) {
2644 trayIcon . Icon = Icon ;
2745 }
2846
29- private void ToggleWindowVisibility ( ) {
47+ public void ToggleWindowVisibility ( ) {
3048 if ( Visible = ! Visible ) {
31- Activate ( ) ;
49+ // Restore previous state.
50+ WindowState = LastWindowState ;
3251 }
3352 }
3453
@@ -43,6 +62,19 @@ private void OnAlertsUpdate(AlertCollection alertsCollection) {
4362 alertsCount . Text = Application . CurrentWorldState . CurrentState . WorldStateObjects . Count ( alertsCollection . Matches ) . ToString ( ) ;
4463 }
4564
65+ private void WatForm_Resize ( object sender , EventArgs e ) {
66+ ShowInTaskbar = WindowState != FormWindowState . Minimized ;
67+
68+ if ( WindowState == FormWindowState . Minimized ) {
69+ // Sync form visibility with minimized state.
70+ Visible = false ;
71+ }
72+ else {
73+ // Record previous non-minimized state.
74+ LastWindowState = WindowState ;
75+ }
76+ }
77+
4678 private void alerts_Click ( object sender , EventArgs e ) {
4779 var alertCollection = Application . Settings . Alerts . Clone ( ) ;
4880
0 commit comments