Skip to content

Commit

Permalink
Added audio icon and added it build as well. Added support for settin…
Browse files Browse the repository at this point in the history
…g hotkeys for specific audio outputs.
  • Loading branch information
Fahim-zzz committed Nov 18, 2024
1 parent d2b4e2c commit 9c7a9e4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
4 changes: 4 additions & 0 deletions DAIRemote/DAIRemote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<BuildAction>None</BuildAction>
</None>
<None Update="Resources\Audio.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<BuildAction>None</BuildAction>
</None>
</ItemGroup>

</Project>
21 changes: 19 additions & 2 deletions DAIRemote/HotkeyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
namespace DAIRemote;
public partial class HotkeyManager : Form
{
private AudioManager.AudioDeviceManager audioManager;
public Dictionary<string, HotkeyConfig> hotkeyConfigs;
private readonly string ConfigFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DAIRemote/hotkeys.json");

public HotkeyManager()
{
audioManager = AudioManager.AudioDeviceManager.GetInstance();
LoadHotkeyConfigs();
}

Expand All @@ -33,7 +35,6 @@ private void UnregisterHotkey(string action)
private const uint MOD_ALT = 0x0001;
private const uint MOD_CONTROL = 0x0002;
private const uint MOD_SHIFT = 0x0004;
private const uint MOD_WIN = 0x0008;

public string GetHotkeyText(HotkeyConfig config)
{
Expand Down Expand Up @@ -102,7 +103,18 @@ public void RegisterCallbacks()
// Register Audio Cycling Callback
if (hotkeyConfigs.ContainsKey("Audio Cycling"))
{
hotkeyConfigs["Audio Cycling"].Callback = AudioManager.AudioDeviceManager.GetInstance().CycleAudioDevice;
hotkeyConfigs["Audio Cycling"].Callback = audioManager.CycleAudioDevice;
}

// Register Audio Callbacks
List<string> audoDevices = audioManager.ActiveDeviceNames;

foreach (string audioDeviceName in audoDevices)
{
if (hotkeyConfigs.ContainsKey(audioDeviceName))
{
hotkeyConfigs[audioDeviceName].Callback = () => audioManager.SetDefaultAudioDevice(audioDeviceName);
}
}
}

Expand Down Expand Up @@ -149,6 +161,11 @@ public void ShowHotkeyInput(string action, Action functionAction)
buttonPanel.Controls.Add(okButton);
buttonPanel.Controls.Add(cancelButton);

if (hotkeyConfigs.ContainsKey(action))
{
inputBox.Text = GetHotkeyText(hotkeyConfigs[action]);
}

uint modifiers = 0;
uint keyCode = 0;

Expand Down
Binary file added DAIRemote/Resources/Audio.ico
Binary file not shown.
36 changes: 34 additions & 2 deletions DAIRemote/SystemTray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class TrayIconManager
private FileSystemWatcher displayProfileDirWatcher;
private readonly string displayProfilesFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DAIRemote/DisplayProfiles");
private HotkeyManager hotkeyManager;
private AudioManager.AudioDeviceManager audioManager;

private Image aboutIcon;
private Image DAIRemoteLogoIcon;
Expand All @@ -21,6 +22,7 @@ public class TrayIconManager
private Image addProfileIcon;
private Image setHotkeyIcon;
private Image audioCyclingIcon;
private Image audioIcon;

public TrayIconManager(Form form)
{
Expand All @@ -36,12 +38,14 @@ public TrayIconManager(Form form)
addProfileIcon = Image.FromFile("Resources/AddProfile.ico");
setHotkeyIcon = Image.FromFile("Resources/MonitorSetHotkey.ico");
audioCyclingIcon = Image.FromFile("Resources/AudioCycling.ico");
audioIcon = Image.FromFile("Resources/Audio.ico");

if (!Directory.Exists(displayProfilesFolderPath))
{
Directory.CreateDirectory(displayProfilesFolderPath);
}

audioManager = AudioManager.AudioDeviceManager.GetInstance();
// Registers any prexisting hotkeys, otherwise initializes
// an empty dictionary in preparation for hotkeys.
hotkeyManager = new HotkeyManager();
Expand Down Expand Up @@ -152,7 +156,7 @@ private void PopulateTrayMenu(ContextMenuStrip menu)
: "";
ToolStripMenuItem audioCyclingHotkey = new($"Audio Cycling{hotkeyText}", audioCyclingIcon, (sender, e) =>
{
hotkeyManager.ShowHotkeyInput("Audio Cycling", () => AudioManager.AudioDeviceManager.GetInstance().CycleAudioDevice());
hotkeyManager.ShowHotkeyInput("Audio Cycling", () => audioManager.CycleAudioDevice());

// Refresh to show the updated hotkey
string updatedHotkeyText = hotkeyManager.hotkeyConfigs.ContainsKey("Audio Cycling")
Expand All @@ -170,8 +174,36 @@ private void PopulateTrayMenu(ContextMenuStrip menu)
}
});

// Add audio cycling item to the hotkey submenu and separate it
// Add audio cycling item to the hotkey submenu
setHotkeysMenuItem.DropDownItems.Add(audioCyclingHotkey);

// Add audio devices to hotkey submenu
List<string> audioDevices = audioManager.ActiveDeviceNames;
foreach (string audioDevice in audioDevices)
{
ToolStripMenuItem audioItem = new(audioDevice, audioIcon, (sender, e) =>
{
hotkeyManager.ShowHotkeyInput(audioDevice, () => audioManager.SetDefaultAudioDevice(audioDevice));

// Refresh to show the updated hotkey
string updatedHotkeyText = hotkeyManager.hotkeyConfigs.ContainsKey(audioDevice)
? $" ({hotkeyManager.GetHotkeyText(hotkeyManager.hotkeyConfigs[audioDevice])})"
: "";

// Find the existing menu item
foreach (var item in setHotkeysMenuItem.DropDownItems)
{
if (item is ToolStripMenuItem menuItem && menuItem.Text.StartsWith(audioDevice))
{
menuItem.Text = $"{audioDevice}{updatedHotkeyText}";
return;
}
}
});
setHotkeysMenuItem.DropDownItems.Add(audioItem);
}

// Separate audio hotkeys from display hotkeys in hotkey submenu
setHotkeysMenuItem.DropDownItems.Add(new ToolStripSeparator());

// Add load profiles label to the main menu and separate it
Expand Down

0 comments on commit 9c7a9e4

Please sign in to comment.