Skip to content

Commit 2b41386

Browse files
Improve Windows notification test reliability
Replaces direct registry modification for Quiet Hours in CI with a date change workaround. Updates unit tests to check Windows notification state using SHQueryUserNotificationState and skip tests if notifications are not accepted, improving test reliability in CI environments.
1 parent ecb0880 commit 2b41386

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,16 @@ jobs:
156156
[System.Windows.Forms.SendKeys]::SendWait(" ")
157157
echo "::endgroup::"
158158
159-
echo "::group::Disable Quiet Hours"
160-
Set-ItemProperty `
161-
-Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings" `
162-
-Name "QuietHours" `
163-
-Type DWord `
164-
-Value 0
165-
Start-Process "gpupdate.exe" -ArgumentList "/force" -Wait
166-
echo "::endgroup::"
167-
168159
echo "::group::Minimize all windows"
169160
$shell = New-Object -ComObject Shell.Application
170161
$shell.MinimizeAll()
171162
echo "::endgroup::"
172163
164+
echo "::group::Set Date - Hack for Quiet Time"
165+
$newDate = (Get-Date).AddHours(2)
166+
Set-Date -Date $newDate
167+
echo "::endgroup::"
168+
173169
- name: Run tests
174170
id: test
175171
# TODO: tests randomly hang on Linux, https://github.com/LizardByte/tray/issues/45

tests/unit/test_tray.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
#if defined(_WIN32) || defined(_WIN64)
99
#include <windows.h>
10+
// clang-format off
11+
// build fails if shellapi.h is included before windows.h
12+
#include <shellapi.h>
13+
// clang-format on
1014
#define TRAY_WINAPI 1
1115
#elif defined(__linux__) || defined(linux) || defined(__linux)
1216
#define TRAY_APPINDICATOR 1
@@ -276,6 +280,14 @@ TEST_F(TrayTest, TestSubmenuCallback) {
276280
TEST_F(TrayTest, TestNotificationDisplay) {
277281
#if !(defined(_WIN32) || defined(__linux__) || defined(__APPLE__))
278282
GTEST_SKIP() << "Notifications only supported on desktop platforms";
283+
#endif
284+
285+
#if defined(_WIN32)
286+
QUERY_USER_NOTIFICATION_STATE notification_state;
287+
HRESULT ns = SHQueryUserNotificationState(&notification_state);
288+
if (ns != S_OK || notification_state != QUNS_ACCEPTS_NOTIFICATIONS) {
289+
GTEST_SKIP() << "Notifications not accepted in this environment. SHQueryUserNotificationState result: " << ns << ", state: " << notification_state;
290+
}
279291
#endif
280292

281293
int initResult = tray_init(&testTray);
@@ -304,6 +316,14 @@ TEST_F(TrayTest, TestNotificationCallback) {
304316
GTEST_SKIP() << "Notifications only supported on desktop platforms";
305317
#endif
306318

319+
#if defined(_WIN32)
320+
QUERY_USER_NOTIFICATION_STATE notification_state;
321+
HRESULT ns = SHQueryUserNotificationState(&notification_state);
322+
if (ns != S_OK || notification_state != QUNS_ACCEPTS_NOTIFICATIONS) {
323+
GTEST_SKIP() << "Notifications not accepted in this environment. SHQueryUserNotificationState result: " << ns << ", state: " << notification_state;
324+
}
325+
#endif
326+
307327
static bool callbackInvoked = false;
308328
auto notification_callback = []() {
309329
callbackInvoked = true;

0 commit comments

Comments
 (0)