Skip to content

Commit

Permalink
Update OnDemand the trayIcon device list.
Browse files Browse the repository at this point in the history
When iteration the devices list, in the case of Windows Remote Desktop, the device could have disappear without giving a device remove event. This lead to an access to an non-exising device -> MemoryAccess Exception. Fixes #41
  • Loading branch information
Antoine Aflalo committed Dec 26, 2015
1 parent 5c2c785 commit 14d8f59
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
22 changes: 2 additions & 20 deletions SoundSwitch/Util/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public TrayIcon()
_trayIcon.ContextMenuStrip = _settingsMenu;
}
};
UpdateDeviceSelectionList();
SetEventHandlers();
}

Expand Down Expand Up @@ -138,8 +137,8 @@ private void SetEventHandlers()
default:
throw new ArgumentOutOfRangeException();
}
_context.Send(s => { UpdateImageContextMenu(audioDeviceType, audioChangeEvent); }, null);
_needToUpdateList = true;

};
AppModel.Instance.SelectedDeviceChanged +=
(sender, @event) => { _needToUpdateList = true; };
Expand All @@ -160,23 +159,6 @@ private void SetEventHandlers()
AppModel.Instance.InitializeMain();
}


private void UpdateImageContextMenu(AudioDeviceType audioDeviceType, DeviceDefaultChangedEvent audioChangeEvent)
{
if (audioChangeEvent.role != Role.Console)
return;

foreach (
var toolStripDevItem in
_selectionMenu.Items.OfType<ToolStripDeviceItem>()
.Where(item => item.AudioDevice.Type == audioDeviceType))
{
toolStripDevItem.Image = toolStripDevItem.AudioDevice.Id == audioChangeEvent.device.Id
? Resources.Check
: null;
}
}

private void NewReleaseAvailable(object sender, UpdateChecker.NewReleaseEvent newReleaseEvent)
{
_updateMenuItem.Tag = newReleaseEvent.Release;
Expand Down

0 comments on commit 14d8f59

Please sign in to comment.