The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
8.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. #if ! JUCE_ANDROID && ! JUCE_IOS && ! JUCE_MAC
  22. bool PushNotifications::Notification::isValid() const noexcept { return true; }
  23. #endif
  24. PushNotifications::Notification::Notification (const Notification& other)
  25. : identifier (other.identifier),
  26. title (other.title),
  27. body (other.body),
  28. subtitle (other.subtitle),
  29. groupId (other.groupId),
  30. badgeNumber (other.badgeNumber),
  31. soundToPlay (other.soundToPlay),
  32. properties (other.properties),
  33. category (other.category),
  34. triggerIntervalSec (other.triggerIntervalSec),
  35. repeat (other.repeat),
  36. icon (other.icon),
  37. channelId (other.channelId),
  38. largeIcon (other.largeIcon),
  39. tickerText (other.tickerText),
  40. actions (other.actions),
  41. progress (other.progress),
  42. person (other.person),
  43. type (other.type),
  44. priority (other.priority),
  45. lockScreenAppearance (other.lockScreenAppearance),
  46. publicVersion (other.publicVersion.get() != nullptr ? new Notification (*other.publicVersion) : nullptr),
  47. groupSortKey (other.groupSortKey),
  48. groupSummary (other.groupSummary),
  49. accentColour (other.accentColour),
  50. ledColour (other.ledColour),
  51. ledBlinkPattern (other.ledBlinkPattern),
  52. vibrationPattern (other.vibrationPattern),
  53. shouldAutoCancel (other.shouldAutoCancel),
  54. localOnly (other.localOnly),
  55. ongoing (other.ongoing),
  56. alertOnlyOnce (other.alertOnlyOnce),
  57. timestampVisibility (other.timestampVisibility),
  58. badgeIconType (other.badgeIconType),
  59. groupAlertBehaviour (other.groupAlertBehaviour),
  60. timeoutAfterMs (other.timeoutAfterMs)
  61. {
  62. }
  63. //==============================================================================
  64. JUCE_IMPLEMENT_SINGLETON (PushNotifications)
  65. PushNotifications::PushNotifications()
  66. #if JUCE_PUSH_NOTIFICATIONS
  67. : pimpl (new Pimpl (*this))
  68. #endif
  69. {
  70. }
  71. PushNotifications::~PushNotifications() { clearSingletonInstance(); }
  72. void PushNotifications::addListener (Listener* l) { listeners.add (l); }
  73. void PushNotifications::removeListener (Listener* l) { listeners.remove (l); }
  74. void PushNotifications::requestPermissionsWithSettings ([[maybe_unused]] const PushNotifications::Settings& settings)
  75. {
  76. #if JUCE_PUSH_NOTIFICATIONS && (JUCE_IOS || JUCE_MAC)
  77. pimpl->requestPermissionsWithSettings (settings);
  78. #else
  79. listeners.call ([] (Listener& l) { l.notificationSettingsReceived ({}); });
  80. #endif
  81. }
  82. void PushNotifications::requestSettingsUsed()
  83. {
  84. #if JUCE_PUSH_NOTIFICATIONS && (JUCE_IOS || JUCE_MAC)
  85. pimpl->requestSettingsUsed();
  86. #else
  87. listeners.call ([] (Listener& l) { l.notificationSettingsReceived ({}); });
  88. #endif
  89. }
  90. bool PushNotifications::areNotificationsEnabled() const
  91. {
  92. #if JUCE_PUSH_NOTIFICATIONS
  93. return pimpl->areNotificationsEnabled();
  94. #else
  95. return false;
  96. #endif
  97. }
  98. void PushNotifications::getDeliveredNotifications() const
  99. {
  100. #if JUCE_PUSH_NOTIFICATIONS
  101. pimpl->getDeliveredNotifications();
  102. #endif
  103. }
  104. void PushNotifications::removeAllDeliveredNotifications()
  105. {
  106. #if JUCE_PUSH_NOTIFICATIONS
  107. pimpl->removeAllDeliveredNotifications();
  108. #endif
  109. }
  110. String PushNotifications::getDeviceToken() const
  111. {
  112. #if JUCE_PUSH_NOTIFICATIONS
  113. return pimpl->getDeviceToken();
  114. #else
  115. return {};
  116. #endif
  117. }
  118. void PushNotifications::setupChannels ([[maybe_unused]] const Array<ChannelGroup>& groups, [[maybe_unused]] const Array<Channel>& channels)
  119. {
  120. #if JUCE_PUSH_NOTIFICATIONS
  121. pimpl->setupChannels (groups, channels);
  122. #endif
  123. }
  124. void PushNotifications::getPendingLocalNotifications() const
  125. {
  126. #if JUCE_PUSH_NOTIFICATIONS
  127. pimpl->getPendingLocalNotifications();
  128. #endif
  129. }
  130. void PushNotifications::removeAllPendingLocalNotifications()
  131. {
  132. #if JUCE_PUSH_NOTIFICATIONS
  133. pimpl->removeAllPendingLocalNotifications();
  134. #endif
  135. }
  136. void PushNotifications::subscribeToTopic ([[maybe_unused]] const String& topic)
  137. {
  138. #if JUCE_PUSH_NOTIFICATIONS
  139. pimpl->subscribeToTopic (topic);
  140. #endif
  141. }
  142. void PushNotifications::unsubscribeFromTopic ([[maybe_unused]] const String& topic)
  143. {
  144. #if JUCE_PUSH_NOTIFICATIONS
  145. pimpl->unsubscribeFromTopic (topic);
  146. #endif
  147. }
  148. void PushNotifications::sendLocalNotification ([[maybe_unused]] const Notification& n)
  149. {
  150. #if JUCE_PUSH_NOTIFICATIONS
  151. pimpl->sendLocalNotification (n);
  152. #endif
  153. }
  154. void PushNotifications::removeDeliveredNotification ([[maybe_unused]] const String& identifier)
  155. {
  156. #if JUCE_PUSH_NOTIFICATIONS
  157. pimpl->removeDeliveredNotification (identifier);
  158. #endif
  159. }
  160. void PushNotifications::removePendingLocalNotification ([[maybe_unused]] const String& identifier)
  161. {
  162. #if JUCE_PUSH_NOTIFICATIONS
  163. pimpl->removePendingLocalNotification (identifier);
  164. #endif
  165. }
  166. void PushNotifications::sendUpstreamMessage ([[maybe_unused]] const String& serverSenderId,
  167. [[maybe_unused]] const String& collapseKey,
  168. [[maybe_unused]] const String& messageId,
  169. [[maybe_unused]] const String& messageType,
  170. [[maybe_unused]] int timeToLive,
  171. [[maybe_unused]] const StringPairArray& additionalData)
  172. {
  173. #if JUCE_PUSH_NOTIFICATIONS
  174. pimpl->sendUpstreamMessage (serverSenderId,
  175. collapseKey,
  176. messageId,
  177. messageType,
  178. timeToLive,
  179. additionalData);
  180. #endif
  181. }
  182. //==============================================================================
  183. void PushNotifications::Listener::notificationSettingsReceived ([[maybe_unused]] const Settings& settings) {}
  184. void PushNotifications::Listener::pendingLocalNotificationsListReceived ([[maybe_unused]] const Array<Notification>& notifications) {}
  185. void PushNotifications::Listener::handleNotification ([[maybe_unused]] bool isLocalNotification,
  186. [[maybe_unused]] const Notification& notification) {}
  187. void PushNotifications::Listener::handleNotificationAction ([[maybe_unused]] bool isLocalNotification,
  188. [[maybe_unused]] const Notification& notification,
  189. [[maybe_unused]] const String& actionIdentifier,
  190. [[maybe_unused]] const String& optionalResponse) {}
  191. void PushNotifications::Listener::localNotificationDismissedByUser ([[maybe_unused]] const Notification& notification) {}
  192. void PushNotifications::Listener::deliveredNotificationsListReceived ([[maybe_unused]] const Array<Notification>& notifications) {}
  193. void PushNotifications::Listener::deviceTokenRefreshed ([[maybe_unused]] const String& token) {}
  194. void PushNotifications::Listener::remoteNotificationsDeleted() {}
  195. void PushNotifications::Listener::upstreamMessageSent ([[maybe_unused]] const String& messageId) {}
  196. void PushNotifications::Listener::upstreamMessageSendingError ([[maybe_unused]] const String& messageId,
  197. [[maybe_unused]] const String& error) {}
  198. } // namespace juce