Skip to content

Commit 7d9169c

Browse files
committed
Allow window post-process in Avalonia
1 parent 29b9de0 commit 7d9169c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/NetSparkle.UI.Avalonia/UIFactory.cs

+21-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ public UIFactory(WindowIcon applicationIcon, string releaseNotesSeparatorTemplat
101101
/// </summary>
102102
public ReleaseNotesGrabber ReleaseNotesGrabberOverride { get; set; } = null;
103103

104+
/// <summary>
105+
/// A delegate for handling windows that are created by a <see cref="UIFactory"/>
106+
/// </summary>
107+
/// <param name="window"><see cref="Window"/> that has been created and initialized (with view model, if applicable)</param>
108+
/// <param name="factory"><see cref="UIFactory"/> that created the given <see cref="Window"/></param>
109+
public delegate void WindowHandler(Window window, UIFactory factory);
110+
111+
/// <summary>
112+
/// Set this property to manually do any other setup on a <see cref="Window"/> after it has been created by the <see cref="UIFactory"/>.
113+
/// Can be used to tweak view models, change styles on the <see cref="Window"/>, etc.
114+
/// </summary>
115+
public WindowHandler ProcessWindowAfterInit { get; set; }
116+
104117
/// <inheritdoc/>
105118
public virtual IUpdateAvailable CreateUpdateAvailableWindow(SparkleUpdater sparkle, List<AppCastItem> updates, bool isUpdateAlreadyDownloaded = false)
106119
{
@@ -130,6 +143,7 @@ public virtual IUpdateAvailable CreateUpdateAvailableWindow(SparkleUpdater spark
130143
viewModel.ReleaseNotesGrabber = ReleaseNotesGrabberOverride;
131144
}
132145
viewModel.Initialize(sparkle, updates, isUpdateAlreadyDownloaded, ReleaseNotesHTMLTemplate, AdditionalReleaseNotesHeaderHTML, ReleaseNotesDateTimeFormat);
146+
ProcessWindowAfterInit?.Invoke(window, this);
133147
return window;
134148
}
135149

@@ -141,19 +155,23 @@ public virtual IDownloadProgress CreateProgressWindow(SparkleUpdater sparkle, Ap
141155
ItemToDownload = item,
142156
SoftwareWillRelaunchAfterUpdateInstalled = sparkle.RelaunchAfterUpdate
143157
};
144-
return new DownloadProgressWindow(viewModel, _iconBitmap)
158+
var window = new DownloadProgressWindow(viewModel, _iconBitmap)
145159
{
146160
Icon = _applicationIcon
147161
};
162+
ProcessWindowAfterInit?.Invoke(window, this);
163+
return window;
148164
}
149165

150166
/// <inheritdoc/>
151167
public virtual ICheckingForUpdates ShowCheckingForUpdates(SparkleUpdater sparkle)
152168
{
153-
return new CheckingForUpdatesWindow(_iconBitmap)
169+
var window = new CheckingForUpdatesWindow(_iconBitmap)
154170
{
155171
Icon = _applicationIcon
156172
};
173+
ProcessWindowAfterInit?.Invoke(window, this);
174+
return window;
157175
}
158176

159177
/// <inheritdoc/>
@@ -211,6 +229,7 @@ private void ShowMessage(string title, string message)
211229
Icon = _applicationIcon
212230
};
213231
messageWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
232+
ProcessWindowAfterInit?.Invoke(window, this);
214233
messageWindow.Show(); // TODO: This was ShowDialog; will this break anything?
215234
}
216235

0 commit comments

Comments
 (0)