malamar/src/Notification.cpp
Ash Logan 24596b1bff chore: Fix license headers to GPLv3
Inkay's been GPLv3 for a while and it's fine to relicense old ISC code to GPL
2024-04-09 23:31:43 +10:00

55 lines
2.2 KiB
C++

/* Copyright 2024 Pretendo Network contributors <pretendo.network>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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();
}
}