Skip to content
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

feat: update typings #72

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ Fires when the battery charge percentage reaches the critical charge threshold.
- Browser (Chrome, Firefox, Opera)


[w3c_spec]: http://www.w3.org/TR/2011/WD-battery-status-20110915/
[w3c_spec]: https://www.w3.org/TR/battery-status/
[status_object]: #status-object
133 changes: 27 additions & 106 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,125 +1,46 @@
// Type definitions for Apache Cordova BatteryStatus plugin
// Type definitions for cordova-plugin-battery-status 2.0
// Project: https://github.com/apache/cordova-plugin-battery-status
// Definitions by: Microsoft Open Technologies Inc <http://msopentech.com>
// Tim Brust <https://github.com/timbru31>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
//
// Copyright (c) Microsoft Open Technologies Inc
// Licensed under the MIT license.

type batteryEvent = 'batterystatus' | 'batterycritical' | 'batterylow';

interface Window {
onbatterystatus: (type: BatteryStatusEvent) => void;
onbatterycritical: (type: BatteryStatusEvent) => void;
onbatterylow: (type: BatteryStatusEvent) => void;
/**
* Adds a listener for an event from the BatteryStatus plugin.
* @param type the event to listen for
* batterystatus: event fires when the percentage of battery charge
* changes by at least 1 percent, or if the device is plugged in or unplugged.
* batterycritical: event fires when the percentage of battery charge has reached
* the critical battery threshold. The value is device-specific.
* batterylow: event fires when the percentage of battery charge has
* reached the low battery threshold, device-specific value.
* @param listener the function that executes when the event fires. The function is
* passed an BatteryStatusEvent object as a parameter.
*/
addEventListener(type: "batterystatus", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
/**
* Adds a listener for an event from the BatteryStatus plugin.
* @param type the event to listen for
* batterystatus: event fires when the percentage of battery charge
* changes by at least 1 percent, or if the device is plugged in or unplugged.
* batterycritical: event fires when the percentage of battery charge has reached
* the critical battery threshold. The value is device-specific.
* batterylow: event fires when the percentage of battery charge has
* reached the low battery threshold, device-specific value.
* @param listener the function that executes when the event fires. The function is
* passed an BatteryStatusEvent object as a parameter.
*/
addEventListener(type: "batterycritical", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
/**
* Adds a listener for an event from the BatteryStatus plugin.
* @param type the event to listen for
* batterystatus: event fires when the percentage of battery charge
* changes by at least 1 percent, or if the device is plugged in or unplugged.
* batterycritical: event fires when the percentage of battery charge has reached
* the critical battery threshold. The value is device-specific.
* batterylow: event fires when the percentage of battery charge has
* reached the low battery threshold, device-specific value.
* @param listener the function that executes when the event fires. The function is
* passed an BatteryStatusEvent object as a parameter.
*/
addEventListener(type: "batterylow", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
/**
* Adds a listener for an event from the BatteryStatus plugin.
* @param type the event to listen for
* batterystatus: event fires when the percentage of battery charge
* changes by at least 1 percent, or if the device is plugged in or unplugged.
* batterycritical: event fires when the percentage of battery charge has reached
* the critical battery threshold. The value is device-specific.
* batterylow: event fires when the percentage of battery charge has
* reached the low battery threshold, device-specific value.
* @param listener the function that executes when the event fires. The function is
* passed an BatteryStatusEvent object as a parameter.
*/
addEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void;
* @param type - The event to listen for.
*
* `batterystatus`: event fires when the percentage of battery charge changes by at least 1 percent, or if the device is plugged in or unplugged.
*
* `batterycritical`: event fires when the percentage of battery charge has reached the critical battery threshold. The value is device-specific.
*
* `batterylow`: event fires when the percentage of battery charge has reached the low battery threshold, device-specific value.
* @param listener - The function that executes when the event fires. The function is passed an BatteryStatusEvent object as a parameter.
* @param useCapture - A Boolean indicating whether events of this type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.
*/
addEventListener(type: batteryEvent, listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
/**
* Removes a listener for an event from the BatteryStatus plugin.
* @param type The event to stop listening for.
* batterystatus: event fires when the percentage of battery charge
* changes by at least 1 percent, or if the device is plugged in or unplugged.
* batterycritical: event fires when the percentage of battery charge has reached
* the critical battery threshold. The value is device-specific.
* batterylow: event fires when the percentage of battery charge has
* reached the low battery threshold, device-specific value.
* @param callback the function that executes when the event fires. The function is
* passed an BatteryStatusEvent object as a parameter.
*/
removeEventListener(type: "batterystatus", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
/**
* Removes a listener for an event from the BatteryStatus plugin.
* @param type The event to stop listening for.
* batterystatus: event fires when the percentage of battery charge
* changes by at least 1 percent, or if the device is plugged in or unplugged.
* batterycritical: event fires when the percentage of battery charge has reached
* the critical battery threshold. The value is device-specific.
* batterylow: event fires when the percentage of battery charge has
* reached the low battery threshold, device-specific value.
* @param callback the function that executes when the event fires. The function is
* passed an BatteryStatusEvent object as a parameter.
*/
removeEventListener(type: "batterycritical", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
/**
* Removes a listener for an event from the BatteryStatus plugin.
* @param type The event to stop listening for.
* batterystatus: event fires when the percentage of battery charge
* changes by at least 1 percent, or if the device is plugged in or unplugged.
* batterycritical: event fires when the percentage of battery charge has reached
* the critical battery threshold. The value is device-specific.
* batterylow: event fires when the percentage of battery charge has
* reached the low battery threshold, device-specific value.
* @param callback the function that executes when the event fires. The function is
* passed an BatteryStatusEvent object as a parameter.
*/
removeEventListener(type: "batterylow", listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
/**
* Removes a listener for an event from the BatteryStatus plugin.
* @param type The event to stop listening for.
* batterystatus: event fires when the percentage of battery charge
* changes by at least 1 percent, or if the device is plugged in or unplugged.
* batterycritical: event fires when the percentage of battery charge has reached
* the critical battery threshold. The value is device-specific.
* batterylow: event fires when the percentage of battery charge has
* reached the low battery threshold, device-specific value.
* @param callback the function that executes when the event fires. The function is
* passed an BatteryStatusEvent object as a parameter.
*/
removeEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void;
* @param Atype - The event to stop listening for.
*
* `batterystatus`: event fires when the percentage of battery charge changes by at least 1 percent, or if the device is plugged in or unplugged.
*
* `batterycritical`: event fires when the percentage of battery charge has reached the critical battery threshold. The value is device-specific.
*
* `batterylow`: event fires when the percentage of battery charge has reached the low battery threshold, device-specific value.
* @param callback - The function that executes when the event fires. The function is passed an BatteryStatusEvent object as a parameter.
* @param useCapture - A Boolean indicating whether events of this type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.
*/
removeEventListener(type: batteryEvent, listener: (ev: BatteryStatusEvent) => any, useCapture?: boolean): void;
}

/** Object, that passed into battery event listener */
interface BatteryStatusEvent extends Event {
/* The percentage of battery charge (0-100). */
level: number;
/* A boolean that indicates whether the device is plugged in. */
isPlugged: boolean;
}
}