@@ -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" ;
4342const QString SystemNotificationWindows::NOTIFICATIONS_SETTING_REGENTRY = " HKEY_CURRENT_USER\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Notifications\\ Settings" ;
4443const QString SystemNotificationWindows::DND_ENABLED_REGENTRY = " NOC_GLOBAL_SETTING_TOASTS_ENABLED" ;
4544const QString SystemNotificationWindows::TOAST_ENABLED_SETTING_REGPATH = " HKEY_CURRENT_USER\\ Software\\ Microsoft\\ Windows\\ CurrentVersion\\ PushNotifications" ;
4645const 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
5050SystemNotificationWindows::SystemNotificationWindows (QObject *parent)
@@ -79,15 +79,7 @@ SystemNotificationWindows::~SystemNotificationWindows()
7979
8080void 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
9385void 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
116107void 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
125116bool 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
145136bool 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
167158void 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 {
0 commit comments