local-notification.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 existing notifications specified by IDs in options.
  58. // *
  59. // * @param {Object} notifications
  60. // * The notification properties to update
  61. // * @param {Function} callback
  62. // * A function to be called after the notification has been updated
  63. // * @param {Object?} scope
  64. // * The scope for the callback function
  65. // * @param {Object?} args
  66. // * skipPermission:true schedules the notifications immediatly without
  67. // * registering or checking for permission
  68. // */
  69. // exports.update = function (notifications, callback, scope, args) {
  70. // this.core.update(notifications, callback, scope, args);
  71. // };
  72. /**
  73. * Clear the specified notifications by id.
  74. *
  75. * @param [ Array<Int> ] ids The IDs of the notifications.
  76. * @param [ Function ] callback The function to be exec as the callback.
  77. * @param [ Object ] scope The callback function's scope.
  78. *
  79. * @return [ Void ]
  80. */
  81. exports.clear = function (ids, callback, scope) {
  82. this.core.clear(ids, callback, scope);
  83. };
  84. /**
  85. * Clear all triggered notifications.
  86. *
  87. * @param [ Function ] callback The function to be exec as the callback.
  88. * @param [ Object ] scope The callback function's scope.
  89. *
  90. * @return [ Void ]
  91. */
  92. exports.clearAll = function (callback, scope) {
  93. this.core.clearAll(callback, scope);
  94. };
  95. /**
  96. * Cancel the specified notifications by id.
  97. *
  98. * @param [ Array<Int> ] ids The IDs of the notifications.
  99. * @param [ Function ] callback The function to be exec as the callback.
  100. * @param [ Object ] scope The callback function's scope.
  101. *
  102. * @return [ Void ]
  103. */
  104. exports.cancel = function (ids, callback, scope) {
  105. this.core.cancel(ids, callback, scope);
  106. };
  107. /**
  108. * Cancel all scheduled notifications.
  109. *
  110. * @param [ Function ] callback The function to be exec as the callback.
  111. * @param [ Object ] scope The callback function's scope.
  112. *
  113. * @return [ Void ]
  114. */
  115. exports.cancelAll = function (callback, scope) {
  116. this.core.cancelAll(callback, scope);
  117. };
  118. /**
  119. * Check if a notification is present.
  120. *
  121. * @param [ Int ] id The ID of the notification.
  122. * @param [ Function ] callback The function to be exec as the callback.
  123. * @param [ Object ] scope The callback function's scope.
  124. *
  125. * @return [ Void ]
  126. */
  127. exports.isPresent = function (id, callback, scope) {
  128. this.core.isPresent(id, callback, scope);
  129. };
  130. /**
  131. * Check if a notification is scheduled.
  132. *
  133. * @param [ Int ] id The ID of the notification.
  134. * @param [ Function ] callback The function to be exec as the callback.
  135. * @param [ Object ] scope The callback function's scope.
  136. *
  137. * @return [ Void ]
  138. */
  139. exports.isScheduled = function (id, callback, scope) {
  140. this.core.isScheduled(id, callback, scope);
  141. };
  142. /**
  143. * Check if a notification was triggered.
  144. *
  145. * @param [ Int ] id The ID of the notification.
  146. * @param [ Function ] callback The function to be exec as the callback.
  147. * @param [ Object ] scope The callback function's scope.
  148. *
  149. * @return [ Void ]
  150. */
  151. exports.isTriggered = function (id, callback, scope) {
  152. this.core.isTriggered(id, callback, scope);
  153. };
  154. /**
  155. * List of all notification ids.
  156. *
  157. * @param [ Function ] callback The function to be exec as the callback.
  158. * @param [ Object ] scope The callback function's scope.
  159. *
  160. * @return [ Void ]
  161. */
  162. exports.getIds = function (callback, scope) {
  163. this.core.getIds(callback, scope);
  164. };
  165. /**
  166. * List of all scheduled notification IDs.
  167. *
  168. * @param [ Function ] callback The function to be exec as the callback.
  169. * @param [ Object ] scope The callback function's scope.
  170. *
  171. * @return [ Void ]
  172. */
  173. exports.getScheduledIds = function (callback, scope) {
  174. this.core.getScheduledIds(callback, scope);
  175. };
  176. /**
  177. * List of all triggered notification IDs.
  178. *
  179. * @param [ Function ] callback The function to be exec as the callback.
  180. * @param [ Object ] scope The callback function's scope.
  181. *
  182. * @return [ Void ]
  183. */
  184. exports.getTriggeredIds = function (callback, scope) {
  185. this.core.getTriggeredIds(callback, scope);
  186. };
  187. /**
  188. * List of local notifications specified by id.
  189. * If called without IDs, all notification will be returned.
  190. *
  191. * @param [ Array<Int> ] ids The IDs of the notifications.
  192. * @param [ Function ] callback The function to be exec as the callback.
  193. * @param [ Object ] scope The callback function's scope.
  194. *
  195. * @return [ Void ]
  196. */
  197. exports.get = function (ids, callback, scope) {
  198. this.core.get(ids, callback, scope);
  199. };
  200. /**
  201. * List for all notifications.
  202. *
  203. * @param [ Function ] callback The function to be exec as the callback.
  204. * @param [ Object ] scope The callback function's scope.
  205. *
  206. * @return [ Void ]
  207. */
  208. exports.getAll = function (callback, scope) {
  209. this.core.getAll(callback, scope);
  210. };
  211. /**
  212. * List of all scheduled notifications.
  213. *
  214. * @param [ Function ] callback The function to be exec as the callback.
  215. * @param [ Object ] scope The callback function's scope.
  216. */
  217. exports.getScheduled = function (callback, scope) {
  218. this.core.getScheduled(callback, scope);
  219. };
  220. /**
  221. * List of all triggered 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.getTriggered = function (callback, scope) {
  227. this.core.getTriggered(callback, scope);
  228. };
  229. /**
  230. * Register an group of actions by id.
  231. *
  232. * @param [ String ] id The Id of the group.
  233. * @param [ Array] actions The action config settings.
  234. * @param [ Function ] callback The function to be exec as the callback.
  235. * @param [ Object ] scope The callback function's scope.
  236. *
  237. * @return [ Void ]
  238. */
  239. exports.addActionGroup = function (id, actions, callback, scope) {
  240. this.core.registerActionGroup(id, actions, callback, scope);
  241. };
  242. /**
  243. * The (platform specific) default settings.
  244. *
  245. * @return [ Object ]
  246. */
  247. exports.getDefaults = function () {
  248. return this.core.getDefaults();
  249. };
  250. /**
  251. * Overwrite default settings.
  252. *
  253. * @param [ Object ] newDefaults New default values.
  254. *
  255. * @return [ Void ]
  256. */
  257. exports.setDefaults = function (defaults) {
  258. this.core.setDefaults(defaults);
  259. };
  260. /**
  261. * Register callback for given event.
  262. *
  263. * @param [ String ] event The name of the event.
  264. * @param [ Function ] callback The function to be exec as callback.
  265. * @param [ Object ] scope The callback function's scope.
  266. *
  267. * @return [ Void ]
  268. */
  269. exports.on = function (event, callback, scope) {
  270. this.core.on(event, callback, scope);
  271. };
  272. /**
  273. * Unregister callback for given event.
  274. *
  275. * @param [ String ] event The name of the event.
  276. * @param [ Function ] callback The function to be exec as callback.
  277. *
  278. * @return [ Void ]
  279. */
  280. exports.un = function (event, callback) {
  281. this.core.un(event, callback);
  282. };