local-notification.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * Apache 2.0 License
  3. *
  4. * Copyright (c) Sebastian Katzer 2017
  5. *
  6. * This file contains Original Code and/or Modifications of Original Code
  7. * as defined in and that are subject to the Apache License
  8. * Version 2.0 (the 'License'). You may not use this file except in
  9. * compliance with the License. Please obtain a copy of the License at
  10. * http://opensource.org/licenses/Apache-2.0/ and read it before using this
  11. * file.
  12. *
  13. * The Original Code and all software distributed under the License are
  14. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  15. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  16. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  18. * Please see the License for the specific language governing rights and
  19. * limitations under the License.
  20. */
  21. /**
  22. * Request permission to show notifications.
  23. *
  24. * @param [ Function ] callback The function to be exec as the callback.
  25. * @param [ Object ] scope The callback function's scope.
  26. *
  27. * @return [ Void ]
  28. */
  29. exports.hasPermission = function (callback, scope) {
  30. this.core.hasPermission(callback, scope);
  31. };
  32. /**
  33. * Request permission to show notifications.
  34. *
  35. * @param [ Function ] callback The function to be exec as the callback.
  36. * @param [ Object ] scope The callback function's scope.
  37. *
  38. * @return [ Void ]
  39. */
  40. exports.requestPermission = function (callback, scope) {
  41. this.core.requestPermission(callback, scope);
  42. };
  43. /**
  44. * Schedule notifications.
  45. *
  46. * @param [ Array ] notifications The notifications to schedule.
  47. * @param [ Function ] callback The function to be exec as the callback.
  48. * @param [ Object ] scope The callback function's scope.
  49. * @param [ Object ] args Optional flags how to schedule.
  50. *
  51. * @return [ Void ]
  52. */
  53. exports.schedule = function (notifications, callback, scope, args) {
  54. this.core.schedule(notifications, callback, scope, args);
  55. };
  56. /**
  57. * Update notifications.
  58. *
  59. * @param [ Array ] notifications The notifications to schedule.
  60. * @param [ Function ] callback The function to be exec as the callback.
  61. * @param [ Object ] scope The callback function's scope.
  62. * @param [ Object ] args Optional flags how to schedule.
  63. *
  64. * @return [ Void ]
  65. */
  66. exports.update = function (notifications, callback, scope, args) {
  67. this.core.update(notifications, callback, scope, args);
  68. };
  69. /**
  70. * Clear the specified notifications by id.
  71. *
  72. * @param [ Array<Int> ] ids The IDs of the notifications.
  73. * @param [ Function ] callback The function to be exec as the callback.
  74. * @param [ Object ] scope The callback function's scope.
  75. *
  76. * @return [ Void ]
  77. */
  78. exports.clear = function (ids, callback, scope) {
  79. this.core.clear(ids, callback, scope);
  80. };
  81. /**
  82. * Clear all triggered notifications.
  83. *
  84. * @param [ Function ] callback The function to be exec as the callback.
  85. * @param [ Object ] scope The callback function's scope.
  86. *
  87. * @return [ Void ]
  88. */
  89. exports.clearAll = function (callback, scope) {
  90. this.core.clearAll(callback, scope);
  91. };
  92. /**
  93. * Cancel the specified notifications by id.
  94. *
  95. * @param [ Array<Int> ] ids The IDs of the notifications.
  96. * @param [ Function ] callback The function to be exec as the callback.
  97. * @param [ Object ] scope The callback function's scope.
  98. *
  99. * @return [ Void ]
  100. */
  101. exports.cancel = function (ids, callback, scope) {
  102. this.core.cancel(ids, callback, scope);
  103. };
  104. /**
  105. * Cancel all scheduled notifications.
  106. *
  107. * @param [ Function ] callback The function to be exec as the callback.
  108. * @param [ Object ] scope The callback function's scope.
  109. *
  110. * @return [ Void ]
  111. */
  112. exports.cancelAll = function (callback, scope) {
  113. this.core.cancelAll(callback, scope);
  114. };
  115. /**
  116. * Check if a notification is present.
  117. *
  118. * @param [ Int ] id The ID of the notification.
  119. * @param [ Function ] callback The function to be exec as the callback.
  120. * @param [ Object ] scope The callback function's scope.
  121. *
  122. * @return [ Void ]
  123. */
  124. exports.isPresent = function (id, callback, scope) {
  125. this.core.isPresent(id, callback, scope);
  126. };
  127. /**
  128. * Check if a notification is scheduled.
  129. *
  130. * @param [ Int ] id The ID of the notification.
  131. * @param [ Function ] callback The function to be exec as the callback.
  132. * @param [ Object ] scope The callback function's scope.
  133. *
  134. * @return [ Void ]
  135. */
  136. exports.isScheduled = function (id, callback, scope) {
  137. this.core.hasType(id, 'scheduled', callback, scope);
  138. };
  139. /**
  140. * Check if a notification was triggered.
  141. *
  142. * @param [ Int ] id The ID of the notification.
  143. * @param [ Function ] callback The function to be exec as the callback.
  144. * @param [ Object ] scope The callback function's scope.
  145. *
  146. * @return [ Void ]
  147. */
  148. exports.isTriggered = function (id, callback, scope) {
  149. this.core.hasType(id, 'triggered', callback, scope);
  150. };
  151. /**
  152. * Get the type (triggered, scheduled) for the notification.
  153. *
  154. * @param [ Int ] id The ID of the notification.
  155. * @param [ Function ] callback The function to be exec as the callback.
  156. * @param [ Object ] scope The callback function's scope.
  157. *
  158. * @return [ Void ]
  159. */
  160. exports.getType = function (id, callback, scope) {
  161. this.core.getType(id, callback, scope);
  162. };
  163. /**
  164. * List of all notification ids.
  165. *
  166. * @param [ Function ] callback The function to be exec as the callback.
  167. * @param [ Object ] scope The callback function's scope.
  168. *
  169. * @return [ Void ]
  170. */
  171. exports.getIds = function (callback, scope) {
  172. this.core.getIds(callback, scope);
  173. };
  174. /**
  175. * List of all scheduled notification IDs.
  176. *
  177. * @param [ Function ] callback The function to be exec as the callback.
  178. * @param [ Object ] scope The callback function's scope.
  179. *
  180. * @return [ Void ]
  181. */
  182. exports.getScheduledIds = function (callback, scope) {
  183. this.core.getScheduledIds(callback, scope);
  184. };
  185. /**
  186. * List of all triggered notification IDs.
  187. *
  188. * @param [ Function ] callback The function to be exec as the callback.
  189. * @param [ Object ] scope The callback function's scope.
  190. *
  191. * @return [ Void ]
  192. */
  193. exports.getTriggeredIds = function (callback, scope) {
  194. this.core.getTriggeredIds(callback, scope);
  195. };
  196. /**
  197. * List of local notifications specified by id.
  198. * If called without IDs, all notification will be returned.
  199. *
  200. * @param [ Array<Int> ] ids The IDs of the notifications.
  201. * @param [ Function ] callback The function to be exec as the callback.
  202. * @param [ Object ] scope The callback function's scope.
  203. *
  204. * @return [ Void ]
  205. */
  206. exports.get = function (ids, callback, scope) {
  207. this.core.get(ids, callback, scope);
  208. };
  209. /**
  210. * List for all notifications.
  211. *
  212. * @param [ Function ] callback The function to be exec as the callback.
  213. * @param [ Object ] scope The callback function's scope.
  214. *
  215. * @return [ Void ]
  216. */
  217. exports.getAll = function (callback, scope) {
  218. this.core.getAll(callback, scope);
  219. };
  220. /**
  221. * List of all scheduled notifications.
  222. *
  223. * @param [ Function ] callback The function to be exec as the callback.
  224. * @param [ Object ] scope The callback function's scope.
  225. */
  226. exports.getScheduled = function (callback, scope) {
  227. this.core.getScheduled(callback, scope);
  228. };
  229. /**
  230. * List of all triggered notifications.
  231. *
  232. * @param [ Function ] callback The function to be exec as the callback.
  233. * @param [ Object ] scope The callback function's scope.
  234. */
  235. exports.getTriggered = function (callback, scope) {
  236. this.core.getTriggered(callback, scope);
  237. };
  238. /**
  239. * Register an group of actions by id.
  240. *
  241. * @param [ String ] id The Id of the group.
  242. * @param [ Array] actions The action config settings.
  243. * @param [ Function ] callback The function to be exec as the callback.
  244. * @param [ Object ] scope The callback function's scope.
  245. *
  246. * @return [ Void ]
  247. */
  248. exports.addActionGroup = function (id, actions, callback, scope) {
  249. this.core.addActionGroup(id, actions, callback, scope);
  250. };
  251. /**
  252. * The (platform specific) default settings.
  253. *
  254. * @return [ Object ]
  255. */
  256. exports.getDefaults = function () {
  257. return this.core.getDefaults();
  258. };
  259. /**
  260. * Overwrite default settings.
  261. *
  262. * @param [ Object ] newDefaults New default values.
  263. *
  264. * @return [ Void ]
  265. */
  266. exports.setDefaults = function (defaults) {
  267. this.core.setDefaults(defaults);
  268. };
  269. /**
  270. * Register callback for given event.
  271. *
  272. * @param [ String ] event The name of the event.
  273. * @param [ Function ] callback The function to be exec as callback.
  274. * @param [ Object ] scope The callback function's scope.
  275. *
  276. * @return [ Void ]
  277. */
  278. exports.on = function (event, callback, scope) {
  279. this.core.on(event, callback, scope);
  280. };
  281. /**
  282. * Unregister callback for given event.
  283. *
  284. * @param [ String ] event The name of the event.
  285. * @param [ Function ] callback The function to be exec as callback.
  286. *
  287. * @return [ Void ]
  288. */
  289. exports.un = function (event, callback) {
  290. this.core.un(event, callback);
  291. };