packages feed

jsaddle-dom-0.10.0.0: src/JSDOM/Generated/Notification.hs

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-- | Generated by dom-gen from notifications (webref). Do not edit.
module JSDOM.Generated.Notification
       (newNotification, close, requestPermission, requestPermission_, getPermissionStatic, getMaxActionsStatic, getTitle, getDir, getLang, getBody, getNavigate, getTag, getIcon, getSilent, getSilentUnsafe, getSilentUnchecked, getRequireInteraction, getData, getActions, click, showEvent, error, cLoseEvent, Notification(..), gTypeNotification)
       where
import Prelude ((.), (==), (>>=), (<$>), (++), Bool(..), Maybe(..), IO, Int, Word, Double, Float)
import qualified Prelude as P
import Control.Monad (void)
import Control.Lens.Operators ((^.))
import Language.Javascript.JSaddle (JSM, JSVal, JSString, toJSVal, valToBool, valToNumber, js, jss, jsf, jsg, new, function, asyncFunction, jsUndefined, jsNull)
import JSDOM.Types
import qualified JSDOM.Types as Types
import JSDOM.EventTargetClosures (EventName, unsafeEventName, unsafeEventNameAsync)
import JSDOM.Generated.Enums

-- | <https://developer.mozilla.org/docs/Web/API/Notification/Notification MDN Notification. documentation>
newNotification :: (MonadDOM m, ToJSString title) => title -> Maybe NotificationOptions -> m Notification
newNotification title options = liftDOM (((new (jsg "Notification") [toJSVal title, P.maybe (P.return jsUndefined) toJSVal options]) >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/close MDN Notification.close documentation>
close :: (MonadDOM m) => Notification -> m ()
close self = liftDOM (void (self ^. jsf "close" ()))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/requestPermission_static MDN Notification.requestPermission documentation>
requestPermission :: (MonadDOM m) => Maybe NotificationPermissionCallback -> m NotificationPermission
requestPermission deprecatedCallback = liftDOM ((((((jsg "Notification") ^. jsf "requestPermission" [P.maybe (P.return jsUndefined) toJSVal deprecatedCallback]) >>= readPromise)) >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/requestPermission_static MDN Notification.requestPermission documentation>
requestPermission_ :: (MonadDOM m) => Maybe NotificationPermissionCallback -> m ()
requestPermission_ deprecatedCallback = liftDOM (void ((((jsg "Notification") ^. jsf "requestPermission" [P.maybe (P.return jsUndefined) toJSVal deprecatedCallback]) >>= readPromise)))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/permission_static MDN Notification.permission documentation>
getPermissionStatic :: (MonadDOM m) => m NotificationPermission
getPermissionStatic = liftDOM ((((jsg "Notification") ^. js "permission") >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/maxActions_static MDN Notification.maxActions documentation>
getMaxActionsStatic :: (MonadDOM m) => m Word
getMaxActionsStatic = liftDOM ((P.round <$> (((jsg "Notification") ^. js "maxActions") >>= valToNumber)))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/title MDN Notification.title documentation>
getTitle :: (MonadDOM m, FromJSString result) => Notification -> m result
getTitle self = liftDOM (((self ^. js "title") >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/dir MDN Notification.dir documentation>
getDir :: (MonadDOM m) => Notification -> m NotificationDirection
getDir self = liftDOM (((self ^. js "dir") >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/lang MDN Notification.lang documentation>
getLang :: (MonadDOM m, FromJSString result) => Notification -> m result
getLang self = liftDOM (((self ^. js "lang") >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/body MDN Notification.body documentation>
getBody :: (MonadDOM m, FromJSString result) => Notification -> m result
getBody self = liftDOM (((self ^. js "body") >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/navigate MDN Notification.navigate documentation>
getNavigate :: (MonadDOM m, FromJSString result) => Notification -> m result
getNavigate self = liftDOM (((self ^. js "navigate") >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/tag MDN Notification.tag documentation>
getTag :: (MonadDOM m, FromJSString result) => Notification -> m result
getTag self = liftDOM (((self ^. js "tag") >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/icon MDN Notification.icon documentation>
getIcon :: (MonadDOM m, FromJSString result) => Notification -> m result
getIcon self = liftDOM (((self ^. js "icon") >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/silent MDN Notification.silent documentation>
getSilent :: (MonadDOM m) => Notification -> m (Maybe Bool)
getSilent self = liftDOM (((self ^. js "silent") >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/silent MDN Notification.silent documentation>
getSilentUnsafe :: (MonadDOM m, HasCallStack) => Notification -> m Bool
getSilentUnsafe self = liftDOM ((((self ^. js "silent") >>= fromJSValUnchecked) >>= P.maybe (P.error "Nothing to return") P.return))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/silent MDN Notification.silent documentation>
getSilentUnchecked :: (MonadDOM m) => Notification -> m Bool
getSilentUnchecked self = liftDOM (((self ^. js "silent") >>= valToBool))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/requireInteraction MDN Notification.requireInteraction documentation>
getRequireInteraction :: (MonadDOM m) => Notification -> m Bool
getRequireInteraction self = liftDOM (((self ^. js "requireInteraction") >>= valToBool))

-- | <https://developer.mozilla.org/docs/Web/API/Notification/data MDN Notification.data documentation>
getData :: (MonadDOM m) => Notification -> m JSVal
getData self = liftDOM (self ^. js "data")

-- | <https://developer.mozilla.org/docs/Web/API/Notification/actions MDN Notification.actions documentation>
getActions :: (MonadDOM m) => Notification -> m [NotificationAction]
getActions self = liftDOM (((self ^. js "actions") >>= fromJSValUnchecked))

-- | <https://notifications.spec.whatwg.org/#dom-notification-onclick click event>
click :: EventName Notification Event
click = unsafeEventName (toJSString "click")

-- | <https://notifications.spec.whatwg.org/#dom-notification-onshow show event>
showEvent :: EventName Notification Event
showEvent = unsafeEventName (toJSString "show")

-- | <https://notifications.spec.whatwg.org/#dom-notification-onerror error event>
error :: EventName Notification Event
error = unsafeEventNameAsync (toJSString "error")

-- | <https://notifications.spec.whatwg.org/#dom-notification-onclose close event>
cLoseEvent :: EventName Notification Event
cLoseEvent = unsafeEventNameAsync (toJSString "close")