Skip to content

Commit 2d084ed

Browse files
Add notification for OTP pair
1 parent a7b5c93 commit 2d084ed

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/nvhttp.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,11 @@ namespace nvhttp {
613613
auto hash = util::hex(crypto::hash(one_time_pin + ptr->second.async_insert_pin.salt + otp_passphrase), true);
614614

615615
if (hash.to_string_view() == it->second) {
616+
617+
#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1
618+
system_tray::update_tray_otp_pair(ptr->second.client.name);
619+
#endif
620+
616621
if (!otp_device_name.empty()) {
617622
ptr->second.client.name = std::move(otp_device_name);
618623
}

src/system_tray.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -381,5 +381,30 @@ namespace system_tray {
381381
tray_update(&tray);
382382
}
383383

384+
void
385+
update_tray_otp_pair(std::string device_name) {
386+
if (!tray_initialized) {
387+
return;
388+
}
389+
390+
tray.notification_title = NULL;
391+
tray.notification_text = NULL;
392+
tray.notification_cb = NULL;
393+
tray.notification_icon = NULL;
394+
tray.icon = TRAY_ICON;
395+
tray_update(&tray);
396+
char msg[256];
397+
snprintf(msg, std::size(msg), "OTP Pairing started for device \"%s\". Please make sure you have access to the device initiating the pairing request.", device_name.c_str());
398+
#ifdef _WIN32
399+
strcpy(msg, convertUtf8ToCurrentCodepage(msg).c_str());
400+
#endif
401+
tray.icon = TRAY_ICON;
402+
tray.notification_title = "Incoming OTP Pairing Request";
403+
tray.notification_text = msg;
404+
tray.notification_icon = TRAY_ICON_LOCKED;
405+
tray.tooltip = PROJECT_NAME;
406+
tray_update(&tray);
407+
}
408+
384409
} // namespace system_tray
385410
#endif

src/system_tray.h

+3
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,7 @@ namespace system_tray {
8484
*/
8585
void
8686
update_tray_require_pin();
87+
88+
void
89+
update_tray_otp_pair(std::string device_name);
8790
} // namespace system_tray

0 commit comments

Comments
 (0)