-
Notifications
You must be signed in to change notification settings - Fork 161
Add the Notification API #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ac779d1
Add the Notification API
coreyauger 613003d
requested fixes
coreyauger e1282b8
remove title from Notification Options
coreyauger 71760f3
revert changes to example
coreyauger df47cbc
style fixes
coreyauger e478f01
revert changes to example
coreyauger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
359 changes: 359 additions & 0 deletions
359
src/main/scala/org/scalajs/dom/experimental/Notification.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,359 @@ | ||
package org.scalajs.dom.experimental | ||
|
||
import org.scalajs.dom.raw.EventTarget | ||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSName | ||
|
||
trait NotificationOptions extends js.Object { | ||
/** | ||
* The body property of the Notification interface indicates the | ||
* body string of the notification. | ||
* | ||
* MDN | ||
*/ | ||
val body: String = js.native | ||
|
||
/** | ||
* The dir property of the Notification interface indicates the | ||
* text direction of the notification. | ||
* | ||
* MDN | ||
*/ | ||
val dir: String = js.native | ||
|
||
/** | ||
* The icon property of the Notification interface contains the | ||
* URL of an icon to be displayed as part of the notification. | ||
* | ||
* MDN | ||
*/ | ||
val icon: String = js.native | ||
|
||
/** | ||
* The lang property of the Notification interface indicates the | ||
* text direction of the notification. | ||
* | ||
* MDN | ||
*/ | ||
val lang: String = js.native | ||
|
||
/** | ||
* The noscreen property of the Notification interface specifies | ||
* whether the notification firing should enable the device's screen or not. | ||
* | ||
* MDN | ||
*/ | ||
val noscreen: Boolean = js.native | ||
|
||
/** | ||
* The renotify property of the Notification interface specifies | ||
* whether the user should be notified after a new notification replaces an | ||
* old one. | ||
* | ||
* MDN | ||
*/ | ||
val renotify: Boolean = js.native | ||
|
||
/** | ||
* The silent property of the Notification interface specifies | ||
* whether the notification should be silent, i.e. no sounds or vibrations | ||
* should be issued, regardless of the device settings. | ||
* | ||
* MDN | ||
*/ | ||
val silent: Boolean = js.native | ||
|
||
/** | ||
* The sound property of the Notification interface specifies the | ||
* URL of an audio file to be played when the notification fires. | ||
* | ||
* MDN | ||
*/ | ||
val sound: String = js.native | ||
|
||
/** | ||
* The sticky property of the Notification interface specifies | ||
* whether the notification should be 'sticky', i.e. not easily clearable | ||
* by the user. | ||
* | ||
* MDN | ||
*/ | ||
val sticky: Boolean = js.native | ||
|
||
/** | ||
* The tag property of the Notification interface signifies an | ||
* identifying tag for the notification. | ||
* | ||
* The idea of notification tags is that more than one notification can | ||
* share the same tag, linking them together. One notification can then | ||
* be programmatically replaced with another to avoid the users' screen | ||
* being filled up with a huge number of similar notifications. | ||
* | ||
* MDN | ||
*/ | ||
val tag: String = js.native | ||
|
||
/** | ||
* The onclick property of the Notification interface specifies an event | ||
* listener to receive click events. These events occur when the user | ||
* clicks on a displayed Notification. | ||
* | ||
* MDN | ||
*/ | ||
var onclick: js.Function0[Any] = js.native | ||
|
||
/** | ||
* The onerror property of the Notification interface specifies an event | ||
* listener to receive error events. These events occur when something goes | ||
* wrong with a Notification (in many cases an error preventing the | ||
* notification from being displayed.) | ||
* | ||
* MDN | ||
*/ | ||
var onerror: js.Function0[Any] = js.native | ||
|
||
val vibrate: js.Array[Double] = js.native | ||
} | ||
|
||
object NotificationOptions { | ||
/** | ||
* Construct a new NotificationOptions | ||
* | ||
* @param body The body text of the notification. | ||
* @param dir The text direction of the notification. | ||
* @param icon The icon URL of the notification. | ||
* @param lang The text direction of the notification. | ||
* @param noscreen Boolean indicating if notification firing should enable | ||
* the device's screen or not | ||
* @param renotify Boolean indicating whether the user should be notified | ||
* after a new notification replaces an old one. | ||
* @param silent Boolean indicating specifies whether the notification | ||
* should be silent, i.e. no sounds or vibrations should | ||
* be issued, regardless of the device settings | ||
* @param sound The URL of an audio file to be played when the | ||
* notification fires. | ||
* @param sticky Boolean indicating whether the notification should be | ||
* 'sticky', i.e. not easily clearable by the user. | ||
* @param tag A text identifying tag for the notification. | ||
* @param vibrate The vibration pattern for hardware to emit | ||
* @return a new NotificationOptions | ||
*/ | ||
@inline | ||
def apply( | ||
body: js.UndefOr[String] = js.undefined, | ||
dir: js.UndefOr[String] = js.undefined, | ||
icon: js.UndefOr[String] = js.undefined, | ||
lang: js.UndefOr[String] = js.undefined, | ||
noscreen: js.UndefOr[Boolean] = js.undefined, | ||
renotify: js.UndefOr[Boolean] = js.undefined, | ||
silent: js.UndefOr[Boolean] = js.undefined, | ||
sound: js.UndefOr[String] = js.undefined, | ||
sticky: js.UndefOr[Boolean] = js.undefined, | ||
tag: js.UndefOr[String] = js.undefined, | ||
onclick: js.UndefOr[js.Function0[Any]] = js.undefined, | ||
onerror: js.UndefOr[js.Function0[Any]] = js.undefined, | ||
vibrate: js.UndefOr[js.Array[Double]] = js.undefined): NotificationOptions = { | ||
val result = js.Dynamic.literal() | ||
body.foreach(result.body = _) | ||
dir.foreach(result.dir = _) | ||
icon.foreach(result.icon = _) | ||
lang.foreach(result.lang = _) | ||
noscreen.foreach(result.noscreen = _) | ||
renotify.foreach(result.renotify = _) | ||
silent.foreach(result.silent = _) | ||
sound.foreach(result.sound = _) | ||
sticky.foreach(result.sticky = _) | ||
tag.foreach(result.tag = _) | ||
onclick.foreach(result.onclick = _) | ||
onerror.foreach(result.onerror = _) | ||
vibrate.foreach(result.vibrate = _) | ||
result.asInstanceOf[NotificationOptions] | ||
} | ||
} | ||
|
||
/** | ||
* Implicit imports for the notification api. | ||
* | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API | ||
*/ | ||
object Notification extends js.Object { | ||
/** | ||
* The permission read-only property of the Notification interface | ||
* indicates the current permission granted by the user for the current | ||
* origin to display web notifications. | ||
* | ||
* MDN | ||
*/ | ||
val permission: String = js.native | ||
|
||
/** | ||
* The requestPermission() method of the Notification interface requests | ||
* permission from the user for the current origin to display | ||
* notifications. | ||
* | ||
* MDN | ||
*/ | ||
def requestPermission(callback: js.Function1[String, Any]): Unit = js.native | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spurious blank line |
||
/** | ||
* The Notification interface allows to notify users of an incoming message | ||
* or event | ||
* NOTE: requires permission | ||
* Note: This feature is available in Web Workers. | ||
* | ||
* @param title The text title of the notification | ||
* @param options The options to configure this notification | ||
* @return a new Notification | ||
* MDN | ||
*/ | ||
@JSName("Notification") | ||
class Notification( title: String, | ||
options: NotificationOptions = ???) extends EventTarget { | ||
|
||
/** | ||
* The body read-only property of the Notification interface indicates the | ||
* body string of the notification, as specified in the body option of the | ||
* Notification() constructor. | ||
* | ||
* MDN | ||
*/ | ||
val body: String = js.native | ||
|
||
/** | ||
* The data read-only property of the Notification interface returns a | ||
* structured clone of the notification's data, as specified in the | ||
* data option of the Notification() constructor. | ||
* | ||
* The notification's data can be any arbitrary data that you want | ||
* associated with the notification. | ||
* | ||
* MDN | ||
*/ | ||
val data: js.Object = js.native | ||
|
||
/** | ||
* The dir read-only property of the Notification interface indicates the | ||
* text direction of the notification, asspecified in the dir option of | ||
* the Notification() constructor. | ||
* | ||
* MDN | ||
*/ | ||
val dir: String = js.native | ||
|
||
/** | ||
* The icon read-only property of the Notification interface contains the | ||
* URL of an icon to be displayed as part of the notification, as specified | ||
* in the icon option of the Notification() constructor. | ||
* | ||
* MDN | ||
*/ | ||
val icon: String = js.native | ||
|
||
/** | ||
* The lang read-only property of the Notification interface indicates the | ||
* text direction of the notification, as specified in the lang option of | ||
* the Notification() constructor. | ||
* | ||
* MDN | ||
*/ | ||
val lang: String = js.native | ||
|
||
/** | ||
* The noscreen read-only property of the Notification interface specifies | ||
* whether the notification firing should enable the device's screen or not, | ||
* as specified in the noscreen option of the Notification() constructor. | ||
* | ||
* MDN | ||
*/ | ||
val noscreen: Boolean = js.native | ||
|
||
/** | ||
* The onclick property of the Notification interface specifies an event | ||
* listener to receive click events. These events occur when the user | ||
* clicks on a displayed Notification. | ||
* | ||
* MDN | ||
*/ | ||
var onclick: js.Function0[Any] = js.native | ||
|
||
/** | ||
* The onerror property of the Notification interface specifies an event | ||
* listener to receive error events. These events occur when something goes | ||
* wrong with a Notification (in many cases an error preventing the | ||
* notification from being displayed.) | ||
* | ||
* MDN | ||
*/ | ||
var onerror: js.Function0[Any] = js.native | ||
|
||
/** | ||
* The renotify read-only property of the Notification interface specifies | ||
* whether the user should be notified after a new notification replaces an | ||
* old one, as specified in the renotify option of the Notification() | ||
* constructor. | ||
* | ||
* MDN | ||
*/ | ||
val renotify: Boolean = js.native | ||
|
||
/** | ||
* The silent read-only property of the Notification interface specifies | ||
* whether the notification should be silent, i.e. no sounds or vibrations | ||
* should be issued, regardless of the device settings. This is specified | ||
* in the renotify option of the Notification() constructor. | ||
* | ||
* MDN | ||
*/ | ||
val silent: Boolean = js.native | ||
|
||
/** | ||
* The sound read-only property of the Notification interface specifies the | ||
* URL of an audio file to be played when the notification fires. This is | ||
* specified in the sound option of the Notification() constructor. | ||
* | ||
* MDN | ||
*/ | ||
val sound: String = js.native | ||
|
||
/** | ||
* The sticky read-only property of the Notification interface specifies | ||
* whether the notification should be 'sticky', i.e. not easily clearable | ||
* by the user. This is specified in the sticky option of the | ||
* Notification() constructor. | ||
* | ||
* MDN | ||
*/ | ||
val sticky: Boolean = js.native | ||
|
||
/** | ||
* The tag read-only property of the Notification interface signifies an | ||
* identifying tag for the notification, as specified in the tag option | ||
* of the Notification() constructor. | ||
* | ||
* The idea of notification tags is that more than one notification can | ||
* share the same tag, linking them together. One notification can then | ||
* be programmatically replaced with another to avoid the users' screen | ||
* being filled up with a huge number of similar notifications. | ||
* | ||
* MDN | ||
*/ | ||
val tag: String = js.native | ||
|
||
/** | ||
* The vibrate read-only property of the Notification interface. | ||
* Specifies a vibration pattern for devices with vibration hardware | ||
* to emit. | ||
* | ||
* MDN | ||
*/ | ||
val vibrate: js.Array[Double] = js.native | ||
|
||
/** | ||
* The close() method of the Notification interface is used to close a | ||
* previously displayed notification. | ||
* | ||
* MDN | ||
*/ | ||
def close(): Unit = js.native | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double blank line here. We only use single blank lines.