Skip to content

Commit 8847c71

Browse files
authored
Add notification force script
1 parent 9e64abc commit 8847c71

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

force.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Xavier Bergeron 2020
2+
// https://github.com/xaviergmail/DiscordNotificationDebug/
3+
// This program tricks any Electron instances into thinking that the computer is locked and going to sleep every X seconds
4+
// The purpose of this is to trigger mobile push notifications for Discord regardless of current activity state.
5+
6+
#include <iostream>
7+
#include <windows.h>
8+
#include <vector>
9+
10+
BOOL CALLBACK processWindow(HWND hWindow, LPARAM param)
11+
{
12+
char szName[1024];
13+
GetWindowTextA(hWindow, szName, 1024);
14+
15+
char szClass[1024];
16+
GetClassNameA(hWindow, szClass, 1024);
17+
18+
printf("\"%s\" [%s]: ", szName, szClass);
19+
DWORD sessionID = 0;
20+
ProcessIdToSessionId(GetCurrentProcessId(), &sessionID);
21+
22+
printf("Sending sleep event.. ");
23+
SendMessageA(hWindow, WM_WTSSESSION_CHANGE, WTS_SESSION_LOCK, sessionID); // "lock" event
24+
SendMessageA(hWindow, WM_POWERBROADCAST, PBT_APMSUSPEND, NULL); // "suspend" event
25+
Sleep(1500);
26+
printf("Sending resume event\n\n");
27+
SendMessageA(hWindow, WM_POWERBROADCAST, PBT_APMRESUMEAUTOMATIC, NULL); // "resume" event
28+
SendMessageA(hWindow, WM_WTSSESSION_CHANGE, WTS_SESSION_UNLOCK, sessionID); // "unlock" event
29+
30+
return TRUE;
31+
}
32+
33+
// Reference:
34+
// https://github.com/electron/electron/blob/a9924e1c32e8445887e3a6b5cdff445d93c2b18f/shell/browser/api/electron_api_power_monitor_win.cc
35+
const char* kPowerMonitorWindowClass = "Electron_PowerMonitorHostWindow";
36+
37+
void findWindows(HWND hWindow = NULL) {
38+
do {
39+
hWindow = FindWindowExA(NULL, hWindow, kPowerMonitorWindowClass, NULL);
40+
processWindow(hWindow, NULL);
41+
} while (hWindow != NULL);
42+
}
43+
44+
int main(int argc, const char** argv) {
45+
std::cout
46+
<< "Starting discord push notification forcer v1\n"
47+
<< "Written by Xavier Bergeron https://github.com/xaviergmail/DiscordNotificationDebug/\n\n"
48+
<< std::endl;
49+
50+
int seconds = 10;
51+
52+
if (argc < 2) {
53+
std::cout << "You can also pass the amount in seconds as a command line argument to avoid this prompt\n";
54+
std::cout << "Enter the amount in seconds between notification pushes (minimum 1): " << std::flush;
55+
std::cin >> seconds;
56+
}
57+
else {
58+
seconds = atoi(argv[1]);
59+
}
60+
61+
seconds = seconds < 1 ? 1 : seconds;
62+
printf("Starting force notification push every %d seconds! Keep this window open.\n", seconds);
63+
while (true) {
64+
findWindows();
65+
Sleep(seconds * 1000);
66+
}
67+
}

0 commit comments

Comments
 (0)