6
6
using NetSparkleUpdater . Enums ;
7
7
using System . Threading ;
8
8
using System . Collections . Generic ;
9
+ using static System . Windows . Forms . VisualStyles . VisualStyleElement ;
9
10
10
11
namespace NetSparkleUpdater . UI . WinForms
11
12
{
@@ -67,6 +68,19 @@ public UIFactory(Icon applicationIcon) : this()
67
68
/// </summary>
68
69
public ReleaseNotesGrabber ReleaseNotesGrabberOverride { get ; set ; } = null ;
69
70
71
+ /// <summary>
72
+ /// A delegate for handling forms that are created by a <see cref="UIFactory"/>
73
+ /// </summary>
74
+ /// <param name="form"><see cref="Form"/> that has been created and initialized</param>
75
+ /// <param name="factory"><see cref="UIFactory"/> that created the given <see cref="Form"/></param>
76
+ public delegate void FormHandler ( Form form , UIFactory factory ) ;
77
+
78
+ /// <summary>
79
+ /// Set this property to manually do any other setup on a <see cref="Form"/> after it has been created by the <see cref="UIFactory"/>.
80
+ /// Can be used to tweak styles or perform other operations on the <see cref="Form"/>, etc.
81
+ /// </summary>
82
+ public FormHandler ProcessFormAfterInit { get ; set ; }
83
+
70
84
/// <inheritdoc/>
71
85
public virtual IUpdateAvailable CreateUpdateAvailableWindow ( SparkleUpdater sparkle , List < AppCastItem > updates , bool isUpdateAlreadyDownloaded = false )
72
86
{
@@ -89,22 +103,27 @@ public virtual IUpdateAvailable CreateUpdateAvailableWindow(SparkleUpdater spark
89
103
window . ReleaseNotesGrabber = ReleaseNotesGrabberOverride ;
90
104
}
91
105
window . Initialize ( ) ;
106
+ ProcessFormAfterInit ? . Invoke ( window , this ) ;
92
107
return window ;
93
108
}
94
109
95
110
/// <inheritdoc/>
96
111
public virtual IDownloadProgress CreateProgressWindow ( SparkleUpdater sparkle , AppCastItem item )
97
112
{
98
- return new DownloadProgressWindow ( item , _applicationIcon )
113
+ var window = new DownloadProgressWindow ( item , _applicationIcon )
99
114
{
100
115
SoftwareWillRelaunchAfterUpdateInstalled = sparkle . RelaunchAfterUpdate
101
116
} ;
117
+ ProcessFormAfterInit ? . Invoke ( window , this ) ;
118
+ return window ;
102
119
}
103
120
104
121
/// <inheritdoc/>
105
122
public virtual ICheckingForUpdates ShowCheckingForUpdates ( SparkleUpdater sparkle )
106
123
{
107
- return new CheckingForUpdatesWindow ( _applicationIcon ) ;
124
+ var window = new CheckingForUpdatesWindow ( _applicationIcon ) ;
125
+ ProcessFormAfterInit ? . Invoke ( window , this ) ;
126
+ return window ;
108
127
}
109
128
110
129
/// <inheritdoc/>
@@ -156,6 +175,7 @@ public virtual void ShowToast(SparkleUpdater sparkle, List<AppCastItem> updates,
156
175
ClickAction = clickHandler ,
157
176
Updates = updates
158
177
} ;
178
+ ProcessFormAfterInit ? . Invoke ( toast , this ) ;
159
179
toast . Show ( Resources . DefaultUIFactory_ToastMessage , Resources . DefaultUIFactory_ToastCallToAction , 5 ) ;
160
180
Application . Run ( toast ) ;
161
181
} ) ;
@@ -173,6 +193,7 @@ private void ShowMessage(string title, string message)
173
193
{
174
194
var messageWindow = new MessageNotificationWindow ( title , message , _applicationIcon ) ;
175
195
messageWindow . StartPosition = FormStartPosition . CenterScreen ;
196
+ ProcessFormAfterInit ? . Invoke ( messageWindow , this ) ;
176
197
messageWindow . ShowDialog ( ) ;
177
198
}
178
199
0 commit comments