1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 05:52:55 +08:00

Avoid initial synchronous dropdown population overhead in AudioDevicesSettings

This commit is contained in:
Dean Herbert 2021-08-16 19:17:36 +09:00
parent 8d051d9fa0
commit b541550ea9

View File

@ -20,17 +20,26 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
private SettingsDropdown<string> dropdown; private SettingsDropdown<string> dropdown;
protected override void Dispose(bool isDisposing) [BackgroundDependencyLoader]
private void load()
{ {
base.Dispose(isDisposing); Children = new Drawable[]
if (audio != null)
{ {
audio.OnNewDevice -= onDeviceChanged; dropdown = new AudioDeviceSettingsDropdown
audio.OnLostDevice -= onDeviceChanged; {
} Keywords = new[] { "speaker", "headphone", "output" }
}
};
updateItems();
audio.OnNewDevice += onDeviceChanged;
audio.OnLostDevice += onDeviceChanged;
dropdown.Current = audio.AudioDevice;
} }
private void onDeviceChanged(string name) => updateItems();
private void updateItems() private void updateItems()
{ {
var deviceItems = new List<string> { string.Empty }; var deviceItems = new List<string> { string.Empty };
@ -49,26 +58,15 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
dropdown.Items = deviceItems.Distinct().ToList(); dropdown.Items = deviceItems.Distinct().ToList();
} }
private void onDeviceChanged(string name) => updateItems(); protected override void Dispose(bool isDisposing)
protected override void LoadComplete()
{ {
base.LoadComplete(); base.Dispose(isDisposing);
Children = new Drawable[] if (audio != null)
{ {
dropdown = new AudioDeviceSettingsDropdown audio.OnNewDevice -= onDeviceChanged;
{ audio.OnLostDevice -= onDeviceChanged;
Keywords = new[] { "speaker", "headphone", "output" } }
}
};
updateItems();
dropdown.Current = audio.AudioDevice;
audio.OnNewDevice += onDeviceChanged;
audio.OnLostDevice += onDeviceChanged;
} }
private class AudioDeviceSettingsDropdown : SettingsDropdown<string> private class AudioDeviceSettingsDropdown : SettingsDropdown<string>