Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sound-file notification hint on Linux #28884

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class NotificationData final : public base::has_weak_ptr {
const not_null<Manager*> _manager;
NotificationId _id;

//Media::Audio::LocalDiskCache _sounds;
Media::Audio::LocalDiskCache _sounds;

Gio::Application _application;
Gio::Notification _notification;
Expand Down Expand Up @@ -222,7 +222,7 @@ NotificationData::NotificationData(
NotificationId id)
: _manager(manager)
, _id(id)
//, _sounds(cWorkingDir() + u"tdata/audio_cache"_q)
, _sounds(cWorkingDir() + u"tdata/audio_cache"_q)
, _application(UseGNotification()
? Gio::Application::get_default()
: nullptr)
Expand All @@ -236,8 +236,7 @@ NotificationData::NotificationData(
bool NotificationData::init(const Info &info) {
const auto &title = info.title;
const auto &subtitle = info.subtitle;
//const auto sound = info.sound ? info.sound() : Media::Audio::LocalSound();
//const auto path = sound ? _sounds.path(sound) : QString();

if (_application) {
_notification = Gio::Notification::new_(
subtitle.isEmpty()
Expand Down Expand Up @@ -365,18 +364,23 @@ bool NotificationData::init(const Info &info) {
_hints.insert_value("action-icons", GLib::Variant::new_boolean(true));
}

// suppress system sound if telegram sound activated,
// otherwise use system sound
if (HasCapability("sound")) {
if (Core::App().settings().soundNotify()) {
const auto sound = info.sound
? info.sound()
: Media::Audio::LocalSound();

const auto path = sound
? _sounds.path(sound).toStdString()
: std::string();

if (!path.empty()) {
_hints.insert_value(
"suppress-sound",
GLib::Variant::new_boolean(true));
"sound-file",
GLib::Variant::new_string(path));
} else {
// sound name according to http://0pointer.de/public/sound-naming-spec.html
_hints.insert_value(
"sound-name",
GLib::Variant::new_string("message-new-instant"));
"suppress-sound",
GLib::Variant::new_boolean(true));
}
}

Expand Down Expand Up @@ -624,8 +628,9 @@ bool ByDefault() {
"actions",
// To have quick reply
"inline-reply",
}, HasCapability) && ranges::any_of(std::array{
// To not to play sound with Don't Disturb activated
// (no, using sound capability is not a way)
"sound",
"inhibitions",
}, HasCapability);
}
Expand Down Expand Up @@ -963,7 +968,9 @@ bool Manager::doSkipToast() const {
}

void Manager::doMaybePlaySound(Fn<void()> playSound) {
_private->invokeIfNotInhibited(std::move(playSound));
if (UseGNotification() || !HasCapability("sound")) {
_private->invokeIfNotInhibited(std::move(playSound));
}
}

void Manager::doMaybeFlashBounce(Fn<void()> flashBounce) {
Expand Down
Loading