Skip to content

Commit

Permalink
Use SnoreToast from installed folder, fix #1238
Browse files Browse the repository at this point in the history
  • Loading branch information
deXol committed Aug 15, 2024
1 parent 133a052 commit d824d98
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/SystemNotifications/SystemNotificationWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ typedef NTSTATUS (NTAPI *PNTQUERYWNFSTATEDATA)(
_Out_writes_bytes_to_opt_(*BufferSize, *BufferSize) PVOID Buffer,
_Inout_ PULONG BufferSize);

const QString SystemNotificationWindows::SNORETOAST= "SnoreToast.exe";
const QString SystemNotificationWindows::SNORETOAST_EXE = "SnoreToast.exe";
const QString SystemNotificationWindows::SNORETOAST= [](){ return findSnoreToast(QDir::currentPath()); }();
const QString SystemNotificationWindows::SNORETOAST_INSTALL= "-install";
const QString SystemNotificationWindows::NOTIFICATIONS_SETTING_REGENTRY = "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings";
const QString SystemNotificationWindows::DND_ENABLED_REGENTRY = "NOC_GLOBAL_SETTING_TOASTS_ENABLED";
Expand All @@ -53,7 +54,6 @@ SystemNotificationWindows::SystemNotificationWindows(QObject *parent)
process = new QProcess();
notificationMap = new NotificationMap();
messageMap = new MessageMap();
installSnoreToast();
}

SystemNotificationWindows::~SystemNotificationWindows()
Expand Down Expand Up @@ -155,6 +155,29 @@ bool SystemNotificationWindows::displayDomainSelectionNotification(const QString
}
}

QString SystemNotificationWindows::findSnoreToast(QString path)
{
QDirIterator it{path, QDirIterator::Subdirectories};
while (it.hasNext())
{
QString filename = it.next();
QFileInfo file{filename};

if (file.isDir())
{
continue;
}

if (file.fileName().contains(SNORETOAST_EXE, Qt::CaseInsensitive))
{
qDebug() << "SnoreToast path: " << file.absoluteFilePath();
return file.absoluteFilePath();
}
}
qWarning() << "SnoreToast is not available.";
return "";
}

void SystemNotificationWindows::installSnoreToast()
{
if (IS_WIN10_OR_ABOVE)
Expand Down
3 changes: 3 additions & 0 deletions src/SystemNotifications/SystemNotificationWindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class SystemNotificationWindows : public ISystemNotification
virtual bool displayLoginRequestNotification(const QString& service, QString &loginName, QString message) override;
virtual bool displayDomainSelectionNotification(const QString& domain, const QString& subdomain, QString &serviceName, QString message) override;

static QString findSnoreToast(QString path);

const static QString SNORETOAST_EXE;
const static QString SNORETOAST;
const static QString SNORETOAST_INSTALL;
const static QString NOTIFICATIONS_SETTING_REGENTRY;
Expand Down

0 comments on commit d824d98

Please sign in to comment.