From de6a151fd011a76f0e5965ad79d62bcd4a629030 Mon Sep 17 00:00:00 2001 From: Kevin Whitaker Date: Sat, 18 Feb 2017 23:13:13 -0500 Subject: [PATCH] Clean up some things. Make skip vote longer. Put in js that should show notifications for skip requests. --- src/GroovePlayer.cpp | 2 +- src/WebInterface.cpp | 10 +++++++++- src/WebInterface.h | 3 +++ src/ui/PlayerInterface.h | 4 ---- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/GroovePlayer.cpp b/src/GroovePlayer.cpp index a22e210..7465f0b 100644 --- a/src/GroovePlayer.cpp +++ b/src/GroovePlayer.cpp @@ -540,7 +540,7 @@ GroovePlayerMgr::PlayerEvent GroovePlayerMgr::getNextPlayerEvent(Wt::Dbo::Sessio return PlayerEvent() = {PlayerEventType::GROOVE_NOWPLAYING}; } } - if(!voteEndedButNotNextTrackYet && currentSkipRequester.size() > 0 && skipRequestedAt+std::chrono::seconds(5) < std::chrono::steady_clock::now()) + if(!voteEndedButNotNextTrackYet && currentSkipRequester.size() > 0 && skipRequestedAt+std::chrono::seconds(10) < std::chrono::steady_clock::now()) { //Skip succeeded. Time to skip song. lastInternalEvents.push_front(PlayerEvent() = {PlayerEventType::SKIP_VOTING_ENDED}); diff --git a/src/WebInterface.cpp b/src/WebInterface.cpp index c8510cf..ece8102 100644 --- a/src/WebInterface.cpp +++ b/src/WebInterface.cpp @@ -45,6 +45,7 @@ WebInterface::WebInterface(const Wt::WEnvironment& env) : Wt::WApplication(env) root()->addWidget(priv_int->loginUI); priv_int->loginUI->animateShow(Wt::WAnimation(Wt::WAnimation::AnimationEffect::SlideInFromTop)); priv_int->loginUI->checkSessionValidity(); + notificationSlot.setJavaScript(getNotificationJs("")); } WebInterface::~WebInterface() @@ -79,7 +80,9 @@ void WebInterface::songChangedFromServer(AudioTrack nextTrack) void WebInterface::skipVotedFromServer(User userRequestingToSkipCurrentTrack) { priv_int->playerUI->updateSkipRequestedFromServer(); - //TODO: show notification + //show notification + notificationSlot.setJavaScript(getNotificationJs(userRequestingToSkipCurrentTrack.username+" has requested to skip "+GroovePlayerMgr::getInstance()->currentTrack.trackName+".")); + notificationSlot.exec(); triggerUpdate(); } @@ -106,3 +109,8 @@ void WebInterface::voteTracksUpdatedFromServer(std::list voteableTra priv_int->playerUI->updateVoteableTracksFromServer(voteableTracks); triggerUpdate(); } + +std::string WebInterface::getNotificationJs(std::string notificationText) +{ + return std::string("function notifyMe(a,b){var c='")+notificationText+std::string("';if('Notification'in window)if('granted'===Notification.permission){new Notification(c)}else'denied'!==Notification.permission&&Notification.requestPermission(function(a){if('granted'===a){new Notification(c)}});else;}"); +} diff --git a/src/WebInterface.h b/src/WebInterface.h index f492760..dca1285 100644 --- a/src/WebInterface.h +++ b/src/WebInterface.h @@ -24,6 +24,7 @@ #include "GroovePlayer.h" #include "db/AudioTrack.h" #include "db/User.h" +#include class WebInterface : public Wt::WApplication { @@ -42,6 +43,8 @@ public: private: struct internal; internal* priv_int = 0; + std::string getNotificationJs(std::string message); + Wt::JSlot notificationSlot; }; #endif // WEBINTERFACE_H diff --git a/src/ui/PlayerInterface.h b/src/ui/PlayerInterface.h index d2da440..244fc44 100644 --- a/src/ui/PlayerInterface.h +++ b/src/ui/PlayerInterface.h @@ -70,10 +70,6 @@ public: bool isPaused = false; //TODO:put in controls for requesting/admin skip and adding users as admin. - //Vote controls - //TODO:put in vote controls for seeing tracks to vote on and vote buttons. - //TODO:put in controls for requesting songs. - void playpauseClicked(); void playpauseUpdated(); void skipRequestClicked(); -- GitLab