Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 589af77

Browse files
committedFeb 8, 2025·
feat: Add libnotify support
1 parent 0d02a63 commit 589af77

15 files changed

+97
-16
lines changed
 

‎.CI/CreateUbuntuDeb.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ deb_path="Chatterino-ubuntu-${ubuntu_release}-x86_64.deb"
2222
case "$ubuntu_release" in
2323
20.04)
2424
# Qt6 static-linked deb, see https://github.com/Chatterino/docker
25-
dependencies="libc6, libstdc++6, libblkid1, libbsd0, libexpat1, libffi7, libfontconfig1, libfreetype6, libglib2.0-0, libglvnd0, libglx0, libgraphite2-3, libharfbuzz0b, libicu66, libjpeg-turbo8, libmount1, libopengl0, libpcre2-16-0, libpcre3, libpng16-16, libselinux1, libssl1.1, libuuid1, libx11-xcb1, libxau6, libxcb1, libxcb-cursor0, libxcb-glx0, libxcb-icccm4, libxcb-image0, libxcb-keysyms1, libxcb-randr0, libxcb-render0, libxcb-render-util0, libxcb-shape0, libxcb-shm0, libxcb-sync1, libxcb-util1, libxcb-xfixes0, libxcb-xkb1, libxdmcp6, libxkbcommon0, libxkbcommon-x11-0, zlib1g"
25+
dependencies="libc6, libstdc++6, libblkid1, libbsd0, libexpat1, libffi7, libfontconfig1, libfreetype6, libglib2.0-0, libglvnd0, libglx0, libgraphite2-3, libharfbuzz0b, libicu66, libjpeg-turbo8, libmount1, libnotify4, libopengl0, libpcre2-16-0, libpcre3, libpng16-16, libselinux1, libssl1.1, libuuid1, libx11-xcb1, libxau6, libxcb1, libxcb-cursor0, libxcb-glx0, libxcb-icccm4, libxcb-image0, libxcb-keysyms1, libxcb-randr0, libxcb-render0, libxcb-render-util0, libxcb-shape0, libxcb-shm0, libxcb-sync1, libxcb-util1, libxcb-xfixes0, libxcb-xkb1, libxdmcp6, libxkbcommon0, libxkbcommon-x11-0, zlib1g"
2626
;;
2727
22.04)
2828
# Qt6 static-linked deb, see https://github.com/Chatterino/docker
29-
dependencies="libc6, libstdc++6, libglx0, libopengl0, libpng16-16, libharfbuzz0b, libfreetype6, libfontconfig1, libjpeg-turbo8, libxcb-glx0, libegl1, libx11-6, libxkbcommon0, libx11-xcb1, libxkbcommon-x11-0, libxcb-cursor0, libxcb-icccm4, libxcb-image0, libxcb-keysyms1, libxcb-randr0, libxcb-render-util0, libxcb-shm0, libxcb-sync1, libxcb-xfixes0, libxcb-render0, libxcb-shape0, libxcb-xkb1, libxcb1, libbrotli1, libglib2.0-0, zlib1g, libicu70, libpcre2-16-0, libssl3, libgraphite2-3, libexpat1, libuuid1, libxcb-util1, libxau6, libxdmcp6, libffi8, libmount1, libselinux1, libpcre3, libbsd0, libblkid1, libpcre2-8-0, libmd0"
29+
dependencies="libc6, libstdc++6, libglx0, libopengl0, libpng16-16, libharfbuzz0b, libfreetype6, libfontconfig1, libjpeg-turbo8, libxcb-glx0, libegl1, libx11-6, libxkbcommon0, libx11-xcb1, libxkbcommon-x11-0, libxcb-cursor0, libxcb-icccm4, libxcb-image0, libxcb-keysyms1, libxcb-randr0, libxcb-render-util0, libxcb-shm0, libxcb-sync1, libxcb-xfixes0, libxcb-render0, libxcb-shape0, libxcb-xkb1, libxcb1, libbrotli1, libglib2.0-0, zlib1g, libicu70, libpcre2-16-0, libssl3, libgraphite2-3, libexpat1, libuuid1, libxcb-util1, libxau6, libxdmcp6, libffi8, libmount1, libnotify4, libselinux1, libpcre3, libbsd0, libblkid1, libpcre2-8-0, libmd0"
3030
;;
3131
24.04)
3232
# Qt6 static-linked deb, see https://github.com/Chatterino/docker
33-
dependencies="libc6, libstdc++6, libglx0, libopengl0, libpng16-16, libharfbuzz0b, libfreetype6, libfontconfig1, libjpeg-turbo8, libxcb-glx0, libegl1, libx11-6, libxkbcommon0, libx11-xcb1, libxkbcommon-x11-0, libxcb-cursor0, libxcb-icccm4, libxcb-image0, libxcb-keysyms1, libxcb-randr0, libxcb-render-util0, libxcb-shm0, libxcb-sync1, libxcb-xfixes0, libxcb-render0, libxcb-shape0, libxcb-xkb1, libxcb1, libbrotli1, libglib2.0-0, zlib1g, libicu74, libpcre2-16-0, libssl3, libgraphite2-3, libexpat1, libuuid1, libxcb-util1, libxau6, libxdmcp6, libffi8, libmount1, libselinux1, libpcre3, libbsd0, libblkid1, libpcre2-8-0, libmd0"
33+
dependencies="libc6, libstdc++6, libglx0, libopengl0, libpng16-16, libharfbuzz0b, libfreetype6, libfontconfig1, libjpeg-turbo8, libxcb-glx0, libegl1, libx11-6, libxkbcommon0, libx11-xcb1, libxkbcommon-x11-0, libxcb-cursor0, libxcb-icccm4, libxcb-image0, libxcb-keysyms1, libxcb-randr0, libxcb-render-util0, libxcb-shm0, libxcb-sync1, libxcb-xfixes0, libxcb-render0, libxcb-shape0, libxcb-xkb1, libxcb1, libbrotli1, libglib2.0-0, zlib1g, libicu74, libpcre2-16-0, libssl3, libgraphite2-3, libexpat1, libuuid1, libxcb-util1, libxau6, libxdmcp6, libffi8, libmount1, libnotify4, libselinux1, libpcre3, libbsd0, libblkid1, libpcre2-8-0, libmd0"
3434
;;
3535
*)
3636
echo "Unsupported Ubuntu release $ubuntu_release"

‎.cirrus.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ freebsd_instance:
33

44
task:
55
install_script:
6-
- pkg install -y boost-libs git qt6-base qt6-svg qt6-5compat qt6-imageformats qtkeychain-qt6 cmake
6+
- pkg install -y boost-libs git libnotify qt6-base qt6-svg qt6-5compat qt6-imageformats qtkeychain-qt6 cmake pkgconf
77
script: |
88
git submodule init
99
git submodule update

‎.docker/Dockerfile-ubuntu-20.04-base

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ RUN apt-get update && apt-get -y install --no-install-recommends \
1313
libxcb-randr0-dev \
1414
libboost-system-dev \
1515
libboost-filesystem-dev \
16+
libnotify4 \
17+
libnotify-dev \
1618
libpulse-dev \
1719
libxkbcommon-x11-0 \
1820
build-essential \

‎.docker/Dockerfile-ubuntu-22.04-base

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ RUN apt-get update && apt-get -y install --no-install-recommends \
1313
libxcb-randr0-dev \
1414
libboost-system-dev \
1515
libboost-filesystem-dev \
16+
libnotify4 \
17+
libnotify-dev \
1618
libpulse-dev \
1719
libxkbcommon-x11-0 \
1820
build-essential \

‎.docker/Dockerfile-ubuntu-22.04-qt6-build

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ RUN apt-get update && apt-get -y install --no-install-recommends \
1717
libxcb-randr0-dev \
1818
libboost-system-dev \
1919
libboost-filesystem-dev \
20+
libnotify4 \
21+
libnotify-dev \
2022
libpulse-dev \
2123
libxkbcommon-x11-0 \
2224
build-essential \

‎.github/workflows/clang-tidy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
rapidjson-dev,
5757
libbenchmark-dev,
5858
build-essential,
59+
libnotify4, libnotify-dev,
5960
libgl1-mesa-dev, libgstreamer-gl1.0-0, libpulse-dev,
6061
libxcb-glx0, libxcb-icccm4, libxcb-image0, libxcb-keysyms1, libxcb-randr0,
6162
libxcb-render-util0, libxcb-render0, libxcb-shape0, libxcb-shm0, libxcb-sync1,

‎BUILDING_ON_FREEBSD.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ high that this also works on older FreeBSD releases, architectures and
99
FreeBSD 15.0-SNAP.
1010

1111
1. Install build dependencies from package sources (or build from the
12-
ports tree): `# pkg install boost-libs git qt6-base qt6-svg qt6-5compat qt6-imageformats qtkeychain-qt6 cmake`
12+
ports tree): `# pkg install boost-libs git libnotify qt6-base qt6-svg qt6-5compat qt6-imageformats qtkeychain-qt6 cmake`
1313
1. In the project directory, create a build directory and enter it
1414
```sh
1515
mkdir build

‎BUILDING_ON_LINUX.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ The built binary should be exportable from the final image & able to run on your
1717
### Debian 12 (bookworm) or later
1818

1919
```sh
20-
sudo apt install qt6-base-dev qt6-5compat-dev qt6-svg-dev qt6-image-formats-plugins libboost1.81-dev libssl-dev cmake g++ git
20+
sudo apt install qt6-base-dev qt6-5compat-dev qt6-svg-dev qt6-image-formats-plugins libboost1.81-dev libnotify-dev libssl-dev cmake g++ git
2121
```
2222

2323
### Arch Linux
2424

2525
```sh
26-
sudo pacman -S --needed qt6-base qt6-tools boost-libs openssl qt6-imageformats qt6-5compat qt6-svg boost rapidjson pkgconf openssl cmake
26+
sudo pacman -S --needed qt6-base qt6-tools boost-libs openssl qt6-imageformats qt6-5compat qt6-svg boost libnotify rapidjson pkgconf openssl cmake
2727
```
2828

2929
If you use Wayland, you will also need to ensure `qt6-wayland` is installed.
@@ -35,13 +35,13 @@ Alternatively you can use the [chatterino2-git](https://aur.archlinux.org/packag
3535
_Most likely works the same for other Red Hat-like distros. Substitute `dnf` with `yum`._
3636

3737
```sh
38-
sudo dnf install qt6-qtbase-devel qt6-qtimageformats qt6-qtsvg-devel qt6-qt5compat-devel g++ git openssl-devel boost-devel cmake
38+
sudo dnf install qt6-qtbase-devel qt6-qtimageformats qt6-qtsvg-devel qt6-qt5compat-devel g++ git openssl-devel boost-devel libnotify-devel cmake
3939
```
4040

4141
### NixOS 18.09+
4242

4343
```sh
44-
nix-shell -p openssl boost qt6.full pkg-config cmake
44+
nix-shell -p openssl boost qt6.full pkg-config cmake libnotify
4545
```
4646

4747
## Compile

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Minor: When (re-)connecting, visible channels are now joined first. (#5850)
1010
- Minor: Added the ability to filter on messages by the author's user ID (example: `author.user_id == "22484632"`). (#5862)
1111
- Minor: Improved error messaging of the `/clip` command. (#5879)
12+
- Minor: Added Linux support for Live Notifications toasts. (#5881)
1213
- Bugfix: Fixed a potential way to escape the Lua Plugin sandbox. (#5846)
1314
- Bugfix: Fixed a crash relating to Lua HTTP. (#5800)
1415
- Bugfix: Fixed a crash that could occur on Linux and macOS when clicking "Install" from the update prompt. (#5818)

‎CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ option(USE_SYSTEM_MINIAUDIO "Build Chatterino with your system miniaudio" OFF)
2222
option(BUILD_WITH_CRASHPAD "Build chatterino with crashpad" OFF)
2323
option(USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
2424
option(BUILD_WITH_QT6 "Build with Qt6" On)
25+
option(BUILD_WITH_LIBNOTIFY "Build with libnotify" ON)
2526
option(CHATTERINO_GENERATE_COVERAGE "Generate coverage files" OFF)
2627
# We don't use translations, and we don't want qtkeychain to build translations
2728
option(BUILD_TRANSLATIONS "" OFF)

‎src/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,15 @@ if (UNIX)
10621062
message(STATUS "Linking with CMake DL libs: '${CMAKE_DL_LIBS}'")
10631063
target_link_libraries(${LIBRARY_PROJECT} PUBLIC ${CMAKE_DL_LIBS})
10641064
endif ()
1065+
1066+
if (NOT APPLE AND BUILD_WITH_LIBNOTIFY)
1067+
find_package(PkgConfig REQUIRED)
1068+
pkg_check_modules(LIBNOTIFY REQUIRED libnotify)
1069+
include_directories(${LIBRARY_PROJECT} ${LIBNOTIFY_INCLUDE_DIRS})
1070+
target_link_libraries(${LIBRARY_PROJECT} PRIVATE ${LIBNOTIFY_LIBRARIES})
1071+
target_link_directories(${LIBRARY_PROJECT} PRIVATE ${LIBNOTIFY_LIBRARY_DIRS})
1072+
target_compile_definitions(${LIBRARY_PROJECT} PUBLIC CHATTERINO_WITH_LIBNOTIFY)
1073+
endif ()
10651074
endif ()
10661075

10671076
if (WIN32)

‎src/controllers/commands/builtin/chatterino/Debugging.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "common/Env.hpp"
66
#include "common/Literals.hpp"
77
#include "controllers/commands/CommandContext.hpp"
8+
#include "controllers/notifications/NotificationController.hpp"
89
#include "messages/Image.hpp"
910
#include "messages/Message.hpp"
1011
#include "messages/MessageBuilder.hpp"
@@ -13,6 +14,7 @@
1314
#include "providers/twitch/TwitchChannel.hpp"
1415
#include "providers/twitch/TwitchIrcServer.hpp"
1516
#include "singletons/Theme.hpp"
17+
#include "singletons/Toasts.hpp"
1618
#include "util/PostToThread.hpp"
1719

1820
#include <QApplication>
@@ -180,6 +182,15 @@ QString debugTest(const CommandContext &ctx)
180182
.arg(nowMillis);
181183
getApp()->getTwitch()->addFakeMessage(ircText);
182184
}
185+
else if (command == "desktop-notify")
186+
{
187+
auto title = ctx.twitchChannel->accessStreamStatus()->title;
188+
189+
getApp()->getToasts()->sendChannelNotification(
190+
ctx.twitchChannel->getName(), title, Platform::Twitch);
191+
ctx.channel->addSystemMessage(
192+
QString("debug-test sent desktop notification"));
193+
}
183194
else
184195
{
185196
ctx.channel->addSystemMessage(

‎src/singletons/Toasts.cpp

+51-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#ifdef Q_OS_WIN
1818
# include <wintoastlib.h>
19+
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
20+
# include <libnotify/notify.h>
1921
#endif
2022

2123
#include <QDesktopServices>
@@ -77,18 +79,25 @@ Toasts::~Toasts()
7779
{
7880
WinToast::instance()->clear();
7981
}
82+
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
83+
if (this->initialized_)
84+
{
85+
notify_uninit();
86+
}
8087
#endif
8188
}
8289

8390
bool Toasts::isEnabled()
8491
{
92+
auto enabled = getSettings()->notificationToast &&
93+
!(getApp()->getStreamerMode()->isEnabled() &&
94+
getSettings()->streamerModeSuppressLiveNotifications);
95+
8596
#ifdef Q_OS_WIN
86-
return WinToast::isCompatible() && getSettings()->notificationToast &&
87-
!(getApp()->getStreamerMode()->isEnabled() &&
88-
getSettings()->streamerModeSuppressLiveNotifications);
89-
#else
90-
return false;
97+
enabled = enabled && WinToast::isCompatible();
9198
#endif
99+
100+
return enabled;
92101
}
93102

94103
QString Toasts::findStringFromReaction(const ToastReaction &reaction)
@@ -123,10 +132,14 @@ void Toasts::sendChannelNotification(const QString &channelName,
123132
auto sendChannelNotification = [this, channelName, channelTitle, p] {
124133
this->sendWindowsNotification(channelName, channelTitle, p);
125134
};
135+
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
136+
auto sendChannelNotification = [this, channelName, channelTitle] {
137+
this->sendLibnotify(channelName, channelTitle);
138+
};
126139
#else
127140
(void)channelTitle;
128141
auto sendChannelNotification = [] {
129-
// Unimplemented for macOS and Linux
142+
// Unimplemented for macOS
130143
};
131144
#endif
132145
// Fetch user profile avatar
@@ -282,6 +295,38 @@ void Toasts::sendWindowsNotification(const QString &channelName,
282295
}
283296
}
284297

298+
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
299+
300+
void Toasts::ensureInitialized()
301+
{
302+
if (this->initialized_)
303+
{
304+
return;
305+
}
306+
auto result = notify_init("chatterino2");
307+
308+
if (result == 0)
309+
{
310+
qCWarning(chatterinoNotification) << "Failed to initialize libnotify";
311+
}
312+
this->initialized_ = true;
313+
}
314+
315+
void Toasts::sendLibnotify(const QString &channelName,
316+
const QString &channelTitle)
317+
{
318+
this->ensureInitialized();
319+
320+
qCDebug(chatterinoNotification) << "sending to libnotify";
321+
322+
QString str = channelName % u" is live!";
323+
324+
NotifyNotification *notif = notify_notification_new(
325+
str.toUtf8().constData(), channelTitle.toUtf8().constData(), nullptr);
326+
327+
notify_notification_show(notif, nullptr);
328+
g_object_unref(notif);
329+
}
285330
#endif
286331

287332
} // namespace chatterino

‎src/singletons/Toasts.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class Toasts final
3535
void sendWindowsNotification(const QString &channelName,
3636
const QString &channelTitle, Platform p);
3737

38+
bool initialized_ = false;
39+
#elif defined(CHATTERINO_WITH_LIBNOTIFY)
40+
void ensureInitialized();
41+
void sendLibnotify(const QString &channelName, const QString &channelTitle);
42+
3843
bool initialized_ = false;
3944
#endif
4045
};

‎src/widgets/settingspages/NotificationPage.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ NotificationPage::NotificationPage()
4646
settings.append(this->createCheckBox(
4747
"Suppress live notifications on startup",
4848
getSettings()->suppressInitialLiveNotification));
49-
#ifdef Q_OS_WIN
49+
#if defined(Q_OS_WIN) || defined(CHATTERINO_WITH_LIBNOTIFY)
5050
settings.append(this->createCheckBox(
5151
"Show notification", getSettings()->notificationToast));
52+
#endif
53+
#ifdef Q_OS_WIN
5254
auto openIn = settings.emplace<QHBoxLayout>().withoutMargin();
5355
{
5456
openIn

0 commit comments

Comments
 (0)
Please sign in to comment.