notification works

This commit is contained in:
2026-06-16 03:37:29 +05:30
parent 9752a76cb2
commit dbc9abae6c
9 changed files with 49 additions and 9 deletions
@@ -153,6 +153,12 @@ bool AdminMenu::handleOperation(int choice)
return true; return true;
} }
void AdminMenu::handleNotificationEvent()
{
auto notifications = m_controller.getNotifications();
displayNewNotification(notifications);
}
/* /*
Function: logout Function: logout
Description: Logs out the currently authenticated admin user. Description: Logs out the currently authenticated admin user.
@@ -15,6 +15,7 @@ class AdminMenu : Menu
{ {
private: private:
bool handleOperation(int choice); bool handleOperation(int choice);
void handleNotificationEvent() override;
public: public:
void showMenu(); void showMenu();
void logout(); void logout();
@@ -124,6 +124,12 @@ bool CustomerMenu::handleOperation(int choice)
return true; return true;
} }
void CustomerMenu::handleNotificationEvent()
{
auto notifications = m_controller.getNotifications();
displayNewNotification(notifications);
}
/* /*
Function: logout Function: logout
Description: Logs out the currently authenticated customer user. Description: Logs out the currently authenticated customer user.
@@ -16,6 +16,7 @@ class CustomerMenu : Menu
{ {
private: private:
bool handleOperation(int choice); bool handleOperation(int choice);
void handleNotificationEvent();
public: public:
void showMenu(); void showMenu();
void logout(); void logout();
@@ -3,7 +3,6 @@
Menu::Menu() Menu::Menu()
: :
m_isMenuActive(false), m_isMenuActive(false),
m_hasNewNotifications(false),
m_accountDisabledEvent(NULL), m_accountDisabledEvent(NULL),
m_notificationAvailableEvent(NULL), m_notificationAvailableEvent(NULL),
m_shutdownEvent(NULL) {} m_shutdownEvent(NULL) {}
@@ -20,7 +19,6 @@ void Menu::startEventListener()
return; return;
} }
m_isMenuActive.store(true); m_isMenuActive.store(true);
m_hasNewNotifications.store(false);
m_accountDisabledEvent = CreateEventA(NULL, FALSE, FALSE, NULL); m_accountDisabledEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
m_notificationAvailableEvent = CreateEventA(NULL, FALSE, FALSE, NULL); m_notificationAvailableEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
m_shutdownEvent = CreateEventA(NULL, FALSE, FALSE, NULL); m_shutdownEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
@@ -43,7 +41,7 @@ void Menu::eventListenerLoop()
handleAccountDisabledEvent(); handleAccountDisabledEvent();
break; break;
case WAIT_OBJECT_0 + 1: case WAIT_OBJECT_0 + 1:
m_hasNewNotifications.store(true); handleNotificationEvent();
break; break;
case WAIT_OBJECT_0 + 2: case WAIT_OBJECT_0 + 2:
return; return;
@@ -82,11 +80,6 @@ void Menu::stopEventListener()
void Menu::handleAccountDisabledEvent() void Menu::handleAccountDisabledEvent()
{ {
m_isMenuActive.store(false); m_isMenuActive.store(false);
/*MessageBoxA(
NULL,
"Your account has been disabled.",
"Account Disabled",
MB_OK | MB_ICONWARNING);*/
MessageBoxA( MessageBoxA(
GetConsoleWindow(), GetConsoleWindow(),
"Your account has been disabled.", "Your account has been disabled.",
@@ -18,7 +18,6 @@ class Menu
protected: protected:
Controller m_controller; Controller m_controller;
std::atomic<bool> m_isMenuActive; std::atomic<bool> m_isMenuActive;
std::atomic<bool> m_hasNewNotifications;
HANDLE m_accountDisabledEvent; HANDLE m_accountDisabledEvent;
HANDLE m_notificationAvailableEvent; HANDLE m_notificationAvailableEvent;
HANDLE m_shutdownEvent; HANDLE m_shutdownEvent;
@@ -27,6 +26,7 @@ protected:
void stopEventListener(); void stopEventListener();
void eventListenerLoop(); void eventListenerLoop();
void handleAccountDisabledEvent(); void handleAccountDisabledEvent();
virtual void handleNotificationEvent() = 0;
public: public:
Menu(); Menu();
virtual ~Menu(); virtual ~Menu();
@@ -1407,4 +1407,30 @@ inline std::string selectComboPackage(util::Map<std::string, const ComboPackage*
std::cout << "Enter a valid choice.\n"; std::cout << "Enter a valid choice.\n";
return ""; return "";
} }
}
inline void displayNewNotification(util::Vector<const Notification*> notifications)
{
const Notification* notification = nullptr;
size_t numberOfNotifications = notifications.getSize();
for (int index = 0; index < numberOfNotifications; index++)
{
if (!notification)
{
notification = notifications[index];
}
else
{
if (notification->getId() < notifications[index]->getId())
{
notification = notifications[index];
}
}
}
MessageBoxA(
GetConsoleWindow(),
notification->getMessage().c_str(),
notification->getTitle().c_str(),
MB_OK |
MB_ICONINFORMATION);
} }
@@ -99,6 +99,12 @@ bool TechnicianMenu::handleOperation(int choice)
return true; return true;
} }
void TechnicianMenu::handleNotificationEvent()
{
auto notifications = m_controller.getNotifications();
displayNewNotification(notifications);
}
/* /*
Function: displayJobs Function: displayJobs
Description: Displays all Jobs assigned to a Technician Description: Displays all Jobs assigned to a Technician
@@ -15,6 +15,7 @@ class TechnicianMenu : Menu
{ {
private: private:
bool handleOperation(int choice); bool handleOperation(int choice);
void handleNotificationEvent();
public: public:
void showMenu(); void showMenu();
void displayJobs(); void displayJobs();