1
1
/********************************************************************
2
- * Copyright (C) 2015 Jeroen Pelgrims
3
- * Copyright (C) 2015-2017 Antoine Aflalo
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * as published by the Free Software Foundation; either version 2
8
- * of the License, or (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- ********************************************************************/
2
+ * Copyright (C) 2015 Jeroen Pelgrims
3
+ * Copyright (C) 2015-2017 Antoine Aflalo
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * as published by the Free Software Foundation; either version 2
8
+ * of the License, or (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ ********************************************************************/
15
15
16
16
using System ;
17
17
using System . Diagnostics ;
@@ -77,7 +77,7 @@ public sealed class TrayIcon : IDisposable
77
77
78
78
private ToolStripMenuItem _updateMenuItem ;
79
79
private TimerForm _animationTimer ;
80
- private readonly UpdateDownloadForm _updateDownloadForm ;
80
+ private readonly Lazy < UpdateDownloadForm > _updateDownloadForm = new ( ( ) => new UpdateDownloadForm ( ) ) ;
81
81
private readonly MethodInfo ? _showContextMenu ;
82
82
83
83
public TrayIcon ( )
@@ -122,7 +122,6 @@ public TrayIcon()
122
122
NotifyIcon . ContextMenuStrip = _settingsMenu ;
123
123
} ;
124
124
SetEventHandlers ( ) ;
125
- _updateDownloadForm = new UpdateDownloadForm ( ) ;
126
125
_tooltipInfoManager . SetIconText ( ) ;
127
126
}
128
127
@@ -142,7 +141,8 @@ public void Dispose()
142
141
143
142
NotifyIcon . Dispose ( ) ;
144
143
_updateMenuItem . Dispose ( ) ;
145
- _updateDownloadForm . Dispose ( ) ;
144
+ if ( _updateDownloadForm . IsValueCreated )
145
+ _updateDownloadForm . Value . Dispose ( ) ;
146
146
}
147
147
148
148
public void ReplaceIcon ( Icon newIcon )
@@ -199,15 +199,15 @@ private void OnUpdateClick(object sender, EventArgs eventArgs)
199
199
return ;
200
200
}
201
201
202
- if ( _updateDownloadForm . Visible )
202
+ if ( _updateDownloadForm . Value . Visible )
203
203
{
204
- _updateDownloadForm . Focus ( ) ;
204
+ _updateDownloadForm . Value . Focus ( ) ;
205
205
return ;
206
206
}
207
207
208
208
StopAnimationIconUpdate ( ) ;
209
209
NotifyIcon . BalloonTipClicked -= OnUpdateClick ;
210
- _updateDownloadForm . DownloadRelease ( ( AppRelease ) _updateMenuItem . Tag ) ;
210
+ _updateDownloadForm . Value . DownloadRelease ( ( AppRelease ) _updateMenuItem . Tag ) ;
211
211
}
212
212
213
213
private void SetEventHandlers ( )
@@ -234,7 +234,7 @@ private void SetEventHandlers()
234
234
switch ( @event . UpdateMode )
235
235
{
236
236
case UpdateMode . Never :
237
- _context . Send ( _ => _updateDownloadForm . DownloadRelease ( @event . AppRelease ) , null ) ;
237
+ _context . Send ( _ => _updateDownloadForm . Value . DownloadRelease ( @event . AppRelease ) , null ) ;
238
238
break ;
239
239
case UpdateMode . Notify :
240
240
_context . Send ( _ => { NewReleaseAvailable ( sender , @event ) ; } , null ) ;
0 commit comments