diff --git a/source/NotificationsUtils.cpp b/source/NotificationsUtils.cpp index c7270d0..62a6edd 100644 --- a/source/NotificationsUtils.cpp +++ b/source/NotificationsUtils.cpp @@ -1,61 +1,8 @@ #include "NotificationsUtils.h" #include "globals.h" #include "utils/logger.h" -#include -#include -#include #include #include -#include - -std::unique_ptr sNotificationsThread; -static bool sShutdownNotificationsThread = false; - -OSMessageQueue sNotificationQueue; -OSMessage sNotificationMessages[0x10]; - -#define NOTIFICATION_QUEUE_COMMAND_STOP 0 -#define NOTIFICATION_QUEUE_COMMAND_ERROR 1 - -struct NotificationMessageWrapper { - NotificationModuleNotificationType type = NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO; - char text[512] = {}; - float duration = 10.0f; -}; - -void NotificationMainLoop() { - bool isOverlayReady = false; - while (!sShutdownNotificationsThread && - NotificationModule_IsOverlayReady(&isOverlayReady) == NOTIFICATION_MODULE_RESULT_SUCCESS && !isOverlayReady) { - OSSleepTicks(OSMillisecondsToTicks(16)); - } - if (sShutdownNotificationsThread || !isOverlayReady) { - return; - } - - OSMessage recv; - while (OSReceiveMessage(&sNotificationQueue, &recv, OS_MESSAGE_FLAGS_BLOCKING)) { - if (recv.args[0] == NOTIFICATION_QUEUE_COMMAND_STOP) { - break; - } - - if (recv.args[0] == NOTIFICATION_QUEUE_COMMAND_ERROR) { - auto *param = (NotificationMessageWrapper *) recv.message; - if (param->type == NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO) { - NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, param->duration); - NotificationModule_AddInfoNotification(param->text); - } else if (param->type == NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR) { - NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, param->duration); - NotificationModule_AddErrorNotification(param->text); - } else { - DEBUG_FUNCTION_LINE_WARN("Unsupported notification type: %d", param->type); - } - - free(param); - continue; - } - } -} bool DisplayNotificationMessage(std::string_view text, NotificationModuleNotificationType type, float duration) { if (!gNotificationModuleLoaded) { @@ -64,23 +11,17 @@ bool DisplayNotificationMessage(std::string_view text, NotificationModuleNotific if (type == NOTIFICATION_MODULE_NOTIFICATION_TYPE_DYNAMIC) { return false; } - auto *param = (NotificationMessageWrapper *) malloc(sizeof(NotificationMessageWrapper)); - if (!param) { - return false; - } - strncpy(param->text, text.data(), sizeof(param->text) - 1); - param->type = type; - param->duration = duration; - OSMessage send; - send.message = param; - send.args[0] = NOTIFICATION_QUEUE_COMMAND_ERROR; - auto res = OSSendMessage(&sNotificationQueue, &send, OS_MESSAGE_FLAGS_NONE); - if (!res) { - DEBUG_FUNCTION_LINE_ERR("Failed to add Error Notification: Queue full"); - free(param); - return false; + if (type == NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO) { + NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, duration); + NotificationModule_AddInfoNotification(text.data()); + } else if (type == NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR) { + NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, duration); + NotificationModule_AddErrorNotification(text.data()); + } else { + DEBUG_FUNCTION_LINE_WARN("Unsupported notification type: %d", type); } + return true; } @@ -90,28 +31,4 @@ bool DisplayInfoNotificationMessage(std::string_view text, float duration) { bool DisplayErrorNotificationMessage(std::string_view text, float duration) { return DisplayNotificationMessage(text, NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR, duration); -} - -void StartNotificationThread() { - sNotificationsThread.reset(); - sShutdownNotificationsThread = false; - if (!gNotificationModuleLoaded) { - return; - } - - constexpr int32_t messageSize = sizeof(sNotificationMessages) / sizeof(sNotificationMessages[0]); - OSInitMessageQueue(&sNotificationQueue, sNotificationMessages, messageSize); - sNotificationsThread = make_unique_nothrow(NotificationMainLoop); -} - -void StopNotificationThread() { - if (sNotificationsThread != nullptr) { - OSMessage message; - message.args[0] = NOTIFICATION_QUEUE_COMMAND_STOP; - OSSendMessage(&sNotificationQueue, &message, OS_MESSAGE_FLAGS_NONE); - sShutdownNotificationsThread = true; - OSMemoryBarrier(); - sNotificationsThread->join(); - sNotificationsThread.reset(); - } } \ No newline at end of file diff --git a/source/NotificationsUtils.h b/source/NotificationsUtils.h index 9cec7de..ef77b94 100644 --- a/source/NotificationsUtils.h +++ b/source/NotificationsUtils.h @@ -2,10 +2,6 @@ #include -void StartNotificationThread(); - -void StopNotificationThread(); - bool DisplayInfoNotificationMessage(std::string_view text, float duration); bool DisplayErrorNotificationMessage(std::string_view text, float duration); \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index bec20b3..f590a45 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,4 +1,3 @@ -#include "NotificationsUtils.h" #include "PluginManagement.h" #include "coreinit/interrupts.h" #include "coreinit/scheduler.h" @@ -65,8 +64,6 @@ WUMS_APPLICATION_ENDS() { } gUsedRPLs.clear(); - StopNotificationThread(); - deinitLogging(); } @@ -80,8 +77,6 @@ WUMS_APPLICATION_STARTS() { OSReport("Running WiiUPluginLoaderBackend " VERSION_FULL "\n"); - StartNotificationThread(); - gUsedRPLs.clear(); // If an allocated rpl was not released properly (e.g. if something else calls OSDynload_Acquire without releasing it) memory get leaked.