Skip to content

Commit 64bdfc3

Browse files
committed
WPF - Allow processing a window after init
#467
1 parent a8b0f82 commit 64bdfc3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/NetSparkle.UI.WPF/UIFactory.cs

+22-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ public UIFactory(ImageSource applicationIcon) : this()
9191
/// </summary>
9292
public System.Windows.Media.Brush UpdateWindowGridBackgroundBrush { get; set; }
9393

94+
/// <summary>
95+
/// A delegate for handling windows that are created by a <see cref="UIFactory"/>
96+
/// </summary>
97+
/// <param name="window"><see cref="Window"/> that has been created and initialized (with view model, if applicable)</param>
98+
/// <param name="factory"><see cref="UIFactory"/> that created the given <see cref="Window"/></param>
99+
public delegate void WindowHandler(Window window, UIFactory factory);
100+
101+
/// <summary>
102+
/// Set this property to manually do any other setup on a <see cref="Window"/> after it has been created by the <see cref="UIFactory"/>.
103+
/// Can be used to tweak view models, change styles on the <see cref="Window"/>, etc.
104+
/// </summary>
105+
public WindowHandler ProcessWindowAfterInit { get; set; }
106+
94107
/// <inheritdoc/>
95108
public virtual IUpdateAvailable CreateUpdateAvailableWindow(SparkleUpdater sparkle, List<AppCastItem> updates, bool isUpdateAlreadyDownloaded = false)
96109
{
@@ -120,6 +133,7 @@ public virtual IUpdateAvailable CreateUpdateAvailableWindow(SparkleUpdater spark
120133
viewModel.ReleaseNotesGrabber = ReleaseNotesGrabberOverride;
121134
}
122135
viewModel.Initialize(sparkle, updates, isUpdateAlreadyDownloaded, ReleaseNotesHTMLTemplate, AdditionalReleaseNotesHeaderHTML, ReleaseNotesDateTimeFormat);
136+
ProcessWindowAfterInit?.Invoke(window, this);
123137
return window;
124138
}
125139

@@ -131,16 +145,20 @@ public virtual IDownloadProgress CreateProgressWindow(SparkleUpdater sparkle, Ap
131145
ItemToDownload = item,
132146
SoftwareWillRelaunchAfterUpdateInstalled = sparkle.RelaunchAfterUpdate
133147
};
134-
return new DownloadProgressWindow(viewModel)
148+
var window = new DownloadProgressWindow(viewModel)
135149
{
136150
Icon = _applicationIcon
137151
};
152+
ProcessWindowAfterInit?.Invoke(window, this);
153+
return window;
138154
}
139155

140156
/// <inheritdoc/>
141157
public virtual ICheckingForUpdates ShowCheckingForUpdates(SparkleUpdater sparkle)
142158
{
143-
return new CheckingForUpdatesWindow { Icon = _applicationIcon };
159+
var window = new CheckingForUpdatesWindow() { Icon = _applicationIcon };
160+
ProcessWindowAfterInit?.Invoke(window, this);
161+
return window;
144162
}
145163

146164
/// <inheritdoc/>
@@ -192,6 +210,7 @@ public virtual void ShowToast(SparkleUpdater sparkle, List<AppCastItem> updates,
192210
};
193211
try
194212
{
213+
ProcessWindowAfterInit?.Invoke(toast, this);
195214
toast.Show(Resources.DefaultUIFactory_ToastMessage, Resources.DefaultUIFactory_ToastCallToAction, 5);
196215
System.Windows.Threading.Dispatcher.Run();
197216
}
@@ -218,6 +237,7 @@ private void ShowMessage(string title, string message)
218237
Icon = _applicationIcon
219238
};
220239
messageWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
240+
ProcessWindowAfterInit?.Invoke(messageWindow, this);
221241
messageWindow.ShowDialog();
222242
}
223243

0 commit comments

Comments
 (0)