Skip to content

Commit

Permalink
Nullability for UI.WinForms.NetFramework
Browse files Browse the repository at this point in the history
  • Loading branch information
Deadpikle committed Jul 27, 2024
1 parent b918e7f commit 7d1873a
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 45 deletions.
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* Fixed `JSONConfiguration` not using correct default last config/check update time
* Added `nullability` compatibility to core and UI libraries (#595)
* Base language version is now 8.0, but this is only used for nullability compatibility (compile-time), so this shouldn't affect older projects (`.NET 4.6.2`, `netstandard2.0`) and is thus a non-breaking change
* Fixed initialization issue in DownloadProgressWindow (WinForms) icon use

## Updating from 0.X or 1.X to 2.X

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public MessageNotificationWindow(string title, string message, Icon? application
FormBorderStyle = FormBorderStyle.FixedDialog;
}

private void OK_Click(object sender, EventArgs e)
private void OK_Click(object? sender, EventArgs e)
{
Close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void RemoveReleaseNotesControls()
Size newSize = new Size(Size.Width, Size.Height - label3.Height - ReleaseNotesBrowser.Height);

// remove the no more needed controls
label3.Parent.Controls.Remove(label3);
label3.Parent?.Controls.Remove(label3);
ReleaseNotesBrowser.Parent?.Controls.Remove(ReleaseNotesBrowser);

// resize the window
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CheckingForUpdatesWindow()
FormClosing += CheckingForUpdatesWindow_FormClosing;
}

private void CheckingForUpdatesWindow_FormClosing(object sender, FormClosingEventArgs e)
private void CheckingForUpdatesWindow_FormClosing(object? sender, FormClosingEventArgs e)
{
UpdatesUIClosing?.Invoke(sender, new EventArgs());
FormClosing -= CheckingForUpdatesWindow_FormClosing;
Expand All @@ -36,7 +36,7 @@ private void CheckingForUpdatesWindow_FormClosing(object sender, FormClosingEven
/// Initializes window and sets the icon to <paramref name="applicationIcon"/>
/// </summary>
/// <param name="applicationIcon">The icon to use</param>
public CheckingForUpdatesWindow(Icon applicationIcon = null)
public CheckingForUpdatesWindow(Icon? applicationIcon = null)
{
InitializeComponent();
if (applicationIcon != null)
Expand All @@ -50,7 +50,7 @@ public CheckingForUpdatesWindow(Icon applicationIcon = null)
/// <summary>
/// Event that is called when the UI for the checking for updates window is closing
/// </summary>
public event EventHandler UpdatesUIClosing;
public event EventHandler? UpdatesUIClosing;

void ICheckingForUpdates.Close()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class DownloadProgressWindow : Form, IDownloadProgress
/// Event to fire when the download UI is complete; tells you
/// if the install process should happen or not
/// </summary>
public event DownloadInstallEventHandler DownloadProcessCompleted;
public event DownloadInstallEventHandler? DownloadProcessCompleted;

private bool _shouldLaunchInstallFileOnClose = false;
private bool _didCallDownloadProcessCompletedHandler = false;
Expand All @@ -37,11 +37,14 @@ public bool SoftwareWillRelaunchAfterUpdateInstalled
/// </summary>
/// <param name="item">The appcast item to use</param>
/// <param name="applicationIcon">Your application Icon</param>
public DownloadProgressWindow(AppCastItem item, Icon applicationIcon)
public DownloadProgressWindow(AppCastItem item, Icon? applicationIcon)
{
InitializeComponent();

imgAppIcon.Image = applicationIcon.ToBitmap();
if (applicationIcon != null)
{
imgAppIcon.Image = new Icon(applicationIcon, new Size(48, 48)).ToBitmap();
}
Icon = applicationIcon;

// init ui
Expand All @@ -56,7 +59,7 @@ public DownloadProgressWindow(AppCastItem item, Icon applicationIcon)
FormClosing += DownloadProgressWindow_FormClosing;
}

private void DownloadProgressWindow_FormClosing(object sender, FormClosingEventArgs e)
private void DownloadProgressWindow_FormClosing(object? sender, FormClosingEventArgs e)
{
FormClosing -= DownloadProgressWindow_FormClosing;
if (!_didCallDownloadProcessCompletedHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public MessageNotificationWindow()
/// <param name="title">Window title</param>
/// <param name="message">Message</param>
/// <param name="applicationIcon">Your application Icon</param>
public MessageNotificationWindow(string title, string message, Icon applicationIcon = null)
public MessageNotificationWindow(string title, string message, Icon? applicationIcon = null)
{
InitializeComponent();
Text = title;
Expand All @@ -42,7 +42,7 @@ public MessageNotificationWindow(string title, string message, Icon applicationI
FormBorderStyle = FormBorderStyle.FixedDialog;
}

private void OK_Click(object sender, EventArgs e)
private void OK_Click(object? sender, EventArgs e)
{
Close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<Nullable>Enable</Nullable>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>..\bin\Debug\NetSparkle.UI.WinForms\</OutputPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<ItemGroup>
<Compile Update="CheckingForUpdatesWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="DownloadProgressWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="MessageNotificationWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="ToastNotifier.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="UpdateAvailableWindow.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>
16 changes: 8 additions & 8 deletions src/NetSparkle.UI.WinForms.NetFramework/ToastNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class ToastNotifier : Form
/// <summary>
/// constructor
/// </summary>
public ToastNotifier(Icon applicationIcon = null)
public ToastNotifier(Icon? applicationIcon = null)
{
InitializeComponent();
// We want our window to be the top most
Expand Down Expand Up @@ -49,13 +49,13 @@ public ToastNotifier(Icon applicationIcon = null)
/// <summary>
/// Action to perform when the user clicks on the toast window
/// </summary>
public Action<List<AppCastItem>> ClickAction { get; set; }
public Action<List<AppCastItem>>? ClickAction { get; set; }

/// <summary>
/// List of <seealso cref="AppCastItem"/> updates that the user is being
/// notified about in the toast message
/// </summary>
public List<AppCastItem> Updates { get; set; }
public List<AppCastItem>? Updates { get; set; }

private void PauseTimerTick(object sender, EventArgs e)
{
Expand All @@ -77,7 +77,7 @@ protected override void OnLoad(EventArgs e)
_goUpTimer.Start();
}

void GoUpTimerTick(object sender, EventArgs e)
void GoUpTimerTick(object? sender, EventArgs e)
{
//Lift window by 5 pixels
startPosY -= 5;
Expand All @@ -93,7 +93,7 @@ void GoUpTimerTick(object sender, EventArgs e)
}
}

private void GoDownTimerTick(object sender, EventArgs e)
private void GoDownTimerTick(object? sender, EventArgs e)
{
//Lower window by 5 pixels
startPosY += 5;
Expand All @@ -109,10 +109,10 @@ private void GoDownTimerTick(object sender, EventArgs e)
}
}

private void ToastNotifier_Click(object sender, EventArgs e)
private void ToastNotifier_Click(object? sender, EventArgs? e)
{
DialogResult = DialogResult.Yes;
ClickAction?.Invoke(Updates);
ClickAction?.Invoke(Updates ?? new List<AppCastItem>());
Close();
}

Expand All @@ -130,7 +130,7 @@ public void Show(string message, string callToAction, int seconds)
Show();
}

private void callToAction_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
private void callToAction_LinkClicked(object? sender, LinkLabelLinkClickedEventArgs e)
{
this.ToastNotifier_Click(null, null);
}
Expand Down
18 changes: 9 additions & 9 deletions src/NetSparkle.UI.WinForms.NetFramework/UIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class UIFactory : IUIFactory
/// <summary>
/// Icon used on various windows shown by NetSparkleUpdater
/// </summary>
protected Icon _applicationIcon = null;
protected Icon? _applicationIcon = null;

/// <inheritdoc/>
public UIFactory()
Expand All @@ -44,10 +44,10 @@ public UIFactory(Icon applicationIcon) : this()
public bool HideRemindMeLaterButton { get; set; }

/// <inheritdoc/>
public string ReleaseNotesHTMLTemplate { get; set; }
public string? ReleaseNotesHTMLTemplate { get; set; }

/// <inheritdoc/>
public string AdditionalReleaseNotesHeaderHTML { get; set; }
public string? AdditionalReleaseNotesHeaderHTML { get; set; }

/// <summary>
/// The DateTime.ToString() format used when formatting dates to show in the release notes
Expand All @@ -66,7 +66,7 @@ public UIFactory(Icon applicationIcon) : this()
/// Use this if you want to easily override the ReleaseNotesGrabber with your own subclass.
/// </para>
/// </summary>
public ReleaseNotesGrabber ReleaseNotesGrabberOverride { get; set; } = null;
public ReleaseNotesGrabber? ReleaseNotesGrabberOverride { get; set; } = null;

/// <summary>
/// A delegate for handling forms that are created by a <see cref="UIFactory"/>
Expand All @@ -79,13 +79,13 @@ public UIFactory(Icon applicationIcon) : this()
/// Set this property to manually do any other setup on a <see cref="Form"/> after it has been created by the <see cref="UIFactory"/>.
/// Can be used to tweak styles or perform other operations on the <see cref="Form"/>, etc.
/// </summary>
public FormHandler ProcessFormAfterInit { get; set; }
public FormHandler? ProcessFormAfterInit { get; set; }

/// <inheritdoc/>
public virtual IUpdateAvailable CreateUpdateAvailableWindow(SparkleUpdater sparkle, List<AppCastItem> updates, bool isUpdateAlreadyDownloaded = false)
{
var window = new UpdateAvailableWindow(sparkle, updates, _applicationIcon, isUpdateAlreadyDownloaded,
ReleaseNotesHTMLTemplate, AdditionalReleaseNotesHeaderHTML, ReleaseNotesDateTimeFormat);
ReleaseNotesHTMLTemplate ?? "", AdditionalReleaseNotesHeaderHTML ?? "", ReleaseNotesDateTimeFormat);
if (HideReleaseNotes)
{
(window as IUpdateAvailable).HideReleaseNotes();
Expand Down Expand Up @@ -154,7 +154,7 @@ public virtual void ShowVersionIsSkippedByUserRequest(SparkleUpdater sparkle)
}

/// <inheritdoc/>
public virtual void ShowCannotDownloadAppcast(SparkleUpdater sparkle, string appcastUrl)
public virtual void ShowCannotDownloadAppcast(SparkleUpdater sparkle, string? appcastUrl)
{
ShowMessage(Resources.DefaultUIFactory_ErrorTitle, Resources.DefaultUIFactory_ShowCannotDownloadAppcastMessage);
}
Expand All @@ -166,7 +166,7 @@ public virtual bool CanShowToastMessages(SparkleUpdater sparkle)
}

/// <inheritdoc/>
public virtual void ShowToast(SparkleUpdater sparkle, List<AppCastItem> updates, Action<List<AppCastItem>> clickHandler)
public virtual void ShowToast(SparkleUpdater sparkle, List<AppCastItem> updates, Action<List<AppCastItem>>? clickHandler)
{
Thread thread = new Thread(() =>
{
Expand All @@ -184,7 +184,7 @@ public virtual void ShowToast(SparkleUpdater sparkle, List<AppCastItem> updates,
}

/// <inheritdoc/>
public virtual void ShowDownloadErrorMessage(SparkleUpdater sparkle, string message, string appcastUrl)
public virtual void ShowDownloadErrorMessage(SparkleUpdater sparkle, string message, string? appcastUrl)
{
ShowMessage(Resources.DefaultUIFactory_ErrorTitle, string.Format(Resources.DefaultUIFactory_ShowDownloadErrorMessage, message));
}
Expand Down
Loading

0 comments on commit 7d1873a

Please sign in to comment.