oh yea, it was that easy

This commit is contained in:
Mike Griese 2021-10-14 12:57:58 -05:00
parent 8fbd32d3c3
commit 4c4fde9da3
4 changed files with 22 additions and 18 deletions

View file

@ -1131,25 +1131,21 @@ void Pane::_ControlWarningBellHandler(const winrt::Windows::Foundation::IInspect
if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Audible))
{
// Audible is set, play the sound
// const auto soundAlias = reinterpret_cast<LPCTSTR>(SND_ALIAS_SYSTEMHAND);
// PlaySound(soundAlias, NULL, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY);
auto sounds{ _profile.BellSound() };
if (sounds && sounds.Size() > 0)
{
winrt::Windows::Foundation::Uri uri{ sounds.GetAt(rand() % sounds.Size()) };
auto source{ winrt::Windows::Media::Core::MediaSource::CreateFromUri(uri) };
auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) };
p.Source(item);
p.Play();
}
else
{
const auto soundAlias = reinterpret_cast<LPCTSTR>(SND_ALIAS_SYSTEMHAND);
PlaySound(soundAlias, NULL, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY);
winrt::Windows::Foundation::Uri honks[]{
winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk1.mp3"),
winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk2.mp3"),
winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk3.mp3"),
winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk4.mp3"),
winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk-muffled1.mp3"),
winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk-muffled2.mp3"),
winrt::Windows::Foundation::Uri(L"C:\\Users\\migrie\\Downloads\\memes\\honks\\Honk-muffled3.mp3"),
};
auto uri{ honks[rand() % ARRAYSIZE(honks)] };
auto source{ winrt::Windows::Media::Core::MediaSource::CreateFromUri(uri) };
auto item{ winrt::Windows::Media::Playback::MediaPlaybackItem(source) };
p.Source(item);
p.Play();
}
}
if (WI_IsFlagSet(_profile.BellStyle(), winrt::Microsoft::Terminal::Settings::Model::BellStyle::Window))

View file

@ -45,6 +45,7 @@ static constexpr std::string_view AntialiasingModeKey{ "antialiasingMode" };
static constexpr std::string_view TabColorKey{ "tabColor" };
static constexpr std::string_view BellStyleKey{ "bellStyle" };
static constexpr std::string_view UnfocusedAppearanceKey{ "unfocusedAppearance" };
static constexpr std::string_view BellSoundKey{ "bellSound" };
Profile::Profile(guid guid) noexcept :
_Guid(guid)
@ -134,6 +135,7 @@ winrt::com_ptr<Profile> Profile::CopySettings() const
profile->_SnapOnInput = _SnapOnInput;
profile->_AltGrAliasing = _AltGrAliasing;
profile->_BellStyle = _BellStyle;
profile->_BellSound = _BellSound;
profile->_ConnectionType = _ConnectionType;
profile->_Origin = _Origin;
profile->_FontInfo = *fontInfo;
@ -221,6 +223,7 @@ void Profile::LayerJson(const Json::Value& json)
JsonUtils::GetValueForKey(json, AntialiasingModeKey, _AntialiasingMode);
JsonUtils::GetValueForKey(json, TabColorKey, _TabColor);
JsonUtils::GetValueForKey(json, BellStyleKey, _BellStyle);
JsonUtils::GetValueForKey(json, BellSoundKey, _BellSound);
if (json.isMember(JsonKey(UnfocusedAppearanceKey)))
{
@ -374,6 +377,7 @@ Json::Value Profile::ToJson() const
JsonUtils::SetValueForKey(json, AntialiasingModeKey, _AntialiasingMode);
JsonUtils::SetValueForKey(json, TabColorKey, _TabColor);
JsonUtils::SetValueForKey(json, BellStyleKey, _BellStyle);
JsonUtils::SetValueForKey(json, BellSoundKey, _BellSound);
// Font settings
const auto fontInfoImpl = winrt::get_self<FontConfig>(_FontInfo);

View file

@ -140,6 +140,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::Profile, Model::IAppearanceConfig, UnfocusedAppearance, nullptr);
INHERITABLE_SETTING(Model::Profile, Windows::Foundation::Collections::IVector<winrt::hstring>, BellSound);
private:
Model::IAppearanceConfig _DefaultAppearance{ winrt::make<AppearanceConfig>(weak_ref<Model::Profile>(*this)) };
Model::FontConfig _FontInfo{ winrt::make<FontConfig>(weak_ref<Model::Profile>(*this)) };

View file

@ -81,5 +81,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_PROFILE_SETTING(Boolean, SnapOnInput);
INHERITABLE_PROFILE_SETTING(Boolean, AltGrAliasing);
INHERITABLE_PROFILE_SETTING(BellStyle, BellStyle);
INHERITABLE_PROFILE_SETTING(Windows.Foundation.Collections.IVector<String>, BellSound);
}
}