local-notification.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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.hasType(id, 'scheduled', 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.hasType(id, 'triggered', callback, scope);
  153. };
  154. /**
  155. * Get the type (triggered, scheduled) for the notification.
  156. *
  157. * @param [ Int ] id The ID of the notification.
  158. * @param [ Function ] callback The function to be exec as the callback.
  159. * @param [ Object ] scope The callback function's scope.
  160. *
  161. * @return [ Void ]
  162. */
  163. exports.getType = function (id, callback, scope) {
  164. this.core.getType(id, callback, scope);
  165. };
  166. /**
  167. * List of all notification ids.
  168. *
  169. * @param [ Function ] callback The function to be exec as the callback.
  170. * @param [ Object ] scope The callback function's scope.
  171. *
  172. * @return [ Void ]
  173. */
  174. exports.getIds = function (callback, scope) {
  175. this.core.getIds(callback, scope);
  176. };
  177. /**
  178. * List of all scheduled notification IDs.
  179. *
  180. * @param [ Function ] callback The function to be exec as the callback.
  181. * @param [ Object ] scope The callback function's scope.
  182. *
  183. * @return [ Void ]
  184. */
  185. exports.getScheduledIds = function (callback, scope) {
  186. this.core.getScheduledIds(callback, scope);
  187. };
  188. /**
  189. * List of all triggered notification IDs.
  190. *
  191. * @param [ Function ] callback The function to be exec as the callback.
  192. * @param [ Object ] scope The callback function's scope.
  193. *
  194. * @return [ Void ]
  195. */
  196. exports.getTriggeredIds = function (callback, scope) {
  197. this.core.getTriggeredIds(callback, scope);
  198. };
  199. /**
  200. * List of local notifications specified by id.
  201. * If called without IDs, all notification will be returned.
  202. *
  203. * @param [ Array<Int> ] ids The IDs of the notifications.
  204. * @param [ Function ] callback The function to be exec as the callback.
  205. * @param [ Object ] scope The callback function's scope.
  206. *
  207. * @return [ Void ]
  208. */
  209. exports.get = function (ids, callback, scope) {
  210. this.core.get(ids, callback, scope);
  211. };
  212. /**
  213. * List for all notifications.
  214. *
  215. * @param [ Function ] callback The function to be exec as the callback.
  216. * @param [ Object ] scope The callback function's scope.
  217. *
  218. * @return [ Void ]
  219. */
  220. exports.getAll = function (callback, scope) {
  221. this.core.getAll(callback, scope);
  222. };
  223. /**
  224. * List of all scheduled notifications.
  225. *
  226. * @param [ Function ] callback The function to be exec as the callback.
  227. * @param [ Object ] scope The callback function's scope.
  228. */
  229. exports.getScheduled = function (callback, scope) {
  230. this.core.getScheduled(callback, scope);
  231. };
  232. /**
  233. * List of all triggered notifications.
  234. *
  235. * @param [ Function ] callback The function to be exec as the callback.
  236. * @param [ Object ] scope The callback function's scope.
  237. */
  238. exports.getTriggered = function (callback, scope) {
  239. this.core.getTriggered(callback, scope);
  240. };
  241. /**
  242. * Register an group of actions by id.
  243. *
  244. * @param [ String ] id The Id of the group.
  245. * @param [ Array] actions The action config settings.
  246. * @param [ Function ] callback The function to be exec as the callback.
  247. * @param [ Object ] scope The callback function's scope.
  248. *
  249. * @return [ Void ]
  250. */
  251. exports.addActionGroup = function (id, actions, callback, scope) {
  252. this.core.registerActionGroup(id, actions, callback, scope);
  253. };
  254. /**
  255. * The (platform specific) default settings.
  256. *
  257. * @return [ Object ]
  258. */
  259. exports.getDefaults = function () {
  260. return this.core.getDefaults();
  261. };
  262. /**
  263. * Overwrite default settings.
  264. *
  265. * @param [ Object ] newDefaults New default values.
  266. *
  267. * @return [ Void ]
  268. */
  269. exports.setDefaults = function (defaults) {
  270. this.core.setDefaults(defaults);
  271. };
  272. /**
  273. * Register 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. * @param [ Object ] scope The callback function's scope.
  278. *
  279. * @return [ Void ]
  280. */
  281. exports.on = function (event, callback, scope) {
  282. this.core.on(event, callback, scope);
  283. };
  284. /**
  285. * Unregister callback for given event.
  286. *
  287. * @param [ String ] event The name of the event.
  288. * @param [ Function ] callback The function to be exec as callback.
  289. *
  290. * @return [ Void ]
  291. */
  292. exports.un = function (event, callback) {
  293. this.core.un(event, callback);
  294. };