The Battle for Wesnoth  1.19.6+dev
apple_notification.mm
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
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 #import <Foundation/Foundation.h>
21 
22 namespace apple_notifications {
23 
24 bool available() {
25  Class notificationClass = NSClassFromString(@"NSUserNotificationCenter");
26  if(notificationClass) {
27  return true;
28  }
29  return false;
30 }
31 
32 void send_cocoa_notification(const std::string& owner, const std::string& message);
33 
34 #pragma clang diagnostic push
35 #pragma clang diagnostic ignored "-Wunused-parameter"
36 void send_notification(const std::string& owner, const std::string& message, const desktop::notifications::type note_type) {
37  @autoreleasepool {
38  Class appleNotificationClass = NSClassFromString(@"NSUserNotificationCenter");
39  if (appleNotificationClass) {
40  send_cocoa_notification(owner, message);
41  }
42  }
43 }
44 #pragma clang diagnostic pop
45 
46 void send_cocoa_notification(const std::string& owner, const std::string& message) {
47  NSString *title = [NSString stringWithCString:owner.c_str() encoding:NSUTF8StringEncoding];
48  NSString *description = [NSString stringWithCString:message.c_str() encoding:NSUTF8StringEncoding];
49  NSUserNotification *notification = [[NSUserNotification alloc] init];
50  notification.title = title;
51  notification.informativeText = description;
52  notification.deliveryDate = [NSDate date];
53 
54  [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:notification];
55 }
56 
57 }
58 #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