Skip to content

Commit

Permalink
boost(Update): Clicking on the update menu item will trigger update
Browse files Browse the repository at this point in the history
Fixes #641
  • Loading branch information
Belphemur committed May 15, 2021
1 parent 297d0ed commit 34a1131
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
10 changes: 8 additions & 2 deletions SoundSwitch/Model/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,14 @@ public UpdateMode UpdateMode
get => AppConfigs.Configuration.UpdateMode;
set
{
if (value != AppConfigs.Configuration.UpdateMode && value != UpdateMode.Never)
if (value != AppConfigs.Configuration.UpdateMode)
{
CheckForUpdate();
if (value != UpdateMode.Never)
{
CheckForUpdate();
}

UpdateModeChanged?.Invoke(this, value);
}

AppConfigs.Configuration.UpdateMode = value;
Expand Down Expand Up @@ -212,6 +217,7 @@ public bool RunAtStartup
public IAudioDeviceLister ActiveUnpluggedAudioLister { get; set; }
public event EventHandler<NotificationSettingsUpdatedEvent> NotificationSettingsChanged;
public event EventHandler<CustomSoundChangedEvent> CustomSoundChanged;
public event EventHandler<UpdateMode> UpdateModeChanged;

#endregion

Expand Down
10 changes: 10 additions & 0 deletions SoundSwitch/Model/IAppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,15 @@ public interface IAppModel : IDisposable
bool CycleActiveDevice(DataFlow type);

#endregion

/// <summary>
/// Triggered when the update mode has been changed
/// </summary>
event EventHandler<UpdateMode> UpdateModeChanged;

/// <summary>
/// For the app to check for update
/// </summary>
void CheckForUpdate();
}
}
18 changes: 14 additions & 4 deletions SoundSwitch/UI/Component/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public sealed class TrayIcon : IDisposable
private readonly TooltipInfoManager _tooltipInfoManager;
private readonly ProfileTrayIconBuilder _profileTrayIconBuilder;

private readonly ToolStripMenuItem _updateMenuItem;
private ToolStripMenuItem _updateMenuItem;
private TimerForm _animationTimer;
private readonly UpdateDownloadForm _updateDownloadForm;
private readonly MethodInfo? _showContextMenu;
Expand All @@ -85,7 +85,7 @@ public TrayIcon()

_updateMenuItem = new ToolStripMenuItem(AppConfigs.Configuration.UpdateMode == UpdateMode.Never ? TrayIconStrings.updateDisabled : TrayIconStrings.noUpdate, RessourceUpdateBitmap, OnUpdateClick)
{
Enabled = false
Enabled = AppConfigs.Configuration.UpdateMode != UpdateMode.Never
};
NotifyIcon.ContextMenuStrip = _settingsMenu;

Expand Down Expand Up @@ -159,6 +159,7 @@ private void PopulateSettingsMenu()
{
var applicationDirectory = Path.GetDirectoryName(ApplicationPath.Executable);
Debug.Assert(applicationDirectory != null, "applicationDirectory != null");
_settingsMenu.Items.Clear();
_settingsMenu.Items.Add(Application.ProductName + ' ' + AssemblyUtils.GetReleaseState() + " (" + Application.ProductVersion + ")", SoundSwitchLogoIcon.ToBitmap());
_settingsMenu.Items.Add(new ToolStripSeparator());
_settingsMenu.Items.Add(TrayIconStrings.playbackDevices, RessourcePlaybackDevicesBitmap,
Expand All @@ -181,7 +182,11 @@ private void PopulateSettingsMenu()
private void OnUpdateClick(object sender, EventArgs eventArgs)
{
if (_updateMenuItem.Tag == null)
{
AppModel.Instance.CheckForUpdate();
return;
}

if (_updateDownloadForm.Visible)
{
_updateDownloadForm.Focus();
Expand Down Expand Up @@ -217,9 +222,14 @@ private void SetEventHandlers()
if (@event.UpdateMode == UpdateMode.Notify)
_context.Send(s => { NewReleaseAvailable(sender, @event); }, null);
};
AppModel.Instance.DefaultDeviceChanged += (_, _) =>
AppModel.Instance.DefaultDeviceChanged += (_, _) => { _tooltipInfoManager.SetIconText(); };
AppModel.Instance.UpdateModeChanged += (_, mode) =>
{
_tooltipInfoManager.SetIconText();
_updateMenuItem = new ToolStripMenuItem(mode == UpdateMode.Never ? TrayIconStrings.updateDisabled : TrayIconStrings.noUpdate, RessourceUpdateBitmap, OnUpdateClick)
{
Enabled = mode != UpdateMode.Never
};
PopulateSettingsMenu();
};
}

Expand Down

0 comments on commit 34a1131

Please sign in to comment.