Notification module support (#8)

This commit is contained in:
Jemma Poffinbarger 2023-03-23 12:57:15 +11:00 committed by Ash Logan
commit c560ca00d5
7 changed files with 67 additions and 5 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
.idea/
/build
*.elf
*.wps

View file

@ -1,8 +1,9 @@
FROM wiiuenv/devkitppc:20220806
FROM wiiuenv/devkitppc:20221228
COPY --from=wiiuenv/libnotifications:20230126 /artifacts $DEVKITPRO
COPY --from=wiiuenv/libkernel:20220724 /artifacts $DEVKITPRO
COPY --from=wiiuenv/libmocha:20220903 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiupluginsystem:20220826 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiupluginsystem:20230126 /artifacts $DEVKITPRO
WORKDIR /app
CMD make -f Makefile -j$(nproc)
CMD make -f Makefile -j$(nproc)

Binary file not shown.

View file

@ -40,7 +40,7 @@ LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map)
LDFLAGS += -T$(WUMS_ROOT)/share/libkernel.ld $(WUPSSPECS)
LIBS := -lwups -lmocha -lkernel -lwut
LIBS := -lwups -lmocha -lkernel -lwut -lnotifications
#-------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level

39
src/Notification.cpp Normal file
View file

@ -0,0 +1,39 @@
#include "Notification.h"
#include <coreinit/cache.h>
#include <coreinit/thread.h>
#include <coreinit/title.h>
#include <notifications/notification_defines.h>
#include <notifications/notifications.h>
#include <thread>
static std::unique_ptr<std::thread> sShowHintThread;
static bool sShutdownHintThread = false;
void ShowNotification(const char * notification) {
// Wait for notification module to be ready
bool isOverlayReady = false;
while (!sShutdownHintThread && NotificationModule_IsOverlayReady(&isOverlayReady) == NOTIFICATION_MODULE_RESULT_SUCCESS && !isOverlayReady)
OSSleepTicks(OSMillisecondsToTicks(16));
if (sShutdownHintThread || !isOverlayReady) return;
NotificationModuleStatus err = NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, 15.0f);
if(err != NOTIFICATION_MODULE_RESULT_SUCCESS) return;
NotificationModule_AddInfoNotification(notification);
}
void StartNotificationThread(const char * value) {
uint64_t titleID = OSGetTitleID();
if (titleID == 0x0005001010040000L || titleID == 0x0005001010040100L || titleID == 0x0005001010040200L) {
sShutdownHintThread = false;
sShowHintThread = std::make_unique<std::thread>(ShowNotification, value);
}
}
void StopNotificationThread() {
if (sShowHintThread != nullptr) {
sShutdownHintThread = true;
OSMemoryBarrier();
sShowHintThread->join();
sShowHintThread.reset();
}
}

7
src/Notification.h Normal file
View file

@ -0,0 +1,7 @@
#pragma once
void ShowNotification(const char * notification);
void StartNotificationThread(const char * value);
void StopNotificationThread();

View file

@ -23,10 +23,13 @@
#include <coreinit/memory.h>
#include <coreinit/memorymap.h>
#include <coreinit/memexpheap.h>
#include <notifications/notifications.h>
#include "wut_extra.h"
#include <utils/logger.h>
#include "url_patches.h"
#include "config.h"
#include "Notification.h"
/**
Mandatory plugin information.
@ -95,6 +98,10 @@ INITIALIZE_PLUGIN() {
return;
}
if (NotificationModule_InitLibrary() != NOTIFICATION_MODULE_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE("NotificationModule_InitLibrary failed");
}
//get os version
MCP_SystemVersion os_version;
int mcp = MCP_Open();
@ -120,11 +127,12 @@ INITIALIZE_PLUGIN() {
for (const auto& patch : url_patches) {
write_string(patch.address, patch.url);
}
DEBUG_FUNCTION_LINE("Pretendo URL and NoSSL patches applied successfully.");
StartNotificationThread("Using Pretendo Network");
}
else {
DEBUG_FUNCTION_LINE("Pretendo URL and NoSSL patches skipped.");
StartNotificationThread("Using Nintendo Network");
}
@ -133,6 +141,7 @@ INITIALIZE_PLUGIN() {
DEINITIALIZE_PLUGIN() {
WHBLogUdpDeinit();
Mocha_DeInitLibrary();
NotificationModule_DeInitLibrary();
}
bool check_olv_libs() {
@ -213,3 +222,8 @@ ON_APPLICATION_START() {
replace(base_addr, size, original_url, sizeof(original_url), new_url, sizeof(new_url));
}
ON_APPLICATION_ENDS() {
DEBUG_FUNCTION_LINE("Inkay: shutting down...\n");
StopNotificationThread();
}