forked from PretendoNetwork/Inkay
Notification module support (#8)
This commit is contained in:
parent
21e9c71757
commit
c560ca00d5
7 changed files with 67 additions and 5 deletions
39
src/Notification.cpp
Normal file
39
src/Notification.cpp
Normal 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
7
src/Notification.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
void ShowNotification(const char * notification);
|
||||
|
||||
void StartNotificationThread(const char * value);
|
||||
|
||||
void StopNotificationThread();
|
||||
16
src/main.cpp
16
src/main.cpp
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue