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
6.8KB

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