Skip to content

Commit

Permalink
boost(Profile::TrayIcon): Update the menu to have the profile directl…
Browse files Browse the repository at this point in the history
…y in the menu

Fixes #628
  • Loading branch information
Belphemur committed May 8, 2021
1 parent 5a38887 commit 54003ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
3 changes: 3 additions & 0 deletions SoundSwitch/Framework/Profile/UI/ProfileTrayIconBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SoundSwitch.Common.Framework.Icon;
using SoundSwitch.Framework.Profile.Trigger;
using SoundSwitch.Model;
using SoundSwitch.Properties;

namespace SoundSwitch.Framework.Profile.UI
{
Expand Down Expand Up @@ -58,6 +59,8 @@ private ProfileToolStripMenuItem BuildMenuItem(Profile profile)
}
}

image ??= Resources.default_profile_image;

return new ProfileToolStripMenuItem(profile, image, profileClicked => ProfileManager.SwitchAudio(profileClicked));
}
}
Expand Down
28 changes: 9 additions & 19 deletions SoundSwitch/UI/Component/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ public TrayIcon()

_selectionMenu.Items.Add(TrayIconStrings.noDevicesSelected, RessourceSettingsSmallBitmap, (sender, e) => ShowSettings());

NotifyIcon.MouseDoubleClick += (sender, args) =>
{
AppModel.Instance.CycleActiveDevice(DataFlow.Render);
};
NotifyIcon.MouseDoubleClick += (sender, args) => { AppModel.Instance.CycleActiveDevice(DataFlow.Render); };

NotifyIcon.MouseClick += (sender, e) =>
{
Expand Down Expand Up @@ -143,7 +140,7 @@ public void ReplaceIcon(Icon newIcon)
{
if (newIcon.Equals(NotifyIcon.Icon))
return;

var oldIcon = NotifyIcon.Icon;
NotifyIcon.Icon = (Icon) newIcon.Clone();
try
Expand Down Expand Up @@ -185,10 +182,7 @@ private void PopulateSettingsMenu()

BrowserUtil.OpenUrl(readmeHtml);
});
_settingsMenu.Items.Add(TrayIconStrings.communityMenu, ResourceDiscord.ToBitmap(), (sender, e) =>
{
BrowserUtil.OpenUrl("https://discord.gg/gUCw3Ue");
});
_settingsMenu.Items.Add(TrayIconStrings.communityMenu, ResourceDiscord.ToBitmap(), (sender, e) => { BrowserUtil.OpenUrl("https://discord.gg/gUCw3Ue"); });
_settingsMenu.Items.Add(TrayIconStrings.donate, ResourceDonateBitmap,
(sender, e) => BrowserUtil.OpenUrl($"https://soundswitch.aaflalo.me/?utm_campaign=application&utm_source={Application.ProductVersion}#donate"));
_settingsMenu.Items.Add(TrayIconStrings.about, RessourceHelpSmallBitmap, (sender, e) => new About().Show());
Expand All @@ -208,7 +202,7 @@ private void OnUpdateClick(object sender, EventArgs eventArgs)

StopAnimationIconUpdate();
NotifyIcon.BalloonTipClicked -= OnUpdateClick;
_updateDownloadForm.DownloadRelease((Release)_updateMenuItem.Tag);
_updateDownloadForm.DownloadRelease((Release) _updateMenuItem.Tag);
}

private void SetEventHandlers()
Expand Down Expand Up @@ -283,12 +277,10 @@ private void StopAnimationIconUpdate()
_animationTimer.Stop();
UpdateIcon();
}

public void ShowSettings()
{
_context.Send(state =>
{
new SettingsForm(AppModel.Instance.ActiveUnpluggedAudioLister).Show();
}, null);
_context.Send(state => { new SettingsForm(AppModel.Instance.ActiveUnpluggedAudioLister).Show(); }, null);
}

/// <summary>
Expand All @@ -300,16 +292,13 @@ public void UpdateDeviceSelectionList()
var playbackDevices = AppModel.Instance.AvailablePlaybackDevices;
var recordingDevices = AppModel.Instance.AvailableRecordingDevices;
var profiles = _profileTrayIconBuilder.GetMenuItems().ToArray();


if (profiles.Length > 0)
{
var profileMenu = new ContextMenuStrip();
var profileMenuItem = new ToolStripMenuItem(SettingsStrings.profile_tab) {DropDown = profileMenu, Image = Resources.profile_menu_icon};
profileMenu.Items.AddRange(profiles);
_selectionMenu.Items.Add(profileMenuItem);
_selectionMenu.Items.AddRange(profiles);
_selectionMenu.Items.Add(new ToolStripSeparator());
}

if (playbackDevices.Count < 0 &&
recordingDevices.Count < 0)
{
Expand All @@ -331,6 +320,7 @@ public void UpdateDeviceSelectionList()
_selectionMenu.Items.Add(new ToolStripDeviceItem(DeviceClicked, item));
}
}

}

private void DeviceClicked(object sender, EventArgs e)
Expand Down

0 comments on commit 54003ea

Please sign in to comment.