Skip to content

Commit 95399fb

Browse files
authored
Merge pull request #1220 from deXol/develop
Fix SnoreToast notifications for Win10
2 parents 48015ad + ecf23d8 commit 95399fb

3 files changed

Lines changed: 24 additions & 28 deletions

File tree

src/AppGui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#ifdef Q_OS_WIN
2828
#include "SystemNotifications/SystemNotificationWindows.h"
29+
#include "windows.h"
2930
#endif
3031

3132
#ifdef Q_OS_MAC

src/SystemNotifications/SystemNotificationWindows.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ typedef NTSTATUS (NTAPI *PNTQUERYWNFSTATEDATA)(
3737
_Out_writes_bytes_to_opt_(*BufferSize, *BufferSize) PVOID Buffer,
3838
_Inout_ PULONG BufferSize);
3939

40-
const QString SystemNotificationWindows::SNORETOAST_FORMAT= "SnoreToast.exe -t \"%1\" -m \"%2\" %3 %4 -p icon.png %5";
41-
const QString SystemNotificationWindows::SNORETOAST_INSTALL= "SnoreToast.exe -install";
42-
const QString SystemNotificationWindows::WINDOWS10_VERSION = "10";
40+
const QString SystemNotificationWindows::SNORETOAST= "SnoreToast.exe";
41+
const QString SystemNotificationWindows::SNORETOAST_INSTALL= "-install";
4342
const QString SystemNotificationWindows::NOTIFICATIONS_SETTING_REGENTRY = "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings";
4443
const QString SystemNotificationWindows::DND_ENABLED_REGENTRY = "NOC_GLOBAL_SETTING_TOASTS_ENABLED";
4544
const QString SystemNotificationWindows::TOAST_ENABLED_SETTING_REGPATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\PushNotifications";
4645
const QString SystemNotificationWindows::TOAST_ENABLED_REGENTRY = "ToastEnabled";
47-
const bool SystemNotificationWindows::IS_WIN10 = QSysInfo::productVersion() == WINDOWS10_VERSION;
46+
const QString SystemNotificationWindows::ICON = "icon.png";
47+
const bool SystemNotificationWindows::IS_WIN10_OR_ABOVE = QSysInfo::productVersion().toInt() >= WINDOWS10_VERSION;
4848

4949

5050
SystemNotificationWindows::SystemNotificationWindows(QObject *parent)
@@ -79,15 +79,7 @@ SystemNotificationWindows::~SystemNotificationWindows()
7979

8080
void SystemNotificationWindows::createNotification(const QString &title, const QString text)
8181
{
82-
if (IS_WIN10)
83-
{
84-
QString notification = SNORETOAST_FORMAT.arg(title, text, "", "", "");
85-
process->start(notification);
86-
}
87-
else
88-
{
89-
emit notifySystray(title, text);
90-
}
82+
emit notifySystray(title, text);
9183
}
9284

9385
void SystemNotificationWindows::createButtonChoiceNotification(const QString &title, const QString text, const QStringList &buttons)
@@ -97,34 +89,33 @@ void SystemNotificationWindows::createButtonChoiceNotification(const QString &ti
9789
qDebug() << "createButtonChoiceNotification called without button text";
9890
return;
9991
}
100-
QString buttonString = "-b \"";
92+
QString buttonString = "";
10193
for (const auto &piece : buttons)
10294
{
10395
buttonString += piece + ";";
10496
}
10597

106-
buttonString = buttonString.replace(buttonString.size()-1, 1, "\"");
98+
buttonString = buttonString.replace(buttonString.size()-1, 1, "");
10799

108100
QProcess *proc = new QProcess();
109101
notificationMap->insert(notificationId, proc);
110-
QString notification = SNORETOAST_FORMAT.arg(title, text, buttonString, "-id " + QString::number(notificationId++), "-w");
111102
connect(proc, static_cast<CallbackType>(&QProcess::finished), this, &SystemNotificationWindows::callbackFunction);
112-
qDebug() << notification;
113-
proc->start(notification);
103+
QStringList choiceArgs = { "-t", title, "-m", text, "-b", buttonString, "-id", QString::number(notificationId++), "-p", ICON, "-w"};
104+
proc->start(SNORETOAST, choiceArgs);
114105
}
115106

116107
void SystemNotificationWindows::createTextBoxNotification(const QString &title, const QString text)
117108
{
118109
QProcess *proc = new QProcess();
119110
notificationMap->insert(notificationId, proc);
120-
QString notification = SNORETOAST_FORMAT.arg(title, text, "-tb", "-id " + QString::number(notificationId++), "-w");
111+
QStringList textNotiArgs = { "-t", title, "-m", text, "-tb", "-id", QString::number(notificationId++), "-p", ICON, "-w"};
121112
connect(proc, static_cast<CallbackType>(&QProcess::finished), this, &SystemNotificationWindows::callbackFunction);
122-
proc->start(notification);
113+
proc->start(SNORETOAST, textNotiArgs);
123114
}
124115

125116
bool SystemNotificationWindows::displayLoginRequestNotification(const QString &service, QString &loginName, QString message)
126117
{
127-
if (IS_WIN10 && !isDoNotDisturbEnabled())
118+
if (IS_WIN10_OR_ABOVE && !isDoNotDisturbEnabled())
128119
{
129120
// A text box notification is displayed on Win10
130121
messageMap->insert(notificationId, message);
@@ -144,7 +135,7 @@ bool SystemNotificationWindows::displayLoginRequestNotification(const QString &s
144135

145136
bool SystemNotificationWindows::displayDomainSelectionNotification(const QString &domain, const QString &subdomain, QString &serviceName, QString message)
146137
{
147-
if (IS_WIN10 && !isDoNotDisturbEnabled())
138+
if (IS_WIN10_OR_ABOVE && !isDoNotDisturbEnabled())
148139
{
149140
// A button choice notification is displayed on Win10
150141
QStringList buttons;
@@ -166,9 +157,9 @@ bool SystemNotificationWindows::displayDomainSelectionNotification(const QString
166157

167158
void SystemNotificationWindows::installSnoreToast()
168159
{
169-
if (IS_WIN10)
160+
if (IS_WIN10_OR_ABOVE)
170161
{
171-
process->start(SNORETOAST_INSTALL);
162+
process->start(SNORETOAST, {SNORETOAST_INSTALL});
172163
}
173164
}
174165

@@ -201,7 +192,10 @@ bool SystemNotificationWindows::isDoNotDisturbEnabled() const
201192
QSettings settings(NOTIFICATIONS_SETTING_REGENTRY, QSettings::NativeFormat);
202193
bool isDoNotDisturb = !settings.value(DND_ENABLED_REGENTRY).isNull();
203194
QSettings toastSetting(TOAST_ENABLED_SETTING_REGPATH, QSettings::NativeFormat);
204-
isDoNotDisturb |= !toastSetting.value(TOAST_ENABLED_REGENTRY).toBool();
195+
if (toastSetting.contains(TOAST_ENABLED_REGENTRY))
196+
{
197+
isDoNotDisturb |= !toastSetting.value(TOAST_ENABLED_REGENTRY).toBool();
198+
}
205199

206200
if (!isDoNotDisturb)
207201
{

src/SystemNotifications/SystemNotificationWindows.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ class SystemNotificationWindows : public ISystemNotification
3030
virtual bool displayLoginRequestNotification(const QString& service, QString &loginName, QString message) override;
3131
virtual bool displayDomainSelectionNotification(const QString& domain, const QString& subdomain, QString &serviceName, QString message) override;
3232

33-
const static QString SNORETOAST_FORMAT;
33+
const static QString SNORETOAST;
3434
const static QString SNORETOAST_INSTALL;
35-
const static QString WINDOWS10_VERSION;
3635
const static QString NOTIFICATIONS_SETTING_REGENTRY;
3736
const static QString DND_ENABLED_REGENTRY;
3837
const static QString TOAST_ENABLED_SETTING_REGPATH;
3938
const static QString TOAST_ENABLED_REGENTRY;
40-
const static bool IS_WIN10;
39+
const static QString ICON;
40+
const static int WINDOWS10_VERSION = 10;
41+
const static bool IS_WIN10_OR_ABOVE;
4142

4243
signals:
4344
void notifySystray(QString title, QString text);

0 commit comments

Comments
 (0)