local-notification.js 9.7 KB

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