[angular-desktop-notification] Added typings

This commit is contained in:
Dona278
2018-02-22 11:47:42 +01:00
parent 425ca63a9e
commit 7d7d5f6763
4 changed files with 243 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
import * as angular from 'angular';
angular
.module('app', ['ngDesktopNotification'])
.config(['desktopNotificationProvider', (desktopNotificationProvider: angular.desktopNotification.IDesktopNotificationProvider) => {
desktopNotificationProvider.config({
autoClose: true,
duration: 5,
showOnPageHidden: false,
});
}])
.controller('AppController', ['desktopNotification', (desktopNotification: angular.desktopNotification.IDesktopNotificationService) => {
// Check support and permission
const isNotificationSupported = desktopNotification.isSupported();
const currentNotificationPermission = desktopNotification.currentPermission();
if (currentNotificationPermission === desktopNotification.permissions.granted) {
// Permission granted
}
// Request permission
desktopNotification.requestPermission().then(
// Permission granted
(permission) => {
// Show notification
desktopNotification.show(
"Notification title",
{
tag: "tag",
body: "Notification body",
icon: "https://www.iconurl.com/icon-name.icon-extension",
onClick: () => {
// Notification clicked
}
});
},
() => {
// No permission granted
});
}]);

View File

@@ -0,0 +1,171 @@
// Type definitions for angular-desktop-notification 1.1
// Project: https://github.com/jmsanpascual/angular-desktop-notification#readme
// Definitions by: Davide Donadello <https://github.com/Dona278>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as angular from 'angular';
declare var _: string;
export = _;
declare module 'angular' {
namespace desktopNotification {
/**
* All options available during show notification according to https://developer.mozilla.org/en-US/docs/Web/API/notification
*/
interface AugmentedNotificationOptions extends NotificationOptions {
/**
* The badge property of the Notification interface returns the URL of the image used to represent the notification
* when there is not enough space to display the notification itself.
*
* This is an experimental technology
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/Notification/badge
*/
badge?: USVString;
/**
* 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
*
* Note: This feature is available in Web Workers.
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/Notification/data
*/
data?: any;
/**
* The image read-only property of the Notification interface contains the URL of an image to be displayed as part of
* the notification, as specified in the image option of the Notification() constructor.
*
* Note: This feature is available in Web Workers.
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/Notification/image
*/
image?: USVString;
/**
* 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
*
* Note: This property is not currently supported in any browser.
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/Notification/renotify
*/
renotify?: boolean;
/**
* The requireInteraction read-only property of the Notification interface returns a Boolean indicating that a notification
* should remain active until the user clicks or dismisses it, rather than closing automatically.
*
* Note: This can be set when the notification is first created by setting the requireInteraction option to true in the
* options object of the Notification.Notification() constructor.
* Note: This feature is available in Web Workers.
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/Notification/requireInteraction
*/
requireInteraction?: boolean;
/**
* 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.
*
* Note: This feature is available in Web Workers.
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/Notification/silent
*/
silent?: boolean;
/**
* The timestamp read-only property of the Notification interface returns a DOMTimeStamp, as specified in the timestamp option of the
* Notification() constructor.
*
* The notification's timestamp can represent the time, in milliseconds since 00:00:00 UTC on 1 January 1970, of the event for which
* the notification was created, or it can be an arbitrary timestamp that you want associated with the notification. For example, a
* timestamp for an upcoming meeting could be set in the future, whereas a timestamp for a missed message could be set in the past.
*
* Note: This feature is available in Web Workers
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/Notification/timestamp
*/
timestamp?: number;
/**
* The title read-only property of the Notification interface indicates the title of the notification, as specified in the title parameter
* of the Notification() constructor.
*
* Note: This feature is available in Web Workers.
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/Notification/title
*/
title?: string;
/**
* The vibrate read-only property of the Notification interface specifies a a vibration pattern for the device's vibration hardware to emit
* when the notification fires. This is specified in the vibrate option of the Notification() constructor.
*
* Note: This property is not currently supported in any browser.
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/Notification/vibrate
*/
vibrate?: boolean;
/**
* 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.
*
* The default behavior is to move the focus to the viewport of the notification's related browsing context.
* If you don't want that behaviour, call preventDefault() on the event object.
*/
onClick?: (event: MouseEvent) => void;
/**
* 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.)
*
* A function which serves as the event handler for the error event. When an error occurs, the specified function will be called.
* If null, no error handler is in effect.
*/
onError?: EventListener;
}
interface IDesktopNotificationOptions {
autoClose?: boolean;
duration?: number;
showOnPageHidden?: boolean;
}
interface IDesktopNotificationProvider {
/**
* Set the default app-wide configuration for desktopNotification
*/
config(options: IDesktopNotificationOptions): void;
}
interface IDesktopNotificationService {
permissions: {
default: 'default',
denied: 'denied',
granted: 'granted',
};
/**
* This method returns true if the browser supports the Notification API, false otherwise
*/
isSupported(): boolean;
/**
* This method will get the current permission set in the browser which could be one of the ff.
* - desktopNotification.permissions.default
* - desktopNotification.permissions.denied
* - desktopNotification.permissions.granted
*/
currentPermission(): NotificationPermission;
/**
* This method returns a $q promise, if the user allowed the notification the successCallback will be executed,
* errorCallback will be executed otherwise
*/
requestPermission(): IPromise<NotificationPermission>;
/**
* This method will display the notification using the parameter values.
* See all available options here at https://developer.mozilla.org/en-US/docs/Web/API/notification#Instance_properties
*/
show(title: string, options?: NotificationOptions | AugmentedNotificationOptions): void;
}
}
}

View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true
},
"files": [
"index.d.ts",
"angular-desktop-notification-tests.ts"
]
}

View File

@@ -0,0 +1,7 @@
{
"extends": "dtslint/dt.json" ,
"rules": {
"interface-name": false,
"max-line-length": false
}
}