Skip to content

Commit 34a1131

Browse files
committed
boost(Update): Clicking on the update menu item will trigger update
Fixes #641
1 parent 297d0ed commit 34a1131

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

SoundSwitch/Model/AppModel.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,14 @@ public UpdateMode UpdateMode
145145
get => AppConfigs.Configuration.UpdateMode;
146146
set
147147
{
148-
if (value != AppConfigs.Configuration.UpdateMode && value != UpdateMode.Never)
148+
if (value != AppConfigs.Configuration.UpdateMode)
149149
{
150-
CheckForUpdate();
150+
if (value != UpdateMode.Never)
151+
{
152+
CheckForUpdate();
153+
}
154+
155+
UpdateModeChanged?.Invoke(this, value);
151156
}
152157

153158
AppConfigs.Configuration.UpdateMode = value;
@@ -212,6 +217,7 @@ public bool RunAtStartup
212217
public IAudioDeviceLister ActiveUnpluggedAudioLister { get; set; }
213218
public event EventHandler<NotificationSettingsUpdatedEvent> NotificationSettingsChanged;
214219
public event EventHandler<CustomSoundChangedEvent> CustomSoundChanged;
220+
public event EventHandler<UpdateMode> UpdateModeChanged;
215221

216222
#endregion
217223

SoundSwitch/Model/IAppModel.cs

+10
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,15 @@ public interface IAppModel : IDisposable
201201
bool CycleActiveDevice(DataFlow type);
202202

203203
#endregion
204+
205+
/// <summary>
206+
/// Triggered when the update mode has been changed
207+
/// </summary>
208+
event EventHandler<UpdateMode> UpdateModeChanged;
209+
210+
/// <summary>
211+
/// For the app to check for update
212+
/// </summary>
213+
void CheckForUpdate();
204214
}
205215
}

SoundSwitch/UI/Component/TrayIcon.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public sealed class TrayIcon : IDisposable
7171
private readonly TooltipInfoManager _tooltipInfoManager;
7272
private readonly ProfileTrayIconBuilder _profileTrayIconBuilder;
7373

74-
private readonly ToolStripMenuItem _updateMenuItem;
74+
private ToolStripMenuItem _updateMenuItem;
7575
private TimerForm _animationTimer;
7676
private readonly UpdateDownloadForm _updateDownloadForm;
7777
private readonly MethodInfo? _showContextMenu;
@@ -85,7 +85,7 @@ public TrayIcon()
8585

8686
_updateMenuItem = new ToolStripMenuItem(AppConfigs.Configuration.UpdateMode == UpdateMode.Never ? TrayIconStrings.updateDisabled : TrayIconStrings.noUpdate, RessourceUpdateBitmap, OnUpdateClick)
8787
{
88-
Enabled = false
88+
Enabled = AppConfigs.Configuration.UpdateMode != UpdateMode.Never
8989
};
9090
NotifyIcon.ContextMenuStrip = _settingsMenu;
9191

@@ -159,6 +159,7 @@ private void PopulateSettingsMenu()
159159
{
160160
var applicationDirectory = Path.GetDirectoryName(ApplicationPath.Executable);
161161
Debug.Assert(applicationDirectory != null, "applicationDirectory != null");
162+
_settingsMenu.Items.Clear();
162163
_settingsMenu.Items.Add(Application.ProductName + ' ' + AssemblyUtils.GetReleaseState() + " (" + Application.ProductVersion + ")", SoundSwitchLogoIcon.ToBitmap());
163164
_settingsMenu.Items.Add(new ToolStripSeparator());
164165
_settingsMenu.Items.Add(TrayIconStrings.playbackDevices, RessourcePlaybackDevicesBitmap,
@@ -181,7 +182,11 @@ private void PopulateSettingsMenu()
181182
private void OnUpdateClick(object sender, EventArgs eventArgs)
182183
{
183184
if (_updateMenuItem.Tag == null)
185+
{
186+
AppModel.Instance.CheckForUpdate();
184187
return;
188+
}
189+
185190
if (_updateDownloadForm.Visible)
186191
{
187192
_updateDownloadForm.Focus();
@@ -217,9 +222,14 @@ private void SetEventHandlers()
217222
if (@event.UpdateMode == UpdateMode.Notify)
218223
_context.Send(s => { NewReleaseAvailable(sender, @event); }, null);
219224
};
220-
AppModel.Instance.DefaultDeviceChanged += (_, _) =>
225+
AppModel.Instance.DefaultDeviceChanged += (_, _) => { _tooltipInfoManager.SetIconText(); };
226+
AppModel.Instance.UpdateModeChanged += (_, mode) =>
221227
{
222-
_tooltipInfoManager.SetIconText();
228+
_updateMenuItem = new ToolStripMenuItem(mode == UpdateMode.Never ? TrayIconStrings.updateDisabled : TrayIconStrings.noUpdate, RessourceUpdateBitmap, OnUpdateClick)
229+
{
230+
Enabled = mode != UpdateMode.Never
231+
};
232+
PopulateSettingsMenu();
223233
};
224234
}
225235

0 commit comments

Comments
 (0)