Skip to content

Commit

Permalink
Add notification for OTP pair
Browse files Browse the repository at this point in the history
  • Loading branch information
ClassicOldSong committed Sep 10, 2024
1 parent a7b5c93 commit 2d084ed
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,11 @@ namespace nvhttp {
auto hash = util::hex(crypto::hash(one_time_pin + ptr->second.async_insert_pin.salt + otp_passphrase), true);

if (hash.to_string_view() == it->second) {

#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1
system_tray::update_tray_otp_pair(ptr->second.client.name);
#endif

if (!otp_device_name.empty()) {
ptr->second.client.name = std::move(otp_device_name);
}
Expand Down
25 changes: 25 additions & 0 deletions src/system_tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,5 +381,30 @@ namespace system_tray {
tray_update(&tray);
}

void
update_tray_otp_pair(std::string device_name) {
if (!tray_initialized) {
return;
}

tray.notification_title = NULL;
tray.notification_text = NULL;
tray.notification_cb = NULL;
tray.notification_icon = NULL;
tray.icon = TRAY_ICON;
tray_update(&tray);
char msg[256];
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());
#ifdef _WIN32
strcpy(msg, convertUtf8ToCurrentCodepage(msg).c_str());
#endif
tray.icon = TRAY_ICON;
tray.notification_title = "Incoming OTP Pairing Request";
tray.notification_text = msg;
tray.notification_icon = TRAY_ICON_LOCKED;
tray.tooltip = PROJECT_NAME;
tray_update(&tray);
}

} // namespace system_tray
#endif
3 changes: 3 additions & 0 deletions src/system_tray.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ namespace system_tray {
*/
void
update_tray_require_pin();

void
update_tray_otp_pair(std::string device_name);
} // namespace system_tray

0 comments on commit 2d084ed

Please sign in to comment.