Skip to content

Commit

Permalink
feat(Update): Let's the user be a to manually check for update by cli…
Browse files Browse the repository at this point in the history
…cking the update menu item.

Fixes #642
  • Loading branch information
Belphemur committed May 16, 2021
1 parent 34a1131 commit 8dd63c1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
9 changes: 9 additions & 0 deletions SoundSwitch/Localization/TrayIconStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions SoundSwitch/Localization/TrayIconStrings.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,7 @@
<data name="updateDisabled" xml:space="preserve">
<value>Vérification MàJ désactivée</value>
</data>
<data name="forceCheckForUpdate" xml:space="preserve">
<value>Vérifier MàJ</value>
</data>
</root>
3 changes: 3 additions & 0 deletions SoundSwitch/Localization/TrayIconStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,7 @@
<data name="updateDisabled" xml:space="preserve">
<value>Update check disabled</value>
</data>
<data name="forceCheckForUpdate" xml:space="preserve">
<value>Check for update</value>
</data>
</root>
34 changes: 18 additions & 16 deletions SoundSwitch/UI/Component/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ public TrayIcon()
_tooltipInfoManager = new TooltipInfoManager(NotifyIcon);
_profileTrayIconBuilder = new ProfileTrayIconBuilder();

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

PopulateSettingsMenu();
Expand Down Expand Up @@ -120,6 +117,11 @@ public TrayIcon()
_tooltipInfoManager.SetIconText();
}

private void SetUpdateMenuItem(UpdateMode mode)
{
_updateMenuItem = new ToolStripMenuItem(mode == UpdateMode.Never ? TrayIconStrings.forceCheckForUpdate : TrayIconStrings.noUpdate, RessourceUpdateBitmap, OnUpdateClick);
}

public void Dispose()
{
_selectionMenu.Dispose();
Expand Down Expand Up @@ -219,16 +221,20 @@ private void SetEventHandlers()
};
AppModel.Instance.NewVersionReleased += (sender, @event) =>
{
if (@event.UpdateMode == UpdateMode.Notify)
_context.Send(s => { NewReleaseAvailable(sender, @event); }, null);
switch (@event.UpdateMode)
{
case UpdateMode.Never:
_context.Send(state => _updateDownloadForm.DownloadRelease(@event.Release), null);
break;
case UpdateMode.Notify:
_context.Send(s => { NewReleaseAvailable(sender, @event); }, null);
break;
}
};
AppModel.Instance.DefaultDeviceChanged += (_, _) => { _tooltipInfoManager.SetIconText(); };
AppModel.Instance.UpdateModeChanged += (_, mode) =>
{
_updateMenuItem = new ToolStripMenuItem(mode == UpdateMode.Never ? TrayIconStrings.updateDisabled : TrayIconStrings.noUpdate, RessourceUpdateBitmap, OnUpdateClick)
{
Enabled = mode != UpdateMode.Never
};
SetUpdateMenuItem(mode);
PopulateSettingsMenu();
};
}
Expand All @@ -237,13 +243,9 @@ private void NewReleaseAvailable(object sender, UpdateChecker.NewReleaseEvent ne
{
StartAnimationIconUpdate();
_updateMenuItem.Tag = newReleaseEvent.Release;
_updateMenuItem.Text =
string.Format(TrayIconStrings.updateAvailable, newReleaseEvent.Release.ReleaseVersion);
_updateMenuItem.Enabled = true;
_updateMenuItem.Text = string.Format(TrayIconStrings.updateAvailable, newReleaseEvent.Release.ReleaseVersion);
NotifyIcon.BalloonTipClicked += OnUpdateClick;
NotifyIcon.ShowBalloonTip(3000,
string.Format(TrayIconStrings.versionAvailable, newReleaseEvent.Release.ReleaseVersion),
newReleaseEvent.Release.Name + '\n' + TrayIconStrings.clickToUpdate, ToolTipIcon.Info);
NotifyIcon.ShowBalloonTip(3000, string.Format(TrayIconStrings.versionAvailable, newReleaseEvent.Release.ReleaseVersion), newReleaseEvent.Release.Name + '\n' + TrayIconStrings.clickToUpdate, ToolTipIcon.Info);
}

/// <summary>
Expand Down

0 comments on commit 8dd63c1

Please sign in to comment.