|
| 1 | +package org.scalajs.dom.experimental |
| 2 | + |
| 3 | +import org.scalajs.dom.raw.EventTarget |
| 4 | +import scala.scalajs.js |
| 5 | +import scala.scalajs.js.annotation.JSName |
| 6 | + |
| 7 | +trait NotificationOptions extends js.Object { |
| 8 | + /** |
| 9 | + * The body property of the Notification interface indicates the |
| 10 | + * body string of the notification. |
| 11 | + * |
| 12 | + * MDN |
| 13 | + */ |
| 14 | + val body: String = js.native |
| 15 | + |
| 16 | + /** |
| 17 | + * The dir property of the Notification interface indicates the |
| 18 | + * text direction of the notification. |
| 19 | + * |
| 20 | + * MDN |
| 21 | + */ |
| 22 | + val dir: String = js.native |
| 23 | + |
| 24 | + /** |
| 25 | + * The icon property of the Notification interface contains the |
| 26 | + * URL of an icon to be displayed as part of the notification. |
| 27 | + * |
| 28 | + * MDN |
| 29 | + */ |
| 30 | + val icon: String = js.native |
| 31 | + |
| 32 | + /** |
| 33 | + * The lang property of the Notification interface indicates the |
| 34 | + * text direction of the notification. |
| 35 | + * |
| 36 | + * MDN |
| 37 | + */ |
| 38 | + val lang: String = js.native |
| 39 | + |
| 40 | + /** |
| 41 | + * The noscreen property of the Notification interface specifies |
| 42 | + * whether the notification firing should enable the device's screen or not. |
| 43 | + * |
| 44 | + * MDN |
| 45 | + */ |
| 46 | + val noscreen: Boolean = js.native |
| 47 | + |
| 48 | + /** |
| 49 | + * The renotify property of the Notification interface specifies |
| 50 | + * whether the user should be notified after a new notification replaces an |
| 51 | + * old one. |
| 52 | + * |
| 53 | + * MDN |
| 54 | + */ |
| 55 | + val renotify: Boolean = js.native |
| 56 | + |
| 57 | + /** |
| 58 | + * The silent property of the Notification interface specifies |
| 59 | + * whether the notification should be silent, i.e. no sounds or vibrations |
| 60 | + * should be issued, regardless of the device settings. |
| 61 | + * |
| 62 | + * MDN |
| 63 | + */ |
| 64 | + val silent: Boolean = js.native |
| 65 | + |
| 66 | + /** |
| 67 | + * The sound property of the Notification interface specifies the |
| 68 | + * URL of an audio file to be played when the notification fires. |
| 69 | + * |
| 70 | + * MDN |
| 71 | + */ |
| 72 | + val sound: String = js.native |
| 73 | + |
| 74 | + /** |
| 75 | + * The sticky property of the Notification interface specifies |
| 76 | + * whether the notification should be 'sticky', i.e. not easily clearable |
| 77 | + * by the user. |
| 78 | + * |
| 79 | + * MDN |
| 80 | + */ |
| 81 | + val sticky: Boolean = js.native |
| 82 | + |
| 83 | + /** |
| 84 | + * The tag property of the Notification interface signifies an |
| 85 | + * identifying tag for the notification. |
| 86 | + * |
| 87 | + * The idea of notification tags is that more than one notification can |
| 88 | + * share the same tag, linking them together. One notification can then |
| 89 | + * be programmatically replaced with another to avoid the users' screen |
| 90 | + * being filled up with a huge number of similar notifications. |
| 91 | + * |
| 92 | + * MDN |
| 93 | + */ |
| 94 | + val tag: String = js.native |
| 95 | + |
| 96 | + /** |
| 97 | + * The onclick property of the Notification interface specifies an event |
| 98 | + * listener to receive click events. These events occur when the user |
| 99 | + * clicks on a displayed Notification. |
| 100 | + * |
| 101 | + * MDN |
| 102 | + */ |
| 103 | + val onclick: js.Function0[Any] = js.native |
| 104 | + |
| 105 | + /** |
| 106 | + * The onerror property of the Notification interface specifies an event |
| 107 | + * listener to receive error events. These events occur when something goes |
| 108 | + * wrong with a Notification (in many cases an error preventing the |
| 109 | + * notification from being displayed.) |
| 110 | + * |
| 111 | + * MDN |
| 112 | + */ |
| 113 | + val onerror: js.Function0[Any] = js.native |
| 114 | + |
| 115 | + val vibrate: js.Array[Double] = js.native |
| 116 | +} |
| 117 | + |
| 118 | +object NotificationOptions { |
| 119 | + /** |
| 120 | + * Construct a new NotificationOptions |
| 121 | + * |
| 122 | + * @param body The body text of the notification. |
| 123 | + * @param dir The text direction of the notification. |
| 124 | + * @param icon The icon URL of the notification. |
| 125 | + * @param lang The text direction of the notification. |
| 126 | + * @param noscreen Boolean indicating if notification firing should enable |
| 127 | + * the device's screen or not |
| 128 | + * @param renotify Boolean indicating whether the user should be notified |
| 129 | + * after a new notification replaces an old one. |
| 130 | + * @param silent Boolean indicating specifies whether the notification |
| 131 | + * should be silent, i.e. no sounds or vibrations should |
| 132 | + * be issued, regardless of the device settings |
| 133 | + * @param sound The URL of an audio file to be played when the |
| 134 | + * notification fires. |
| 135 | + * @param sticky Boolean indicating whether the notification should be |
| 136 | + * 'sticky', i.e. not easily clearable by the user. |
| 137 | + * @param tag A text identifying tag for the notification. |
| 138 | + * @param vibrate The vibration pattern for hardware to emit |
| 139 | + * @return a new NotificationOptions |
| 140 | + */ |
| 141 | + @inline |
| 142 | + def apply( |
| 143 | + body: js.UndefOr[String] = js.undefined, |
| 144 | + dir: js.UndefOr[String] = js.undefined, |
| 145 | + icon: js.UndefOr[String] = js.undefined, |
| 146 | + lang: js.UndefOr[String] = js.undefined, |
| 147 | + noscreen: js.UndefOr[Boolean] = js.undefined, |
| 148 | + renotify: js.UndefOr[Boolean] = js.undefined, |
| 149 | + silent: js.UndefOr[Boolean] = js.undefined, |
| 150 | + sound: js.UndefOr[String] = js.undefined, |
| 151 | + sticky: js.UndefOr[Boolean] = js.undefined, |
| 152 | + tag: js.UndefOr[String] = js.undefined, |
| 153 | + onclick: js.UndefOr[js.Function0[Any]] = js.undefined, |
| 154 | + onerror: js.UndefOr[js.Function0[Any]] = js.undefined, |
| 155 | + vibrate: js.UndefOr[js.Array[Double]] = js.undefined): NotificationOptions = { |
| 156 | + val result = js.Dynamic.literal() |
| 157 | + body.foreach(result.body = _) |
| 158 | + dir.foreach(result.dir = _) |
| 159 | + icon.foreach(result.icon = _) |
| 160 | + lang.foreach(result.lang = _) |
| 161 | + noscreen.foreach(result.noscreen = _) |
| 162 | + renotify.foreach(result.renotify = _) |
| 163 | + silent.foreach(result.silent = _) |
| 164 | + sound.foreach(result.sound = _) |
| 165 | + sticky.foreach(result.sticky = _) |
| 166 | + tag.foreach(result.tag = _) |
| 167 | + onclick.foreach(result.onclick = _) |
| 168 | + onerror.foreach(result.onerror = _) |
| 169 | + vibrate.foreach(result.vibrate = _) |
| 170 | + result.asInstanceOf[NotificationOptions] |
| 171 | + } |
| 172 | +} |
| 173 | + |
| 174 | +/** |
| 175 | + * Implicit imports for the notification api. |
| 176 | + * |
| 177 | + * https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API |
| 178 | + */ |
| 179 | +object Notification extends js.Object { |
| 180 | + /** |
| 181 | + * The permission read-only property of the Notification interface |
| 182 | + * indicates the current permission granted by the user for the current |
| 183 | + * origin to display web notifications. |
| 184 | + * |
| 185 | + * MDN |
| 186 | + */ |
| 187 | + val permission: String = js.native |
| 188 | + |
| 189 | + /** |
| 190 | + * The requestPermission() method of the Notification interface requests |
| 191 | + * permission from the user for the current origin to display |
| 192 | + * notifications. |
| 193 | + * |
| 194 | + * MDN |
| 195 | + */ |
| 196 | + def requestPermission(callback: js.Function1[String, Any]): Unit = js.native |
| 197 | +} |
| 198 | + |
| 199 | +/** |
| 200 | + * The Notification interface allows to notify users of an incoming message |
| 201 | + * or event. |
| 202 | + * |
| 203 | + * NOTE: requires permission |
| 204 | + * Note: This feature is available in Web Workers. |
| 205 | + * |
| 206 | + * MDN |
| 207 | + * |
| 208 | + * @param title The text title of the notification |
| 209 | + * @param options The options to configure this notification |
| 210 | + * @return a new Notification |
| 211 | + */ |
| 212 | +@JSName("Notification.Notification") |
| 213 | +class Notification( |
| 214 | + title: String, |
| 215 | + options: NotificationOptions = ???) extends EventTarget { |
| 216 | + |
| 217 | + /** |
| 218 | + * The body read-only property of the Notification interface indicates the |
| 219 | + * body string of the notification, as specified in the body option of the |
| 220 | + * Notification() constructor. |
| 221 | + * |
| 222 | + * MDN |
| 223 | + */ |
| 224 | + val body: String = js.native |
| 225 | + |
| 226 | + /** |
| 227 | + * The data read-only property of the Notification interface returns a |
| 228 | + * structured clone of the notification's data, as specified in the |
| 229 | + * data option of the Notification() constructor. |
| 230 | + * |
| 231 | + * The notification's data can be any arbitrary data that you want |
| 232 | + * associated with the notification. |
| 233 | + * |
| 234 | + * MDN |
| 235 | + */ |
| 236 | + val data: js.Object = js.native |
| 237 | + |
| 238 | + /** |
| 239 | + * The dir read-only property of the Notification interface indicates the |
| 240 | + * text direction of the notification, asspecified in the dir option of |
| 241 | + * the Notification() constructor. |
| 242 | + * |
| 243 | + * MDN |
| 244 | + */ |
| 245 | + val dir: String = js.native |
| 246 | + |
| 247 | + /** |
| 248 | + * The icon read-only property of the Notification interface contains the |
| 249 | + * URL of an icon to be displayed as part of the notification, as specified |
| 250 | + * in the icon option of the Notification() constructor. |
| 251 | + * |
| 252 | + * MDN |
| 253 | + */ |
| 254 | + val icon: String = js.native |
| 255 | + |
| 256 | + /** |
| 257 | + * The lang read-only property of the Notification interface indicates the |
| 258 | + * text direction of the notification, as specified in the lang option of |
| 259 | + * the Notification() constructor. |
| 260 | + * |
| 261 | + * MDN |
| 262 | + */ |
| 263 | + val lang: String = js.native |
| 264 | + |
| 265 | + /** |
| 266 | + * The noscreen read-only property of the Notification interface specifies |
| 267 | + * whether the notification firing should enable the device's screen or not, |
| 268 | + * as specified in the noscreen option of the Notification() constructor. |
| 269 | + * |
| 270 | + * MDN |
| 271 | + */ |
| 272 | + val noscreen: Boolean = js.native |
| 273 | + |
| 274 | + /** |
| 275 | + * The onclick property of the Notification interface specifies an event |
| 276 | + * listener to receive click events. These events occur when the user |
| 277 | + * clicks on a displayed Notification. |
| 278 | + * |
| 279 | + * MDN |
| 280 | + */ |
| 281 | + var onclick: js.Function0[Any] = js.native |
| 282 | + |
| 283 | + /** |
| 284 | + * The onerror property of the Notification interface specifies an event |
| 285 | + * listener to receive error events. These events occur when something goes |
| 286 | + * wrong with a Notification (in many cases an error preventing the |
| 287 | + * notification from being displayed.) |
| 288 | + * |
| 289 | + * MDN |
| 290 | + */ |
| 291 | + var onerror: js.Function0[Any] = js.native |
| 292 | + |
| 293 | + /** |
| 294 | + * The renotify read-only property of the Notification interface specifies |
| 295 | + * whether the user should be notified after a new notification replaces an |
| 296 | + * old one, as specified in the renotify option of the Notification() |
| 297 | + * constructor. |
| 298 | + * |
| 299 | + * MDN |
| 300 | + */ |
| 301 | + val renotify: Boolean = js.native |
| 302 | + |
| 303 | + /** |
| 304 | + * The silent read-only property of the Notification interface specifies |
| 305 | + * whether the notification should be silent, i.e. no sounds or vibrations |
| 306 | + * should be issued, regardless of the device settings. This is specified |
| 307 | + * in the renotify option of the Notification() constructor. |
| 308 | + * |
| 309 | + * MDN |
| 310 | + */ |
| 311 | + val silent: Boolean = js.native |
| 312 | + |
| 313 | + /** |
| 314 | + * The sound read-only property of the Notification interface specifies the |
| 315 | + * URL of an audio file to be played when the notification fires. This is |
| 316 | + * specified in the sound option of the Notification() constructor. |
| 317 | + * |
| 318 | + * MDN |
| 319 | + */ |
| 320 | + val sound: String = js.native |
| 321 | + |
| 322 | + /** |
| 323 | + * The sticky read-only property of the Notification interface specifies |
| 324 | + * whether the notification should be 'sticky', i.e. not easily clearable |
| 325 | + * by the user. This is specified in the sticky option of the |
| 326 | + * Notification() constructor. |
| 327 | + * |
| 328 | + * MDN |
| 329 | + */ |
| 330 | + val sticky: Boolean = js.native |
| 331 | + |
| 332 | + /** |
| 333 | + * The tag read-only property of the Notification interface signifies an |
| 334 | + * identifying tag for the notification, as specified in the tag option |
| 335 | + * of the Notification() constructor. |
| 336 | + * |
| 337 | + * The idea of notification tags is that more than one notification can |
| 338 | + * share the same tag, linking them together. One notification can then |
| 339 | + * be programmatically replaced with another to avoid the users' screen |
| 340 | + * being filled up with a huge number of similar notifications. |
| 341 | + * |
| 342 | + * MDN |
| 343 | + */ |
| 344 | + val tag: String = js.native |
| 345 | + |
| 346 | + /** |
| 347 | + * The vibrate read-only property of the Notification interface. |
| 348 | + * Specifies a vibration pattern for devices with vibration hardware |
| 349 | + * to emit. |
| 350 | + * |
| 351 | + * MDN |
| 352 | + */ |
| 353 | + val vibrate: js.Array[Double] = js.native |
| 354 | + |
| 355 | + /** |
| 356 | + * The close() method of the Notification interface is used to close a |
| 357 | + * previously displayed notification. |
| 358 | + * |
| 359 | + * MDN |
| 360 | + */ |
| 361 | + def close(): Unit = js.native |
| 362 | +} |
0 commit comments