The Battle for Wesnoth  1.19.22+dev
apple_notification.mm
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2025
3  by Google Inc.
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #ifdef __APPLE__
17 
19 
20 #include <TargetConditionals.h>
21 #import <Foundation/Foundation.h>
22 
23 namespace apple_notifications {
24 
25 #if TARGET_OS_OSX
26 
27 bool available() {
28  Class notificationClass = NSClassFromString(@"NSUserNotificationCenter");
29  if(notificationClass) {
30  return true;
31  }
32  return false;
33 }
34 
35 void send_cocoa_notification(const std::string& owner, const std::string& message);
36 
37 #pragma clang diagnostic push
38 #pragma clang diagnostic ignored "-Wunused-parameter"
39 void send_notification(const std::string& owner, const std::string& message, const desktop::notifications::type note_type) {
40  @autoreleasepool {
41  Class appleNotificationClass = NSClassFromString(@"NSUserNotificationCenter");
42  if (appleNotificationClass) {
43  send_cocoa_notification(owner, message);
44  }
45  }
46 }
47 #pragma clang diagnostic pop
48 
49 void send_cocoa_notification(const std::string& owner, const std::string& message) {
50  NSString *title = [NSString stringWithCString:owner.c_str() encoding:NSUTF8StringEncoding];
51  NSString *description = [NSString stringWithCString:message.c_str() encoding:NSUTF8StringEncoding];
52  NSUserNotification *notification = [[NSUserNotification alloc] init];
53  notification.title = title;
54  notification.informativeText = description;
55  notification.deliveryDate = [NSDate date];
56 
57  [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:notification];
58 }
59 
60 #else
61 
62 bool available() {
63  return false;
64 }
65 
66 void send_notification(const std::string&, const std::string&, const desktop::notifications::type) {
67 }
68 
69 #endif
70 
71 }
72 #endif //end __APPLE__
void send_notification(const std::string &owner, const std::string &message, const desktop::notifications::type note_type)
@ notification
Callbacks with a sender aka notification messages.
struct utils::detail::formula_initer init