Skip to content

Commit 4de67e6

Browse files
committed
fix(updater): fix possible issue with the updater crashing at SoundSwitch startup.
Fixes SOUNDSWITCH-1PK
1 parent 3b880c0 commit 4de67e6

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

SoundSwitch/UI/Component/TrayIcon.cs

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/********************************************************************
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+
********************************************************************/
1515

1616
using System;
1717
using System.Diagnostics;
@@ -77,7 +77,7 @@ public sealed class TrayIcon : IDisposable
7777

7878
private ToolStripMenuItem _updateMenuItem;
7979
private TimerForm _animationTimer;
80-
private readonly UpdateDownloadForm _updateDownloadForm;
80+
private readonly Lazy<UpdateDownloadForm> _updateDownloadForm = new(() => new UpdateDownloadForm());
8181
private readonly MethodInfo? _showContextMenu;
8282

8383
public TrayIcon()
@@ -122,7 +122,6 @@ public TrayIcon()
122122
NotifyIcon.ContextMenuStrip = _settingsMenu;
123123
};
124124
SetEventHandlers();
125-
_updateDownloadForm = new UpdateDownloadForm();
126125
_tooltipInfoManager.SetIconText();
127126
}
128127

@@ -142,7 +141,8 @@ public void Dispose()
142141

143142
NotifyIcon.Dispose();
144143
_updateMenuItem.Dispose();
145-
_updateDownloadForm.Dispose();
144+
if (_updateDownloadForm.IsValueCreated)
145+
_updateDownloadForm.Value.Dispose();
146146
}
147147

148148
public void ReplaceIcon(Icon newIcon)
@@ -199,15 +199,15 @@ private void OnUpdateClick(object sender, EventArgs eventArgs)
199199
return;
200200
}
201201

202-
if (_updateDownloadForm.Visible)
202+
if (_updateDownloadForm.Value.Visible)
203203
{
204-
_updateDownloadForm.Focus();
204+
_updateDownloadForm.Value.Focus();
205205
return;
206206
}
207207

208208
StopAnimationIconUpdate();
209209
NotifyIcon.BalloonTipClicked -= OnUpdateClick;
210-
_updateDownloadForm.DownloadRelease((AppRelease)_updateMenuItem.Tag);
210+
_updateDownloadForm.Value.DownloadRelease((AppRelease)_updateMenuItem.Tag);
211211
}
212212

213213
private void SetEventHandlers()
@@ -234,7 +234,7 @@ private void SetEventHandlers()
234234
switch (@event.UpdateMode)
235235
{
236236
case UpdateMode.Never:
237-
_context.Send(_ => _updateDownloadForm.DownloadRelease(@event.AppRelease), null);
237+
_context.Send(_ => _updateDownloadForm.Value.DownloadRelease(@event.AppRelease), null);
238238
break;
239239
case UpdateMode.Notify:
240240
_context.Send(_ => { NewReleaseAvailable(sender, @event); }, null);

0 commit comments

Comments
 (0)